Received: by 2002:ac0:c50a:0:0:0:0:0 with SMTP id y10csp1332638imi; Fri, 1 Jul 2022 07:40:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vWxq/Z34IdBb1XijqvYvFz96skDV9oY9ai6CEMqDM10yEmLaQo1YUYA7tSCH72nVRnJGA5 X-Received: by 2002:a17:902:f391:b0:16a:2d12:152c with SMTP id f17-20020a170902f39100b0016a2d12152cmr21941474ple.102.1656686434199; Fri, 01 Jul 2022 07:40:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656686434; cv=none; d=google.com; s=arc-20160816; b=uczOsTDXpyygRTPLVjaSpXDcDz78sNbVD9vVX+S2BKxKhLUznA4uo0EDEyzMEv35Jp I43nkmd2llTo6iQo1kndyT4vwuw7tOuxMO5V07ISJeFlVRfz9b44rfTdKao1qTmx/yni oOst2f7lAVuBB5yKv2uuQD9KceA8uklTDFr0sUj0U69QjnMWJj0r7ZkrIToK9ZnV/NZ3 237aR8H8Kpl6GWuEjYWLuaEnzWFqqLBV9NQQg44VOwNA2FZcS8Gyeojv3LAx8CFxSqlG k2dCJFuu0qZrgbs0fpv9POps1xzCvA2N4dCC0/97M+MXv4WptEUrK2yBsngz9pEaXpz8 E7zw== 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:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=gkw9YA7vb5ti0YajzjGN1OXbVHAqDO+SEh0OPXXltUo=; b=zNA9ugDfkQSw/5yNu0pe5N2qfiIBHh34x3l/N20zmRDHdSIv8pT6SlwPKBjPTZjwKN yrqgrQB6QBexk5y5qSWX1tis04Mg2rxi+bsqfLpCfgqwILHne3nZYzH0yQYV5t/ObDb0 LT9UygrdfjIgh3IEy5Hg6uxjCxgCDS688cOoGvcu+tTwoAu2pSEKrAXJBUccsVbJDQ7L N4bC7t+gh316eargTS9vfdtBlqNvQGfp4EW80UcHi1Ff0ySz9r4RqV/jIwEdaGhqjx04 pX6EKlslg9VbQJ7FP4rKcGRWqV1tzh/9MHNqlm+sWEo8jsvjcftAoLjoz4zWW6x6wox3 8Kkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DJbRcfFJ; 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 gl10-20020a17090b120a00b001ec9d364ec6si7059609pjb.50.2022.07.01.07.40.23; Fri, 01 Jul 2022 07:40:34 -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=DJbRcfFJ; 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 S231719AbiGAOYU (ORCPT + 99 others); Fri, 1 Jul 2022 10:24:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232249AbiGAOXh (ORCPT ); Fri, 1 Jul 2022 10:23:37 -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 7533B39B84 for ; Fri, 1 Jul 2022 07:23:35 -0700 (PDT) Received: by mail-ed1-x549.google.com with SMTP id r12-20020a05640251cc00b00435afb01d7fso1869909edd.18 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=tMIXe9sw7E1b6atRUI6VIA1QkhcbAdvvhveBlYJrJxMTr5syKyi+kKonBdBmIXA2po 6Ca75SXsfvC+0WtaVrMuD8Lzwwjsyl6fsKpwl5mYyTt5Nw0fg0ajeYtE616Az/zlTyJG HHZJoxPqdBCwRPJZWKyYkVUK9I5Jy3yBzcvnpQiFpHx1mE18BWOqkOxrcQ6CvpruVxRv G8+GvJRaogGDha0RZP7Bg/U+bCaGqqETYa/qK3yu6lc8ke3a/6JB0EXbBTecU6KTtnu3 4Ycb6qx7WJmb3MuakdiNMQg1DnyoDNq+9BH6+ykIzcCC11WJH6coGEF3rjPd+EpSJxpw ebbQ== X-Gm-Message-State: AJIora8Ce0uglqR/g0UqGoSOJ1LYpjbd/goZE4hPLrR2rceW72AOMn7P geq30de1iLq4Xng/iFsHNYFzmLWIIC8= 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 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,T_SCC_BODY_TEXT_LINE,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 --- 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. -- 2.37.0.rc0.161.g10f37bed90-goog