From patchwork Thu Feb 8 15:46:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 127675 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1609138ljc; Thu, 8 Feb 2018 07:46:45 -0800 (PST) X-Google-Smtp-Source: AH8x226A5ymXp/FEM6zyjdVkBbJZZYTk9kqH00H4YtYFEZbKOgGVirh89n/kcqCUOORH6BHme5o7 X-Received: by 2002:a17:902:9898:: with SMTP id s24-v6mr1028630plp.275.1518104805362; Thu, 08 Feb 2018 07:46:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518104805; cv=none; d=google.com; s=arc-20160816; b=xYiAmkhjKFy68DGUOasF2nYU/wHiFAnqJseip6tYpHiO35ldnHXTAROsAeqBv3ccGr rAkwKE9ZnWm2ZqdcZPMVWZ/a1Tt7KVPLkLIMwwuAMbGWbwJJ93Fww+7mGxE4hWE4t30x WRbrO/FlAqTisikKDiEYMwJ1AWxwMlSzwnN7PSevLSzlGSuoWih0kIalzRGL4FxItwhR QELGqarr7xakLeSsvqBHFybPt6W1rcBVrttvXoSHGEqRVjHoK7tANR47QUUGgWtioT4E lMcB0QTPg9puCMZH1/0WnrnBZ13tNLm/b+keBZMxlImOVxDBkIiGFyrNWEoksVoil5v4 CedQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Ee3MuuAQ6oFeRS+jG5hDs2K7foTi4GMTkPkKdiDx6nI=; b=oeL+tQ0eqX2quvENi8mW0NGZwVaMiqZmmq2AyE4rVOAfzw/H0rrs67e/th0yc7wAQD nZ4HXelMWHZsL7gs7He+SHhDWY09a2AwX9GsKN5qyR4y4gfL02PSK+0MJYygPANY+vj6 3kDPL1y/23gT3JNaOOKpyvDOFtxxe/62/591z0iLNJ/r/28iF4ykVX/OHQ+t9I9TW+oi 2zlsHxV7JnmIo0daISNLfRzILKU1oL4XJswaP2M6Oo8wTVzO+NCS11WBB/eJxx8BB22u z5GEFGl5tu25mziAMzv7V2Bl/elgkAVlDB0Xk7igJs2ixRfTYdQBSCRLBRcgiarfp8mj 8aVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i187si137671pfe.384.2018.02.08.07.46.45; Thu, 08 Feb 2018 07:46:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752372AbeBHPqm (ORCPT + 13 others); Thu, 8 Feb 2018 10:46:42 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:36738 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751094AbeBHPql (ORCPT ); Thu, 8 Feb 2018 10:46:41 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B25AA1435; Thu, 8 Feb 2018 07:46:40 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C63043F25C; Thu, 8 Feb 2018 07:46:39 -0800 (PST) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Andrew Morton , Andrey Ryabinin Subject: [PATCH] UBSAN: support __ubsan_handle_type_mismatch_v1 Date: Thu, 8 Feb 2018 15:46:36 +0000 Message-Id: <20180208154636.21320-1-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Originally, UBSAN's __ubsan_handle_type_mismatch took a struct type_mismatch_data, as defined in lib/ubsan.h. This has an unsigned long alignment field. New versions of UBSAN call __ubsan_handle_type_mismatch_v1, which is similar to __ubsan_handle_type_mismatch, but takes a different struct where the alignment is stored in an unsigned char (as log2 of the alignment). All other fields are unchanged. As we don't implement __ubsan_handle_type_mismatch_v1, the kernel will fail to link when compiled with compilers using the new ABI (e.g. clang form the LLVM 5.0.0 release). This patch adds support for the new ABI. To keep things simple, we simply convert the new data format into the old format, and hand it on to the existing handlers. Signed-off-by: Mark Rutland Cc: Andrew Morton Cc: Andrey Ryabinin --- lib/ubsan.c | 14 ++++++++++++++ lib/ubsan.h | 7 +++++++ 2 files changed, 21 insertions(+) Andrey, does this look correct to you? Are there any other new ABI bits that need to be plumbed in? Mark. -- 2.11.0 diff --git a/lib/ubsan.c b/lib/ubsan.c index fb0409df1bcf..b7af7d3478a9 100644 --- a/lib/ubsan.c +++ b/lib/ubsan.c @@ -328,6 +328,20 @@ void __ubsan_handle_type_mismatch(struct type_mismatch_data *data, } EXPORT_SYMBOL(__ubsan_handle_type_mismatch); +void __ubsan_handle_type_mismatch_v1(struct type_mismatch_data_v1 *data_v1, + unsigned long ptr) +{ + struct type_mismatch_data data = { + .location = data_v1->location, + .type = data_v1->type, + .alignment = 1UL << data_v1->log_alignment, + .type_check_kind = data_v1->type_check_kind, + }; + + __ubsan_handle_type_mismatch(&data, ptr); +} +EXPORT_SYMBOL(__ubsan_handle_type_mismatch_v1); + void __ubsan_handle_nonnull_return(struct nonnull_return_data *data) { unsigned long flags; diff --git a/lib/ubsan.h b/lib/ubsan.h index 88f23557edbe..dc0b8cbc7f57 100644 --- a/lib/ubsan.h +++ b/lib/ubsan.h @@ -37,6 +37,13 @@ struct type_mismatch_data { unsigned char type_check_kind; }; +struct type_mismatch_data_v1 { + struct source_location location; + struct type_descriptor *type; + unsigned char log_alignment; + unsigned char type_check_kind; +}; + struct nonnull_arg_data { struct source_location location; struct source_location attr_location;