Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1506381ybg; Tue, 2 Jun 2020 11:50:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZ5XiQVWgQjclmHVqcCUkXvutEClx1EbQTBqsoC9+udIqeeb2X2bR77Kmu3Yqh71/tg/gf X-Received: by 2002:a17:906:78b:: with SMTP id l11mr2826179ejc.427.1591123804880; Tue, 02 Jun 2020 11:50:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591123804; cv=none; d=google.com; s=arc-20160816; b=FD83UlXVOFkrCj8jKfoeIjemTjVcHSCc144CLDcxGZZWlpfLbWUG7MFJyIs//RZGA3 OkedzMoVgzy++oGIQ7repP7SAZoNFbsJ+pV0l00tngBQRpBIO2+h3yw5qC+AMAwAi07j U54YAlrkQPXnk1dqDzJqobQ+x9ARRd5atEwP9o1B+YeoG/fbhOUtyDE5VCPZ2RriglmT fBLsQJccsuxaDbHK2W3xtAH66X7vm0SmVcTwFyAu1WOG6o2zNEuiBqvdgZqYnWnIswrQ rBU0/4iNlqgHl8pxA94HSlmNqQB4JWtCskLNobuh+BCpkQJY3xdUEeWHVayhtgtySUXi RXDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=+FgmqyrmNJ7X96y+2DvYBXfBfS1ICd8c/t7BA8+xtfg=; b=xQP/brbaEvh0lj5UlMJf/HBftrf9yGLHKDynRMnfT7F2XGskih5VqKUiw81lTSd8P8 hkc2+ny1WlZY0tc1fxcWemAhP3rFco8trtWDBVQdi+8JeCFl4b/0Q8vTwPv8qO7yN1xE D0b4OGmaR3+ln0snCSrBJ76cZbWlPaKSvtlI5diYeIU39rL+aJdx3c6dWKty6+o82pxR 8U4XacK/8RlVI1WDlSQFzZI05FSaortprHs/OUNtCTxtH0FHaX4jjhRO1dY33E5sbI7H GckGWfSxDP06WG7fTUqGC5V7IFY00cmTfotfbvKu5sgT54msMVIcT1e63WDqqIjNUIFR AIgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ih+cI902; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn1si2373616ejc.638.2020.06.02.11.49.40; Tue, 02 Jun 2020 11:50:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ih+cI902; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727826AbgFBSoT (ORCPT + 99 others); Tue, 2 Jun 2020 14:44:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726000AbgFBSoQ (ORCPT ); Tue, 2 Jun 2020 14:44:16 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C612C08C5C0 for ; Tue, 2 Jun 2020 11:44:16 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id c17so12676114ybf.7 for ; Tue, 02 Jun 2020 11:44:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=+FgmqyrmNJ7X96y+2DvYBXfBfS1ICd8c/t7BA8+xtfg=; b=Ih+cI902kz5t7uJJLppal8ZALLognsWXdA/nGcB832ZjevEAps41Xf85EJ4lQNNRLx aSGv2kdW1RsgrQjdkPU3eduEGsRlR5zkHjhZlZDfJUyQLWxNkK9Eh/vW8KjGC1aVZJDo ql9STNz0KE/H8twNAY5tBzkzuDJBn+D5j2iqgXqabsHArIU7VY9DzabDO1c7SbWUVl9y hmy55hmuk+lZ28VQD3nqH257Y/KSiztMn44marRqh2WRS7RIaCmI5+xITgMFowGWoLVW da3BLSGuBNRQpJDFeNibBC39Ahsk9w8BpzDT3KXdVQFsHLrBoTkNohyKQXwcFZSrxMbr vlLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=+FgmqyrmNJ7X96y+2DvYBXfBfS1ICd8c/t7BA8+xtfg=; b=nkMbKtQOgzPSxAcX52BHEtydtuRHcBuTPruPPDW146iqnmy89D6lM4M1VqIwgyVoRk Lt1BhQjYUtI5/EMDh+FNvjVevQPofxtF+YqvfniLo4zt7ZxBc3ygtPJebrxLS/VbcpR4 7KZxgLEYzRz9dtNy+bYoDI7dKgQvzyoqxyqnmoJvmqrBBp8eTeRfwm0piBnwzWba931C 2InUYF2KAnsEGmP90/W9nLGrYiNR8E1s6MeAdfBuQDl/hh0lzeztPOQcIfNOjxp7vad4 A+J9RbvMSfUzFnj1Qngq+BnE697wnHJ5PYldpLjDAv9WTRxz06yYPducwvgRGRiTt0uR r0zA== X-Gm-Message-State: AOAM533dWSclgiZl0nmYOyyCcJPihQcOtr3+kwBwH/MvBXxW84QSyF0v K1rn/uAQcQl2o3fKi2lvD+UJd/ARNw== X-Received: by 2002:a25:bdc8:: with SMTP id g8mr42893731ybk.122.1591123455849; Tue, 02 Jun 2020 11:44:15 -0700 (PDT) Date: Tue, 2 Jun 2020 20:44:09 +0200 In-Reply-To: <20200602184409.22142-1-elver@google.com> Message-Id: <20200602184409.22142-2-elver@google.com> Mime-Version: 1.0 References: <20200602184409.22142-1-elver@google.com> X-Mailer: git-send-email 2.27.0.rc2.251.g90737beb825-goog Subject: [PATCH -tip 2/2] compiler_types.h: Add __no_sanitize_{address,undefined} to noinstr From: Marco Elver To: elver@google.com Cc: will@kernel.org, peterz@infradead.org, bp@alien8.de, tglx@linutronix.de, mingo@kernel.org, clang-built-linux@googlegroups.com, paulmck@kernel.org, dvyukov@google.com, glider@google.com, andreyknvl@google.com, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, syzbot+dc1fa714cb070b184db5@syzkaller.appspotmail.com 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 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. Link: https://lore.kernel.org/lkml/000000000000d2474c05a6c938fe@google.com/ Reported-by: syzbot+dc1fa714cb070b184db5@syzkaller.appspotmail.com Signed-off-by: Marco Elver --- 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. --- 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