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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD952C6FA89 for ; Thu, 15 Sep 2022 15:05:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230366AbiIOPFu (ORCPT ); Thu, 15 Sep 2022 11:05:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230363AbiIOPFS (ORCPT ); Thu, 15 Sep 2022 11:05:18 -0400 Received: from mail-ej1-x64a.google.com (mail-ej1-x64a.google.com [IPv6:2a00:1450:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C27BF54678 for ; Thu, 15 Sep 2022 08:04:59 -0700 (PDT) Received: by mail-ej1-x64a.google.com with SMTP id qk37-20020a1709077fa500b00730c2d975a0so7694910ejc.13 for ; Thu, 15 Sep 2022 08:04:59 -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=7OfgundMTt+YC4iQNnFmvVMPWyUxQUXGix+9tsHbM1h9YxCTsdaDdv19DmlrdEGdMn QjVrrA07CtB1BiX8SKETZwM4mxltWnAmZFXfvObYktZ33wZ2MegG32k430tqNdHOXYA/ Qf3TYcVI9bi6gjGGehusKF3ciGA7kHrWhQhJEkwwvSVzK8yXLt8yNPC0WYZHlwW7XlR0 XP4e9cBSfr79GVfgwV6ZAGg5fAEbYsSZRmqHqKRCPpfBQQ0hQ84jxkeEtqFy2jXUANqt Cc9aZ5XZw/+7KhmpYTl3s5GSiXBbPZwKegp8gCX/lE8vjwtUxqhTXr1V4+UavYzw5l4U l0/g== X-Gm-Message-State: ACrzQf3gq2+KvkwANwoHmDyvl/xdQ24UZFyLVifcecImOJTZLY6kqhra 6DUvF+0S53oTRinOFViq+G+hOsa/qzI= 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-arch@vger.kernel.org __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. -- 2.37.2.789.g6183377224-goog