Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp969590rwn; Thu, 15 Sep 2022 08:40:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4uSaWBXH9B8dmjT/mwiyXIJ8yKSzmndVz2DIrHfwjUrh55IlpKrjURWcS/NkJ/d+NJO2nL X-Received: by 2002:a17:902:e552:b0:16d:2a83:e751 with SMTP id n18-20020a170902e55200b0016d2a83e751mr160427plf.39.1663256442268; Thu, 15 Sep 2022 08:40:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663256442; cv=none; d=google.com; s=arc-20160816; b=BFGmhW6HEv5p4W6N8MG0NIdExKuXkIDy+mXAa/bbH+eGNNUwOC/Kq/aFrdY5Vk7IGO M0Vc/I/tfRSz7qbmAi6RAE3EpS4MKSTq50miNlPrgvZ/dtWY1DSKJ0uLQFsB8gjcbj6W krCFGMlgzwpVnshwf00TYL8r6oY7Kbv5NuF+nn4Yh5MmIm7bczH2bhzppr5kGv+J0QrY Wl9jGE8tNag8/46EuDgKQM7QKhCEivZiGQi1XsmYViROKeWb/xj7py2D5jYatsuq7Chf jlkcuhKByIfOEqYiImuSsuuQxOotIwYqs6sRBxHKfPNASvRN9O9l62LQEy2mxouGXnKc If3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=FNkIx/jm8VmVwIUxP0UOjGDN2D7zAcH5S0k2sC/Umx8=; b=JuJCwN4uIJl/zMHHFrxQAvwL75W/4gKR16sSElBHd2ul43BxI7/WkIU+SxkTHVBq4i B34agoOsw2fSN0vykoloTCxspLvL6js1cyKYH/eWocwMXCQDwEMow9usqa909+PS9rES X0f3D6iYPUHX07B7v8ZCnmDcWGK6uVX/5RvVY4tCXVgLdiHeUm8kFH4VwVnHymCpaeDH chK5xxMdmEZMHGBdTtZaXF/VRUMq/Q7xQY/LkIreg+M4+LIAC6hlE69Bvnmh2WiqNzPm P9js6Pbjh1NzO/Jtg/3tmkKeZTVNEEwmky9uZ0B/RjbZKE1nEp5u1nT/KpqtN0z9gbGy glXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=bQZcA86h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id be2-20020a170902aa0200b001786f5de977si2259724plb.162.2022.09.15.08.40.29; Thu, 15 Sep 2022 08:40:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=bQZcA86h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S230435AbiIOPFx (ORCPT + 99 others); Thu, 15 Sep 2022 11:05:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230148AbiIOPFS (ORCPT ); Thu, 15 Sep 2022 11:05:18 -0400 Received: from mail-ed1-x549.google.com (mail-ed1-x549.google.com [IPv6:2a00:1450:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C294E54CAA for ; Thu, 15 Sep 2022 08:04:59 -0700 (PDT) Received: by mail-ed1-x549.google.com with SMTP id h13-20020a056402280d00b004528c8400afso5032592ede.6 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=R5NIuPPC0gPtyN3HPyFEbibt8TS42yqMGHnil+Tq2IQZ6p/9DgL5CFiBI/ogs7x1X1 CZLybp59gv1Vt6mjZmvIulbBLDB0xHgOqw3pHzXLuF6TGFlGKzmIGTzbKNeBJaCVjcDG LobxFdbK1UOxYHGRFOHBdA847b2Ig8kWXK9mWPJvpozO5OLgckrQImvutWjZWsgFSeGQ PdbbuCQqNfcuIj6z1UITjEn1zvhbU/pAQAuOx2gih5591exm9kFZZ6CKUmhde6dfX0LG 1H6MdIL1L7OI55Bx1KLS5mZXjfenk4XYLTl1EHW0dkkkO33eZ4PCncV+4nPvIszBKvmy D00w== X-Gm-Message-State: ACrzQf12FPpEuNuNiMj2QWpFr6kjywim+6f7JLTWFTxkLfLr1dDnq9z6 oWxyVd39/QHujxRNagudLAmv98+svto= 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" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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