From patchwork Thu Sep 15 15:04:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12977548 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75534C6FA89 for ; Thu, 15 Sep 2022 15:06:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F01998001D; Thu, 15 Sep 2022 11:06:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EB14D80007; Thu, 15 Sep 2022 11:06:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D546B8001D; Thu, 15 Sep 2022 11:06:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C20EE80007 for ; Thu, 15 Sep 2022 11:06:01 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8A0E51604C7 for ; Thu, 15 Sep 2022 15:06:01 +0000 (UTC) X-FDA: 79914644922.03.D1E258F Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf11.hostedemail.com (Postfix) with ESMTP id 20E1A400A0 for ; Thu, 15 Sep 2022 15:06:00 +0000 (UTC) Received: by mail-ed1-f74.google.com with SMTP id i17-20020a05640242d100b0044f18a5379aso13462906edc.21 for ; Thu, 15 Sep 2022 08:06:00 -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=gorYk6QZYQqsbqX3c5FquLgSIgOkVhkBb0FBAlBlnNE=; b=kplPwV+LYMSeUsnP2/9jWw9wErn1H9lcBvU6cYlfR9a9Dsgm+kvLhjsgtxH1cQy28i BqtFI2VWtQT0leDmXz7ejpScV23UNEpG7mJUJp3p94fZxjT3BON080bQ5cWYXRzOCLrz ZUxUFyu1gz8AEgRa3BvmhVwvPqSacmkXDWPaVsqzafrIjNY67epDctUiPvU7vq5tB49w 88DUeT8ArehnGDKGPcuQSCCI6keHi8snBjlyia1r1w4gojNAEwRsQ3FJChQoxpuNNwb6 M511hTfOPRRHM1hCwd5bgSAMfa1aQqdBSl1zmfrvkVXFvA8JeL076IxXdfuOF0rLR0Cs o2vA== 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=gorYk6QZYQqsbqX3c5FquLgSIgOkVhkBb0FBAlBlnNE=; b=g+Kw7LdXGVWdIJFauFxB3UnBUi5Q5pzixaX6TeVxO/5me83Hil827sIUYQs5Mg6S1T 6DMnlPrzFqj8yWmXWRSogOsGjXxXXwYBXJnJd1f2G7WqZv9sbdTEea+PLgJZkjgXhns0 Em5sqQZwk8rhkrxYPnZU0FpRwe8hgA7PvjMQ1LEG4dpInjGaXNIduIpDD5ZFYCb3rSny ZfuxS+MK6tAztH1I1sdpzLPM+79rbT3Ynef4/GG4IkfVVNTPQWiMng1lSee8W2hBaBfu cb4d1RTSCwLxMjHZBLmhjAH/QTjPxnzT9epchbXxaO4/I6hFckDM4YHqnJ4TpPwKP3bs 9fXA== X-Gm-Message-State: ACrzQf0tNfSeRD3Ygnm0oD3y9u82glr97uLpvNGa+7wRszXW2J012GFh ExWj1kGSBQZj2C3aoei+agnG9L1rhO0= X-Google-Smtp-Source: AMsMyM7Ej6tr71uaPSqPY+N0inRBDQ4LmutJrp7lfFBWMCSzFwVfOzeQ+hQiLlB1cPu959xMS4EWDWvMK6U= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:686d:27b5:495:85b7]) (user=glider job=sendgmr) by 2002:a05:6402:2201:b0:44f:443e:2a78 with SMTP id cq1-20020a056402220100b0044f443e2a78mr293434edb.76.1663254359888; Thu, 15 Sep 2022 08:05:59 -0700 (PDT) Date: Thu, 15 Sep 2022 17:04:04 +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-31-glider@google.com> Subject: [PATCH v7 30/43] 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 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663254361; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gorYk6QZYQqsbqX3c5FquLgSIgOkVhkBb0FBAlBlnNE=; b=RbCm2HNnWXx0hPjOkxHnxVxwE+cS5KlLXDLUPZKWUb+CFfSP9EcKOvmETwYLV2NYwbzSwX VZ4w8wZ/q00q8llJXALzWgPW51TlcDdx7Knr3XYHHh05GqKjKzWw0JwCzk3RnOHf9jFZV2 65+9F4BBDDz0cbkAjph7FH4eCweaGlk= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=kplPwV+L; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 3Vz8jYwYKCIImrojkxmuumrk.iusrot03-ssq1giq.uxm@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3Vz8jYwYKCIImrojkxmuumrk.iusrot03-ssq1giq.uxm@flex--glider.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663254361; a=rsa-sha256; cv=none; b=MCVP00UH5gHONjBEomG5jRPvxfjG/XEliycn41TdL/cAyy/VDxbb99KeENPSDo1imhZXil YuYcng2/OdbYnUiYLLJigPSnINo3ZS0f8dwgrUUKqzX+5JmZfuOkD0fCa8X9w2blIMLuU6 GngDBkTjXK8HKnXBXMgwcA+9Lc+meWM= Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=kplPwV+L; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 3Vz8jYwYKCIImrojkxmuumrk.iusrot03-ssq1giq.uxm@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3Vz8jYwYKCIImrojkxmuumrk.iusrot03-ssq1giq.uxm@flex--glider.bounces.google.com X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 20E1A400A0 X-Stat-Signature: 6euxxpo41ku959pfx311jcgpycy3eez7 X-HE-Tag: 1663254360-288376 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 b28093e3bb42a..e5eed276ee41d 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -936,6 +936,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".