Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp537894imw; Wed, 13 Jul 2022 03:27:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tL6vH32TrO9Bw0ifdn6t00GfJUb4NLvUjgharY2A8Oms29ho2zFM5pIWVTFqTYja/PDZck X-Received: by 2002:a17:906:2086:b0:712:1257:77bf with SMTP id 6-20020a170906208600b00712125777bfmr2849284ejq.655.1657708046503; Wed, 13 Jul 2022 03:27:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657708046; cv=none; d=google.com; s=arc-20160816; b=tpPnm1HroMW58L91VxJzpSOISraYtLMfXxePZh91Hmmhk12kphdA1jBqu1I73H5SUd 7i6r7TR0NL5hA6Kd/v5luRhv5Z3ZydONSBy8O+CVFBYbqN90diwoardbrg+wOGLdm+Uy Ly/0BNopSiIR66NueDUAPyEmlj6HYZf/HYlyZoyWZEDYdijRFiENLpNjIMDOhb8ggWVu HnQafry9EILxyS5Rtr6WlYPOWdJpyFykfmRFK1OEpNmiD37p4Ip6UvyYgr88L/OYLuGR OKKrXBrNsTzWyyqN+UcR9NsNjpDqUoQW0n2MoJB0g8Ty6qcWrRXfG+5Zy1cKidCo7g6g a5tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=f6Y9qjwogxCtal7OxlGnHDAF4wB3anj4wqmO3ly+ml0=; b=0znem+2WejidgdTSKfDa27AYO+jE7yunDTS3l5iz6xE9AH3+1JAFvSAabP8InXnLH9 0y/Vl5+h/OYdp9ApYMlNqLd7f6hX+l8cttW3hzJr7bvutFlboNuy3CwdTM5qp8j69CYW eSicrleJbMSJ8b+KYOyIdL2WduzjDQPJDu/sNExKLgV6g182Mbez5komerT7xtBQY9E3 V+zFx4uOEo3R1LpLIGjHtlfv79o7vp091EMQCtyKJfaMogte0azYKxCbxXM/7bsprtwr KtmRTPg6gmY7QV0HVz55tTWSv7N+323hCeQ8MKjVTZBbv6PM5YHgNHixLJApjAbFdzTl +1cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=he3+yyZi; 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 hw19-20020a170907a0d300b006febfa8bf0asi13628069ejc.509.2022.07.13.03.27.01; Wed, 13 Jul 2022 03:27:26 -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=he3+yyZi; 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 S235255AbiGMKE5 (ORCPT + 99 others); Wed, 13 Jul 2022 06:04:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234441AbiGMKE4 (ORCPT ); Wed, 13 Jul 2022 06:04:56 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD32ED4449 for ; Wed, 13 Jul 2022 03:04:54 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id i204-20020a1c3bd5000000b003a2fa488efdso570792wma.4 for ; Wed, 13 Jul 2022 03:04:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=f6Y9qjwogxCtal7OxlGnHDAF4wB3anj4wqmO3ly+ml0=; b=he3+yyZi6Tsrcv7LH0IV7Ke1Rsii76jKm9NNxzRjpskQ6BJuY6vU4yOQTSEts/c11L djSaAdwjki0dcFTLJh+YzipCWg4yVHQU3VlTKfFaB9iq77W3kRpG91Ed74Q8nYfad4VR izYayhzzyj1J7Juuf1UWdOh1+9NNA9HTztb9LkL2b/UKb4qEksvXWffDeZNa4OV4BYv2 uqbIuHe184MFeTmBmGHh1zB2RsJDoCQhrwonLCtAB8CFMh/CrqaGMDZoMrGbsE/vMB5E vbjhht34Ff64Ouirs+J801C6TEtd+J/hdGatsmmUlrhZeW813xb/9+vlIFxclfXi4TKb n8jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=f6Y9qjwogxCtal7OxlGnHDAF4wB3anj4wqmO3ly+ml0=; b=TYNFn2GsWA6yDCypgkIo7oq4Xh05rved94H07DOPuezOat5To4pxap4IzaF6QnHt/N PjPTc5lDZpazqQzYg+sqZNpWwtYSitXbMv7NNLDUW2TloQh0T/AWZN2MqeaFy5ypRUqf v/vPSuuxp1hnYe8LDxJaDPyryigN1am58tol9x5A+ed6j8gzaJM8bKvP9/rTxleVmWE2 SUg9rqp5pAx8v6h/O0j8f9dSYrTyZzWDBLKie+Z63Tnpiobb28hX5MecPOe/d2M1Bb7g N5QxoLVjo+gDPaZEJKS++84y5TpLAhSH7Asg/iSIK5Uwaj4fFF72E3L7XNZLi3iCWxq0 ox8g== X-Gm-Message-State: AJIora+QlysXfEeGXpzj2u9uHAJz9ne4PcmB+q3321kzlSz6tazSoMKG SbtceVcg/3otaYYt3/qFVtHCtQ== X-Received: by 2002:a1c:1902:0:b0:3a2:ee85:3934 with SMTP id 2-20020a1c1902000000b003a2ee853934mr7963222wmz.31.1657706693167; Wed, 13 Jul 2022 03:04:53 -0700 (PDT) Received: from elver.google.com ([2a00:79e0:9c:201:63e6:a6c0:5e2a:ac17]) by smtp.gmail.com with ESMTPSA id p6-20020a05600c358600b003a2e2ba94ecsm1640729wmq.40.2022.07.13.03.04.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 03:04:52 -0700 (PDT) Date: Wed, 13 Jul 2022 12:04:46 +0200 From: Marco Elver To: Alexander Potapenko 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 , 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 Subject: Re: [PATCH v4 11/45] kmsan: add KMSAN runtime core Message-ID: References: <20220701142310.2188015-1-glider@google.com> <20220701142310.2188015-12-glider@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220701142310.2188015-12-glider@google.com> User-Agent: Mutt/2.2.3 (2022-04-12) X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 On Fri, Jul 01, 2022 at 04:22PM +0200, 'Alexander Potapenko' via kasan-dev wrote: [...] > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug > index 2e24db4bff192..59819e6fa5865 100644 > --- a/lib/Kconfig.debug > +++ b/lib/Kconfig.debug > @@ -963,6 +963,7 @@ config DEBUG_STACKOVERFLOW > > source "lib/Kconfig.kasan" > source "lib/Kconfig.kfence" > +source "lib/Kconfig.kmsan" > > endmenu # "Memory Debugging" > > diff --git a/lib/Kconfig.kmsan b/lib/Kconfig.kmsan > new file mode 100644 > index 0000000000000..8f768d4034e3c > --- /dev/null > +++ b/lib/Kconfig.kmsan > @@ -0,0 +1,50 @@ > +# SPDX-License-Identifier: GPL-2.0-only > +config HAVE_ARCH_KMSAN > + bool > + > +config HAVE_KMSAN_COMPILER > + # Clang versions <14.0.0 also support -fsanitize=kernel-memory, but not > + # all the features necessary to build the kernel with KMSAN. > + depends on CC_IS_CLANG && CLANG_VERSION >= 140000 > + def_bool $(cc-option,-fsanitize=kernel-memory -mllvm -msan-disable-checks=1) > + > +config HAVE_KMSAN_PARAM_RETVAL > + # Separate check for -fsanitize-memory-param-retval support. This comment doesn't add much value, maybe instead say that "Supported only by Clang >= 15." > + depends on CC_IS_CLANG && CLANG_VERSION >= 140000 Why not just "depends on HAVE_KMSAN_COMPILER"? (All fsanitize-memory-param-retval supporting compilers must also be KMSAN compilers.) > + def_bool $(cc-option,-fsanitize=kernel-memory -fsanitize-memory-param-retval) > + > + HAVE_KMSAN_PARAM_RETVAL should be moved under "if KMSAN" so that this isn't unnecessarily evaluated in every kernel build (saving 1 shelling out to clang in most builds). > +config KMSAN > + bool "KMSAN: detector of uninitialized values use" > + depends on HAVE_ARCH_KMSAN && HAVE_KMSAN_COMPILER > + depends on SLUB && DEBUG_KERNEL && !KASAN && !KCSAN > + select STACKDEPOT > + select STACKDEPOT_ALWAYS_INIT > + help > + KernelMemorySanitizer (KMSAN) is a dynamic detector of uses of > + uninitialized values in the kernel. It is based on compiler > + instrumentation provided by Clang and thus requires Clang to build. > + > + An important note is that KMSAN is not intended for production use, > + because it drastically increases kernel memory footprint and slows > + the whole system down. > + > + See for more details. > + > +if KMSAN > + > +config KMSAN_CHECK_PARAM_RETVAL > + bool "Check for uninitialized values passed to and returned from functions" > + default HAVE_KMSAN_PARAM_RETVAL This can be enabled even if !HAVE_KMSAN_PARAM_RETVAL. Should this be: default y depends on HAVE_KMSAN_PARAM_RETVAL instead? > + help > + If the compiler supports -fsanitize-memory-param-retval, KMSAN will > + eagerly check every function parameter passed by value and every > + function return value. > + > + Disabling KMSAN_CHECK_PARAM_RETVAL will result in tracking shadow for > + function parameters and return values across function borders. This > + is a more relaxed mode, but it generates more instrumentation code and > + may potentially report errors in corner cases when non-instrumented > + functions call instrumented ones. > +