]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mm/mm_init: Introduce a boot parameter for check_pages
authorJoshua Hahn <joshua.hahnjy@gmail.com>
Mon, 1 Dec 2025 18:07:38 +0000 (10:07 -0800)
committerMike Rapoport (Microsoft) <rppt@kernel.org>
Thu, 4 Dec 2025 17:40:25 +0000 (19:40 +0200)
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 <sj@kernel.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
Signed-off-by: Joshua Hahn <joshua.hahnjy@gmail.com>
Link: https://patch.msgid.link/20251201180739.2330474-1-joshua.hahnjy@gmail.com
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Documentation/admin-guide/kernel-parameters.txt
mm/mm_init.c

index 6c42061ca20e581b5192b66c6f25aba38d4f8ff8..acdc7fbdecacf02286f7e8f35fb3ccd37bb73c1a 100644 (file)
                        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.
index 7712d887b6963b27ea737aeac997c2418cc87651..220b7c6b5fb2cef878ba396b79e727c0f84d443c 100644 (file)
@@ -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
        /*