From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Cyrus-Session-Id: sloti22d1t05-4090104-1516375736-2-14188425480759057074 X-Sieve: CMU Sieve 3.0 X-Spam-known-sender: no X-Spam-score: 0.0 X-Spam-hits: BAYES_00 -1.9, HEADER_FROM_DIFFERENT_DOMAINS 0.25, RCVD_IN_DNSWL_HI -5, T_RP_MATCHES_RCVD -0.01, LANGUAGES unknown, BAYES_USED global, SA_VERSION 3.4.0 X-Spam-source: IP='209.132.180.67', Host='vger.kernel.org', Country='US', FromHeader='com', MailFrom='org', XOriginatingCountry='RU' X-Spam-charsets: X-Resolved-to: greg@kroah.com X-Delivered-to: greg@kroah.com X-Mail-from: stable-owner@vger.kernel.org ARC-Seal: i=1; a=rsa-sha256; cv=none; d=messagingengine.com; s=arctest; t=1516375735; b=VOCpeE6aOCkOp768XPsZmqpT3G6fB/MlALWJ1yXx74WqKp1 Sh1h4hOm5NLpPKggDVgM2FHiGeO5NYXLH8HqwqzDh4upmo3+Uy9A1Ww9R1QD5Ye1 vLqu/9JYyyRX3uEYueg21JwysrnLom+6sEwY1W6aB85bHE8cX9xtcFZwhDOh02FN /Geh4lfykxE/09oCb/w/wKRYL84hqIenPLpTwdOBN4exLKp+Is6glpZ5/rQr3kj7 PIgk3DYAGukMmLdIomqEgAPqvIuCsNvN/cW2688v+IyDDU7SF+nVga648GOBCpn9 rZV66sXedcSMJavjdTbqXV6F7yaEidnUg+L0Wag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=from:to:cc:subject:date:message-id :mime-version:content-type:sender:list-id; s=arctest; t= 1516375735; bh=gCwOwwV9cWkpG4fO8H2rXjZwrJRDyqWU/ZpwGOMYszM=; b=G zS0J1eRo2ApqYuFgTPeY5ZHfpKoC7+k8QEH/ckHjXuyYA4qs8P+N+jQIxCDjcrdZ KQDb+28I3sps+PVjDZN6IW8o4O/tpRktLHQk+cSqp3+Nr3epS2YNLF5egfN1YitA lgkEgJasPuPbMV/UTQSQckrYKp1t1UnL1VuXMo+U4TpQabbk4hDgu5thVg1LQL4o dytW9g9snumIGP6ockpdndvwKMY+4AvDhwSo8olcU0YMeKheu8vvrWCRXj63/MHW hpFRkEDB1Q7jTvdidubQO4i1L/olyxyrVxSkc8ZA+wjuyXTuur4l3UssvjyMCMs3 VTgeF/yOiS3bk337OVlZw== ARC-Authentication-Results: i=1; mx1.messagingengine.com; arc=none (no signatures found); dkim=pass (1024-bit rsa key sha256) header.d=virtuozzo.com header.i=@virtuozzo.com header.b=QDP10Ucs x-bits=1024 x-keytype=rsa x-algorithm=sha256 x-selector=selector1; dmarc=pass (p=none,has-list-id=yes,d=none) header.from=virtuozzo.com; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=stable-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=virtuozzo.com header.result=pass header_is_org_domain=yes Authentication-Results: mx1.messagingengine.com; arc=none (no signatures found); dkim=pass (1024-bit rsa key sha256) header.d=virtuozzo.com header.i=@virtuozzo.com header.b=QDP10Ucs x-bits=1024 x-keytype=rsa x-algorithm=sha256 x-selector=selector1; dmarc=pass (p=none,has-list-id=yes,d=none) header.from=virtuozzo.com; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=stable-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=virtuozzo.com header.result=pass header_is_org_domain=yes Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754964AbeASP2x (ORCPT ); Fri, 19 Jan 2018 10:28:53 -0500 Received: from mail-db5eur01on0101.outbound.protection.outlook.com ([104.47.2.101]:58400 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754542AbeASP2w (ORCPT ); Fri, 19 Jan 2018 10:28:52 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=aryabinin@virtuozzo.com; From: Andrey Ryabinin To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Sodagudi Prasad , Andrey Ryabinin , stable Subject: [PATCH 1/2] lib/ubsan: Add type mismatch handler for new GCC/Clang Date: Fri, 19 Jan 2018 18:28:52 +0300 Message-Id: <20180119152853.16806-1-aryabinin@virtuozzo.com> X-Mailer: git-send-email 2.13.6 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR09CA0071.eurprd09.prod.outlook.com (2603:10a6:7:3d::15) To DB6PR08MB2824.eurprd08.prod.outlook.com (2603:10a6:6:1d::27) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 01e0bdd0-b6e7-40e2-ae31-08d55f5156bd X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:DB6PR08MB2824; X-Microsoft-Exchange-Diagnostics: 1;DB6PR08MB2824;3:6ruoNT14AGQFtybYkIoPKCeOeGjudEZi+C15w8BDsbrUbj2xcjJjWuPPP1YYKp/9dm6xN3QJRy65KYW+VDrRnEZfnPz2Gxj3yVZ88jt98q4jYSGNrKlN5/A8zbDFNf125FmgTzrNEH4odDJzqz/WBu1n5CW7yN6olR57BjVB6waauhHA2qQeUEhi1dRwM92wpWZLfg/qR70Bll48hKZqoM1ChQ6SNWrXTUpbJEM2DmZqn5a4Lmc6clyATLr08RZn;25:Wr9R7AHMVt5XMt0l+Va2WOJUk4u6vnZGqBPNhTr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P0941QASDxb9wGUgMbwGvxy8X7K+H2BjIBMxI2cpIsndgnA0Qa4vsGzzP1Knj1lGXhib7GR44yXsLEvq9ct7ejmEFkKnS9drjxEHxfcPv1VyLyW6spvZRE6w5LqYBaSd+2iFPVn8xYKtL0yQIFQv/zL3/iDY+eZCjLGlyKYcFEaSI3ReN9ubikWfKzLxHugZ4biCt+5vOI6H4pdaDsT/Q2Pawxh/NSnObZldVOeSDHfIsNkZaRzqeq3WJnVUAr2IXsFX1DsRrab5M/3pg4DG7fAzPJ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(3231023)(2400079)(944501161)(6041268)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:DB6PR08MB2824;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:DB6PR08MB2824; X-Forefront-PRVS: 0557CBAD84 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(346002)(366004)(376002)(39380400002)(396003)(39850400004)(189003)(199004)(86362001)(16526018)(7736002)(25786009)(105586002)(5660300001)(6916009)(2906002)(386003)(6506007)(52116002)(305945005)(36756003)(59450400001)(68736007)(106356001)(54906003)(6116002)(16586007)(316002)(53416004)(6666003)(53936002)(47776003)(8936002)(51416003)(76506005)(97736004)(81166006)(6512007)(8676002)(48376002)(478600001)(4326008)(50226002)(50466002)(81156014)(1076002)(69596002)(66066001)(26005)(3846002)(6486002);DIR:OUT;SFP:1102;SCL:1;SRVR:DB6PR08MB2824;H:localhost.sw.ru;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DB6PR08MB2824;23:8v8X0q9llQwINlpnt1vbw1Ff3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JNVVHQeGL9V9nZ+jBhU8WnJoOfSVVPahJ7ddsktL52U40aHaCvchHH3ifcZECGaMrpSxA+4BF0Yh/0rVOTzht4lJgGD5+lXpflJo2zkUURS+3qv8zUACz7dVKqRqMJjq92DTjRhFc1KYAkJsxjEZFDrXzwtExi986xDYFoXt4Q99p2zd6sHKLsSDoGkX75ju/dLRiEz0nnnK0mu2irgLG9RGe2fUx5UpLJR/luTfvDhZxISrGV SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DB6PR08MB2824;20:lmGXe0tLiSzLIvyzzfE052HtW0BIVMwxfMAp3+E/mMfXV7Eiv+iqCaZ+j219VrV/eXxPOyRCe2G0w7xkUh8/CPBSQd3UswliXiS+pko2alLtfKmYZTczTQZ28Qbg5Cjmv8AnOZm2eBDods3JdOgX1sheN57tu0Jgi18PqCufzIA= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2018 15:28:48.9741 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 01e0bdd0-b6e7-40e2-ae31-08d55f5156bd X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR08MB2824 Sender: stable-owner@vger.kernel.org X-Mailing-List: stable@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-Mailing-List: linux-kernel@vger.kernel.org List-ID: UBSAN=y fails to build with new GCC/clang: arch/x86/kernel/head64.o: In function `sanitize_boot_params': arch/x86/include/asm/bootparam_utils.h:37: undefined reference to `__ubsan_handle_type_mismatch_v1' because Clang and GCC 8 slightly changed ABI for 'type mismatch' errors. Compiler now uses new __ubsan_handle_type_mismatch_v1() function with slightly modified 'struct type_mismatch_data'. Let's add new 'struct type_mismatch_data_common' which is independent from compiler's layout of 'struct type_mismatch_data'. And make __ubsan_handle_type_mismatch[_v1]() functions transform compiler-dependent type mismatch data to our internal representation. This way, we can support both old and new compilers with minimal amount of change. Reported-by: Sodagudi Prasad Signed-off-by: Andrey Ryabinin Cc: stable # 4.5+ --- lib/ubsan.c | 48 ++++++++++++++++++++++++++++++++++++++---------- lib/ubsan.h | 14 ++++++++++++++ 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/lib/ubsan.c b/lib/ubsan.c index 1e2328fa002d..50d1d5c25deb 100644 --- a/lib/ubsan.c +++ b/lib/ubsan.c @@ -265,14 +265,14 @@ void __ubsan_handle_divrem_overflow(struct overflow_data *data, } EXPORT_SYMBOL(__ubsan_handle_divrem_overflow); -static void handle_null_ptr_deref(struct type_mismatch_data *data) +static void handle_null_ptr_deref(struct type_mismatch_data_common *data) { unsigned long flags; - if (suppress_report(&data->location)) + if (suppress_report(data->location)) return; - ubsan_prologue(&data->location, &flags); + ubsan_prologue(data->location, &flags); pr_err("%s null pointer of type %s\n", type_check_kinds[data->type_check_kind], @@ -281,15 +281,15 @@ static void handle_null_ptr_deref(struct type_mismatch_data *data) ubsan_epilogue(&flags); } -static void handle_misaligned_access(struct type_mismatch_data *data, +static void handle_misaligned_access(struct type_mismatch_data_common *data, unsigned long ptr) { unsigned long flags; - if (suppress_report(&data->location)) + if (suppress_report(data->location)) return; - ubsan_prologue(&data->location, &flags); + ubsan_prologue(data->location, &flags); pr_err("%s misaligned address %p for type %s\n", type_check_kinds[data->type_check_kind], @@ -299,15 +299,15 @@ static void handle_misaligned_access(struct type_mismatch_data *data, ubsan_epilogue(&flags); } -static void handle_object_size_mismatch(struct type_mismatch_data *data, +static void handle_object_size_mismatch(struct type_mismatch_data_common *data, unsigned long ptr) { unsigned long flags; - if (suppress_report(&data->location)) + if (suppress_report(data->location)) return; - ubsan_prologue(&data->location, &flags); + ubsan_prologue(data->location, &flags); pr_err("%s address %p with insufficient space\n", type_check_kinds[data->type_check_kind], (void *) ptr); @@ -315,7 +315,7 @@ static void handle_object_size_mismatch(struct type_mismatch_data *data, ubsan_epilogue(&flags); } -void __ubsan_handle_type_mismatch(struct type_mismatch_data *data, +static void ubsan_type_mismatch_common(struct type_mismatch_data_common *data, unsigned long ptr) { @@ -326,8 +326,36 @@ void __ubsan_handle_type_mismatch(struct type_mismatch_data *data, else handle_object_size_mismatch(data, ptr); } + +void __ubsan_handle_type_mismatch(struct type_mismatch_data *data, + unsigned long ptr) +{ + struct type_mismatch_data_common common_data = { + .location = &data->location, + .type = data->type, + .alignment = data->alignment, + .type_check_kind = data->type_check_kind + }; + + ubsan_type_mismatch_common(&common_data, ptr); +} EXPORT_SYMBOL(__ubsan_handle_type_mismatch); +void __ubsan_handle_type_mismatch_v1(struct type_mismatch_data_v1 *data, + unsigned long ptr) +{ + + struct type_mismatch_data_common common_data = { + .location = &data->location, + .type = data->type, + .alignment = 1UL << data->log_alignment, + .type_check_kind = data->type_check_kind + }; + + ubsan_type_mismatch_common(&common_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..7e30b26497e0 100644 --- a/lib/ubsan.h +++ b/lib/ubsan.h @@ -37,6 +37,20 @@ 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 type_mismatch_data_common { + struct source_location *location; + struct type_descriptor *type; + unsigned long alignment; + unsigned char type_check_kind; +}; + struct nonnull_arg_data { struct source_location location; struct source_location attr_location; -- 2.13.6