From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7A09C433E0 for ; Thu, 4 Jun 2020 10:25:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B11B32064C for ; Thu, 4 Jun 2020 10:25:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="DsqAMDU1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728502AbgFDKZl (ORCPT ); Thu, 4 Jun 2020 06:25:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728486AbgFDKZg (ORCPT ); Thu, 4 Jun 2020 06:25:36 -0400 Received: from merlin.infradead.org (unknown [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C55EFC03E96D for ; Thu, 4 Jun 2020 03:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=v2OvG7tLuUOfVg0mt6uzXQB9ddwSE7MfPjtV2q2apbU=; b=DsqAMDU1mnpdlY1y52Eu6Vabna 8h18AHQEkX5bwA9I2OmHHhXhMcwFhD5bV7Ds+m+mMSySvo0kxDgln2dCkIaPlcA91Mh6ICrmU7p3+ QBJ3u+U961X/WOLH9It3nFPNbewnBQXUkVR3GQmuGD1ijnvG/F67zWF4YNuwp0bksFQ6FDbRvQDBn 6zJmEM05dqVEfa2lze+f+fEtafnjDIbX7wmjhXtPtPkAWl3JqIW2ItnQJWH3tCEuksYqRlkbYLjT2 1Ij5IFmYOPhlrcLh2qrrfCf8r0NZas45el+h4ccZ3tuRqwebglSRxalmtFtpqqTrrsMINTPQP5IMN TA0Mts4g==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jgn3e-0003tk-Jg; Thu, 04 Jun 2020 10:25:10 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 0F18C306E4A; Thu, 4 Jun 2020 12:25:08 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id E33F220CB4767; Thu, 4 Jun 2020 12:25:07 +0200 (CEST) Message-ID: <20200604102428.193173789@infradead.org> User-Agent: quilt/0.66 Date: Thu, 04 Jun 2020 12:22:46 +0200 From: Peter Zijlstra To: tglx@linutronix.de Cc: x86@kernel.org, elver@google.com, paulmck@kernel.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, peterz@infradead.org, will@kernel.org, dvyukov@google.com, glider@google.com, andreyknvl@google.com, syzbot+dc1fa714cb070b184db5@syzkaller.appspotmail.com, Miguel Ojeda Subject: [PATCH 5/8] compiler_types.h: Add __no_sanitize_{address,undefined} to noinstr References: <20200604102241.466509982@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marco Elver Adds the portable definitions for __no_sanitize_address, and __no_sanitize_undefined, and subsequently changes noinstr to use the attributes to disable instrumentation via KASAN or UBSAN. Reported-by: syzbot+dc1fa714cb070b184db5@syzkaller.appspotmail.com Signed-off-by: Marco Elver Signed-off-by: Peter Zijlstra (Intel) Acked-by: Miguel Ojeda Link: https://lore.kernel.org/lkml/000000000000d2474c05a6c938fe@google.com/ --- Note: __no_sanitize_coverage (for KCOV) isn't possible right now, because neither GCC nor Clang support such an attribute. This means going and changing the compilers again (for Clang it's fine, for GCC, it'll take a while). However, it looks like that KCOV_INSTRUMENT := n is currently in all the right places. Short-term, this should be reasonable. v2: * No change. --- include/linux/compiler-clang.h | 8 ++++++++ include/linux/compiler-gcc.h | 6 ++++++ include/linux/compiler_types.h | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h index 2cb42d8bdedc..c0e4b193b311 100644 --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h @@ -33,6 +33,14 @@ #define __no_sanitize_thread #endif +#if __has_feature(undefined_behavior_sanitizer) +/* GCC does not have __SANITIZE_UNDEFINED__ */ +#define __no_sanitize_undefined \ + __attribute__((no_sanitize("undefined"))) +#else +#define __no_sanitize_undefined +#endif + /* * Not all versions of clang implement the the type-generic versions * of the builtin overflow checkers. Fortunately, clang implements diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index 7dd4e0349ef3..1c74464c80c6 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -150,6 +150,12 @@ #define __no_sanitize_thread #endif +#if __has_attribute(__no_sanitize_undefined__) +#define __no_sanitize_undefined __attribute__((no_sanitize_undefined)) +#else +#define __no_sanitize_undefined +#endif + #if GCC_VERSION >= 50100 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1 #endif diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index 02becd21d456..89b8c1ae18a1 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -198,7 +198,8 @@ struct ftrace_likely_data { /* Section for code which can't be instrumented at all */ #define noinstr \ - noinline notrace __attribute((__section__(".noinstr.text"))) __no_kcsan + noinline notrace __attribute((__section__(".noinstr.text"))) \ + __no_kcsan __no_sanitize_address __no_sanitize_undefined #endif /* __KERNEL__ */ -- 2.27.0.rc2.251.g90737beb825-goog