From patchwork Fri Jul 1 14:22:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12903364 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6868CC43334 for ; Fri, 1 Jul 2022 14:23:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EFA056B007D; Fri, 1 Jul 2022 10:23:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E82896B0080; Fri, 1 Jul 2022 10:23:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CFD3A6B0081; Fri, 1 Jul 2022 10:23:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BFAB36B007D for ; Fri, 1 Jul 2022 10:23:36 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 79BB5615E2 for ; Fri, 1 Jul 2022 14:23:36 +0000 (UTC) X-FDA: 79638749232.09.8F53680 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) by imf23.hostedemail.com (Postfix) with ESMTP id 28021140044 for ; Fri, 1 Jul 2022 14:23:35 +0000 (UTC) Received: by mail-ed1-f73.google.com with SMTP id m8-20020a056402430800b00435cfa7c6d1so1886234edc.9 for ; Fri, 01 Jul 2022 07:23:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=gkw9YA7vb5ti0YajzjGN1OXbVHAqDO+SEh0OPXXltUo=; b=DJbRcfFJX1wyQKX8l1FZMyPmyPhiG8QaxtSYEHL+jg9LVV4C2ZYVwI87iVYJ5A4E5H sNiz7RovSUX82iKvetSTT3ivRgXe5SpIKUpLrVUzsQuWrPS2jZdEVUvd0d8c9xpIi90R qYQHmigg/c73A/xfmHKA2YHRRIAqFEe1j/TS5WTo13oUcktHSiV8OM6WEW0kvknYU24w qmZDUmfFklZTJQaCpjJHDgMF8cHmn9jm2Clttqa12yyLWz5x4d/+8IezIzi4zJyCX3cm qbQ7Z3421wCmEB8O7JvaGEmI1uQEvIdKykYZFz7qXILVLVkF14Shh8wwyANYIgOrQMXI WcWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=gkw9YA7vb5ti0YajzjGN1OXbVHAqDO+SEh0OPXXltUo=; b=LOp6s9W3nMpjK4piXgQdOmQ7Ab+ukUzfrafgaG5E4sxbGacJODjIiW6qd5DVIdBoph QxswAKG0zx8QJwbFZFqWSRqCR2uKudnKv8xBvTVuXx7tAXuLWos36lL1a3GkJ7nlHJ2v dd7PFOoctpu71jeXgN7sEZQ1oALL3TMAkwccLZnlSezTPAKpdHDd0xpSCwQ4zlrtHVEa eANas4u0uQOJNf1lThODo2s4o0VISPBg952P39VHDpRDfgddqxiMm89GsjXER1FCHO2D CvJ2kHeCUS5ou2Y1bTOpupLesYugP0L273Nb+iZRBAy+5oizsNHURthw3yid4dqzBlJ1 JBcw== X-Gm-Message-State: AJIora+PWTOHMLcktDKvU14pGSKGMDKynRtbDVJZwa2ZyDr9mLJCtV65 ekZ6zQ5TP2wUNM1Oh/GEF7qIpOUNIRc= X-Google-Smtp-Source: AGRyM1uCNIkqQBwTVhpOJ3Y5EwonQhFZw2dysbIFTeg8qz1++vtqH5YHyoXPS6hxY4s/hJxG0C172twlxOY= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:a6f5:f713:759c:abb6]) (user=glider job=sendgmr) by 2002:a05:6402:518b:b0:435:c1ed:3121 with SMTP id q11-20020a056402518b00b00435c1ed3121mr19002047edd.405.1656685414953; Fri, 01 Jul 2022 07:23:34 -0700 (PDT) Date: Fri, 1 Jul 2022 16:22:32 +0200 In-Reply-To: <20220701142310.2188015-1-glider@google.com> Message-Id: <20220701142310.2188015-8-glider@google.com> Mime-Version: 1.0 References: <20220701142310.2188015-1-glider@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 07/45] kmsan: introduce __no_sanitize_memory and __no_kmsan_checks From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , Alexei Starovoitov , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Marco Elver , Mark Rutland , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=DJbRcfFJ; spf=pass (imf23.hostedemail.com: domain of 3ZgO_YgYKCIUpurmn0pxxpun.lxvurw36-vvt4jlt.x0p@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3ZgO_YgYKCIUpurmn0pxxpun.lxvurw36-vvt4jlt.x0p@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656685416; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gkw9YA7vb5ti0YajzjGN1OXbVHAqDO+SEh0OPXXltUo=; b=eKk38tqLz6mgno0W0nCLchP9d/wyQ4cCBPng1VBBFoQWlK4jdmeVwXfA+kD+sFgG6XCcHQ 2nm6agbXoNpZex4XcBJUnW5VJoydwVVQRVaqelGfUAD5NJwVvMIBzmnqYIotrMqb1rkYp9 EblXISbeHt2OSTEdsMeBYFRVBpbtcy0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656685416; a=rsa-sha256; cv=none; b=IWYeBBw0hLNkLRAqsxbn/UYbz15muYI44WNozwXxLFzc8PkrpQxkTKoRBImVef0uhdnKk7 V7yOCqNOXW1/YdNpq+lwAiJikVHbffwCnA7ktrWrdtfZ8GZwapFoILwQakyYLXboWD6ULO Wgl5GUCTLe7WTerAklspv4WHutReVWc= X-Stat-Signature: ep89b8yiuso37suk4aanef8gje5o8xzi X-Rspamd-Queue-Id: 28021140044 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=DJbRcfFJ; spf=pass (imf23.hostedemail.com: domain of 3ZgO_YgYKCIUpurmn0pxxpun.lxvurw36-vvt4jlt.x0p@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3ZgO_YgYKCIUpurmn0pxxpun.lxvurw36-vvt4jlt.x0p@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam12 X-Rspam-User: X-HE-Tag: 1656685415-687138 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: __no_sanitize_memory is a function attribute that instructs KMSAN to skip a function during instrumentation. This is needed to e.g. implement the noinstr functions. __no_kmsan_checks is a function attribute that makes KMSAN ignore the uninitialized values coming from the function's inputs, and initialize the function's outputs. Functions marked with this attribute can't be inlined into functions not marked with it, and vice versa. This behavior is overridden by __always_inline. __SANITIZE_MEMORY__ is a macro that's defined iff the file is instrumented with KMSAN. This is not the same as CONFIG_KMSAN, which is defined for every file. Signed-off-by: Alexander Potapenko Reviewed-by: Marco Elver --- Link: https://linux-review.googlesource.com/id/I004ff0360c918d3cd8b18767ddd1381c6d3281be --- include/linux/compiler-clang.h | 23 +++++++++++++++++++++++ include/linux/compiler-gcc.h | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h index c84fec767445d..4fa0cc4cbd2c8 100644 --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h @@ -51,6 +51,29 @@ #define __no_sanitize_undefined #endif +#if __has_feature(memory_sanitizer) +#define __SANITIZE_MEMORY__ +/* + * Unlike other sanitizers, KMSAN still inserts code into functions marked with + * no_sanitize("kernel-memory"). Using disable_sanitizer_instrumentation + * provides the behavior consistent with other __no_sanitize_ attributes, + * guaranteeing that __no_sanitize_memory functions remain uninstrumented. + */ +#define __no_sanitize_memory __disable_sanitizer_instrumentation + +/* + * The __no_kmsan_checks attribute ensures that a function does not produce + * false positive reports by: + * - initializing all local variables and memory stores in this function; + * - skipping all shadow checks; + * - passing initialized arguments to this function's callees. + */ +#define __no_kmsan_checks __attribute__((no_sanitize("kernel-memory"))) +#else +#define __no_sanitize_memory +#define __no_kmsan_checks +#endif + /* * Support for __has_feature(coverage_sanitizer) was added in Clang 13 together * with no_sanitize("coverage"). Prior versions of Clang support coverage diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index a0c55eeaeaf16..63eb90eddad77 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -125,6 +125,12 @@ #define __SANITIZE_ADDRESS__ #endif +/* + * GCC does not support KMSAN. + */ +#define __no_sanitize_memory +#define __no_kmsan_checks + /* * Turn individual warnings and errors on and off locally, depending * on version.