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 42F0FC43334 for ; Fri, 1 Jul 2022 14:28:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232392AbiGAO2k (ORCPT ); Fri, 1 Jul 2022 10:28:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232506AbiGAO1Q (ORCPT ); Fri, 1 Jul 2022 10:27:16 -0400 Received: from mail-ed1-x54a.google.com (mail-ed1-x54a.google.com [IPv6:2a00:1450:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C26053EFB for ; Fri, 1 Jul 2022 07:24:44 -0700 (PDT) Received: by mail-ed1-x54a.google.com with SMTP id o11-20020a056402438b00b0043676efd75dso1894295edc.16 for ; Fri, 01 Jul 2022 07:24:44 -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=j/MMQ3wL35Ri2ZE1mUjRi1/flHRltTweDkn7/EP9qns=; b=A0D6vxcEEYdG93cr58BEviQfu68kGt3tEP1iTrR6OH1MbSU/Ast73yd8+4vsdcPmvE F7ExVCd/cNsiCCMmB9SmZydBoWkU9FpwlqoBDrui/aoc2LQ1w9cfWSsiQe9fPTxl7POg NM5QDGCVrMNlDXqg+DOl6IQHgm2+D05loxFr7+rCszfrFODm8mVgsHCH0aSVcLkJQe7T kky823TWf9SifhaporOMyAr0TbyadwLpD+GGYZT4yExEPXSeAb92kGyVv5kZ7CV8ymNw QQyd/Be2e/kfhOwudlyywf9K4wuV9loKYMofj2XGSkbkbiUtOPenyfcrmjx9kiJdXq0B iddA== 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=j/MMQ3wL35Ri2ZE1mUjRi1/flHRltTweDkn7/EP9qns=; b=u/2gVEyEwlT6l9tsRzt/ICNxJmH21whhqLJ7q7nZ2/VpIJcDDaOoafJcq8E0NyAhU0 EvpHzUmXFrR83yHUJswJZpzUgyodlFiUgoUNjXbtjF2o0vQrXNZNNMK9N4xPc+qNjsrF gDKNCDmGFJHetxrCrO7+a/Bg6gOGGIAlwg+ZAJktGg83GwSf9+rVJVil0IRdXihK/mhh vNSDN+wnMoBDaB6hY7BfAitFfMkZM6yKYjfA8yeBjwEoNBHTezQRSGCmyOXv5W8+Kvgs y4oTb9NdeDS0oC+/iW/kczqQvvgci819XzGO2jtBr27+WwluMObp5p2HnJRwBLgDNiEa WBMg== X-Gm-Message-State: AJIora8wNIfKc5NFVIUpZL2rvaeKmvHsGa/qu2jYHrtif0lx2fT6CTJa 9ZboNqDw9wGmmydwsltzbExsU66LaF0= X-Google-Smtp-Source: AGRyM1tW+YFwdIUQ0n4BqBxiWtFhSDA/V1RYi8OfYlcWw4L6Ky6njb01crp74wyk5/Ql1YeiQo29PS5mWtc= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:a6f5:f713:759c:abb6]) (user=glider job=sendgmr) by 2002:a17:906:9b86:b0:6fe:d37f:b29d with SMTP id dd6-20020a1709069b8600b006fed37fb29dmr14586176ejc.327.1656685482242; Fri, 01 Jul 2022 07:24:42 -0700 (PDT) Date: Fri, 1 Jul 2022 16:22:56 +0200 In-Reply-To: <20220701142310.2188015-1-glider@google.com> Message-Id: <20220701142310.2188015-32-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 31/45] security: kmsan: fix interoperability with auto-initialization 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" Precedence: bulk List-ID: X-Mailing-List: linux-arch@vger.kernel.org Heap and stack initialization is great, but not when we are trying uses of uninitialized memory. When the kernel is built with KMSAN, having kernel memory initialization enabled may introduce false negatives. We disable CONFIG_INIT_STACK_ALL_PATTERN and CONFIG_INIT_STACK_ALL_ZERO under CONFIG_KMSAN, making it impossible to auto-initialize stack variables in KMSAN builds. We also disable CONFIG_INIT_ON_ALLOC_DEFAULT_ON and CONFIG_INIT_ON_FREE_DEFAULT_ON to prevent accidental use of heap auto-initialization. We however still let the users enable heap auto-initialization at boot-time (by setting init_on_alloc=1 or init_on_free=1), in which case a warning is printed. Signed-off-by: Alexander Potapenko --- Link: https://linux-review.googlesource.com/id/I86608dd867018683a14ae1870f1928ad925f42e9 --- mm/page_alloc.c | 4 ++++ security/Kconfig.hardening | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index e8d5a0b2a3264..3a0a5e204df7a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -854,6 +854,10 @@ void init_mem_debugging_and_hardening(void) else static_branch_disable(&init_on_free); + if (IS_ENABLED(CONFIG_KMSAN) && + (_init_on_alloc_enabled_early || _init_on_free_enabled_early)) + pr_info("mem auto-init: please make sure init_on_alloc and init_on_free are disabled when running KMSAN\n"); + #ifdef CONFIG_DEBUG_PAGEALLOC if (!debug_pagealloc_enabled()) return; diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening index bd2aabb2c60f9..2739a6776454e 100644 --- a/security/Kconfig.hardening +++ b/security/Kconfig.hardening @@ -106,6 +106,7 @@ choice config INIT_STACK_ALL_PATTERN bool "pattern-init everything (strongest)" depends on CC_HAS_AUTO_VAR_INIT_PATTERN + depends on !KMSAN help Initializes everything on the stack (including padding) with a specific debug value. This is intended to eliminate @@ -124,6 +125,7 @@ choice config INIT_STACK_ALL_ZERO bool "zero-init everything (strongest and safest)" depends on CC_HAS_AUTO_VAR_INIT_ZERO + depends on !KMSAN help Initializes everything on the stack (including padding) with a zero value. This is intended to eliminate all @@ -218,6 +220,7 @@ config STACKLEAK_RUNTIME_DISABLE config INIT_ON_ALLOC_DEFAULT_ON bool "Enable heap memory zeroing on allocation by default" + depends on !KMSAN help This has the effect of setting "init_on_alloc=1" on the kernel command line. This can be disabled with "init_on_alloc=0". @@ -230,6 +233,7 @@ config INIT_ON_ALLOC_DEFAULT_ON config INIT_ON_FREE_DEFAULT_ON bool "Enable heap memory zeroing on free by default" + depends on !KMSAN help This has the effect of setting "init_on_free=1" on the kernel command line. This can be disabled with "init_on_free=0". -- 2.37.0.rc0.161.g10f37bed90-goog