From patchwork Thu Sep 15 15:03:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12977525 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 687F6ECAAA1 for ; Thu, 15 Sep 2022 15:05:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F01BF8D0005; Thu, 15 Sep 2022 11:04:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E8C8B8D0001; Thu, 15 Sep 2022 11:04:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB6058D0005; Thu, 15 Sep 2022 11:04:59 -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 BD3A78D0001 for ; Thu, 15 Sep 2022 11:04:59 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 011DA1C2642 for ; Thu, 15 Sep 2022 15:04:58 +0000 (UTC) X-FDA: 79914642276.25.E3AB8CC Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf26.hostedemail.com (Postfix) with ESMTP id 9BC021400D1 for ; Thu, 15 Sep 2022 15:04:58 +0000 (UTC) Received: by mail-ed1-f74.google.com with SMTP id y14-20020a056402440e00b0044301c7ccd9so13177484eda.19 for ; Thu, 15 Sep 2022 08:04:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=FNkIx/jm8VmVwIUxP0UOjGDN2D7zAcH5S0k2sC/Umx8=; b=bQZcA86h1qdzkhJGHuC1vulzCY9/vYojby8OXPpWVu/zRyh5HczDOweVFKdJ4iLXuF GyYCdbY0ycNTlctxGp2Qkk0ioxtzMFkx9QZQlbXKFcl7aeu1akUOI1KeHnOgF6CHm0Fv obXQEHRhmunHmiFIxXCbTaWBthGdhqBefEoxaeY22QEHGd8ceECbBf3z8KFzhi5TCvvT mViYy1jZUqHyxugpaM4vdP8Kdzh+QNJNBDR5XY5YwcZt4wyaxBZ9DHAOLj3aRhrrMQXE FJgQqWptGQUPr62YjXrSkGv5rqr0x+LDUJoYI+k2RwY89uUfjbxM4+mQeSfb2/XyzBo6 JcYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=FNkIx/jm8VmVwIUxP0UOjGDN2D7zAcH5S0k2sC/Umx8=; b=vuTef4NuaQMZOJypFYg82sWLiW3Tt88oECevu1tjRGMfRk88x45XrKRkYPBENooCZa +ifGsmqW7rOdMoDVPpEbQN3XJZAZKJa0Qf6omfS0RX3q4h/iU1i4z68efqMfviKVFyy7 kuRFuJPIvShNOrfsadjaI+cxWLlaOdIM6TaHrbZOmL1MO4QUffNDEAnwpq9CuOxgdOMl fHnDvgk8An4JZUgLcwO9AxZ72Jr/FtXfRrGd1LPOexi6RyUgQqiXYwkCH1Kr44sZDZGm sb5QfJfk6SSSPQyDRDPSfeUmT9FHuwSDUTymNPqeLps4qHSS3pkXdHLWBn9YdV/R4PY6 xuiw== X-Gm-Message-State: ACrzQf1i9IJTozmXMZpbapMiwsfhLN7h6DH/mlZggdk1F5T/D3+Rsr8z +e8bYhv9dDOUe3SauUURod0R0X1YaZM= X-Google-Smtp-Source: AMsMyM6w2KbV7Uo7UXovOlHDL9eur1WPj/OeZn6zE9SBsrD7mTMRXaISFQ/Ug34qtuaBk27l/iQo9UqsYqI= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:686d:27b5:495:85b7]) (user=glider job=sendgmr) by 2002:a17:907:94c7:b0:780:7ccd:aca7 with SMTP id dn7-20020a17090794c700b007807ccdaca7mr323937ejc.136.1663254297632; Thu, 15 Sep 2022 08:04:57 -0700 (PDT) Date: Thu, 15 Sep 2022 17:03:41 +0200 In-Reply-To: <20220915150417.722975-1-glider@google.com> Mime-Version: 1.0 References: <20220915150417.722975-1-glider@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220915150417.722975-8-glider@google.com> Subject: [PATCH v7 07/43] 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 Biggers , 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 , Stephen Rothwell , 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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663254298; a=rsa-sha256; cv=none; b=N6KJiW6aaIlVp+/EhZ5xqyxDT/rRaIRPSXQQq3tWSMQoYvjiG52765ury/l0ToO32Ma5p6 giDp19OgQaHjDNGLZWS+v7EDAuKNmnGbKfbCvK8Uy8yUanccogKtlNMv/TbbMHfKlk81fp yk3HgxBNYchKpSmyW6enDHboTd/7luw= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=bQZcA86h; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 3GT8jYwYKCEQmrojkxmuumrk.iusrot03-ssq1giq.uxm@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3GT8jYwYKCEQmrojkxmuumrk.iusrot03-ssq1giq.uxm@flex--glider.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663254298; 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=FNkIx/jm8VmVwIUxP0UOjGDN2D7zAcH5S0k2sC/Umx8=; b=Lu4T/UJWdfhs+9i/Lk16QbCgYQ7NyxSkO2g3qowcAY0hyIdAjAUOxoy1D4ezld3C/ul3Ki H2eqK5bk9Idd3sknawbY0IURk4zzthlEBoxg81OkITC02Jmzs+BHH/NpdZZ+9l00+kHbmU uPCW5whrsqX1ARjY0TYfA0KCSFNZ724= X-Rspam-User: X-Rspamd-Queue-Id: 9BC021400D1 X-Rspamd-Server: rspam05 X-Stat-Signature: 3f6ift3oi17uhye65offc6oxfj7ge3ud Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=bQZcA86h; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 3GT8jYwYKCEQmrojkxmuumrk.iusrot03-ssq1giq.uxm@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3GT8jYwYKCEQmrojkxmuumrk.iusrot03-ssq1giq.uxm@flex--glider.bounces.google.com X-HE-Tag: 1663254298-680209 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 9b157b71036f1..f55a37efdb974 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -114,6 +114,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.