From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39FD32D8367; Wed, 3 Dec 2025 09:01:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764752504; cv=none; b=bp4JW3/E6TIhRQ9nxnv3EOYDaHlDOyeUmyv9owLjCCUrz4m3pSYNgivD5kiYUbaUiebJTTPWA1Fhg2EeKcObu2z8zPonZmG+Wu31ahvsL5olk9WJUF5x/zXDprBLjJIHXC6a67GZu8YRaXdIA09N4rxwdJg88eORGb7W3esnoFw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764752504; c=relaxed/simple; bh=ofOg7y0Oxn0ScACDF36NJxu/w3xWs0qEUQIPGUp3Icg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ludvjMWbeLcgYfKEMTASRRuX1IjXfGiZC7bwaSgAIU4oZWZH6XkqCIGKe354VgzL6ZKeFBd7bmcNvyUcuFmCK3bMFf3iI1imT2xSAhah684NxE5IEYas+n9xAmfoH+0N+03P4SdPr9SiQqxEqauGbWm/2SumZQLngyTwKhV4tiI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1B4E6339; Wed, 3 Dec 2025 01:01:34 -0800 (PST) Received: from [10.163.49.22] (unknown [10.163.49.22]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6AF5A3F59E; Wed, 3 Dec 2025 01:01:38 -0800 (PST) Message-ID: Date: Wed, 3 Dec 2025 14:31:35 +0530 Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] mm/mm_init: Introduce a boot parameter for check_pages To: Joshua Hahn , Andrew Morton Cc: Vlastimil Babka , SeongJae Park , Jonathan Corbet , Mike Rapoport , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-team@meta.com References: <20251201180739.2330474-1-joshua.hahnjy@gmail.com> Content-Language: en-US From: Anshuman Khandual In-Reply-To: <20251201180739.2330474-1-joshua.hahnjy@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 01/12/25 11:37 PM, Joshua Hahn wrote: > Use-after-free and double-free bugs can be very difficult to track down. > The kernel is good at tracking these and preventing bad pages from being > used/created through simple checks gated behind "check_pages_enabled". > > Currently, the only ways to enable this flag is by building with > CONFIG_DEBUG_VM, or as a side effect of other checks such as > init_on_{alloc, free}, page_poisoning, or debug_pagealloc among others. > These solutions are powerful, but may often be too coarse in balancing > the performance vs. safety that a user may want, particularly in > latency-sensitive production environments. > > Introduce a new boot parameter "check_pages", which enables page checking > with no other side effects. It takes kstrbool-able inputs as an argument > (i.e. 0/1, true/false, on/off, ...). This patch is backwards-compatible; > setting CONFIG_DEBUG_VM still enables page checking. > > Acked-by: SeongJae Park > Acked-by: Michal Hocko > Signed-off-by: Joshua Hahn > --- > v2 --> v3: > - Dropped the second patch. I may pursue it at another time : -) > - Variable renaming (dropping leading _) and cleaner check in > mem_debugging_and_hardening_init, as suggested by Mike Rapoport > v1 --> v2: > - Changed check_pages from a build config into a boot config, as suggested > by Vlastimil. > - Introduced the second patch, which decouples page checking from > init_on_page_alloc and init_on_page_free. > --- > Documentation/admin-guide/kernel-parameters.txt | 8 ++++++++ > mm/mm_init.c | 10 +++++++++- > 2 files changed, 17 insertions(+), 1 deletion(-) > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > index 6c42061ca20e..acdc7fbdecac 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -669,6 +669,14 @@ > nokmem -- Disable kernel memory accounting. > nobpf -- Disable BPF memory accounting. > > + check_pages= [MM,EARLY] Enable sanity checking of pages after > + allocations / before freeing. This adds checks to catch > + double-frees, use-after-frees, and other sources of > + page corruption by inspecting page internals (flags, > + mapcount/refcount, memcg_data, etc.). > + Format: { "0" | "1" } > + Default: 0 (1 if CONFIG_DEBUG_VM is set) > + > checkreqprot= [SELINUX] Set initial checkreqprot flag value. > Format: { "0" | "1" } > See security/selinux/Kconfig help text. > diff --git a/mm/mm_init.c b/mm/mm_init.c > index c6812b4dbb2e..fc2a6f1e518f 100644 > --- a/mm/mm_init.c > +++ b/mm/mm_init.c > @@ -2525,6 +2525,14 @@ early_param("init_on_free", early_init_on_free); > > DEFINE_STATIC_KEY_MAYBE(CONFIG_DEBUG_VM, check_pages_enabled); > > +static bool check_pages_enabled_early __initdata; > + > +static int __init early_check_pages(char *buf) > +{ > + return kstrtobool(buf, &check_pages_enabled_early); > +} > +early_param("check_pages", early_check_pages); > + > /* > * Enable static keys related to various memory debugging and hardening options. > * Some override others, and depend on early params that are evaluated in the > @@ -2534,7 +2542,7 @@ DEFINE_STATIC_KEY_MAYBE(CONFIG_DEBUG_VM, check_pages_enabled); > static void __init mem_debugging_and_hardening_init(void) > { > bool page_poisoning_requested = false; > - bool want_check_pages = false; > + bool want_check_pages = check_pages_enabled_early; > > #ifdef CONFIG_PAGE_POISONING > /* LGTM. Also a very nice write up for the commit message explaining the new kernel parameter rationale comprehensively. Reviewed-by: Anshuman Khandual