Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/mm_init: Introduce a boot parameter for check_pages

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>

authored by

Joshua Hahn and committed by
Mike Rapoport (Microsoft)
83c8f7b5 ac3fd01e

+17 -1
+8
Documentation/admin-guide/kernel-parameters.txt
··· 669 669 nokmem -- Disable kernel memory accounting. 670 670 nobpf -- Disable BPF memory accounting. 671 671 672 + check_pages= [MM,EARLY] Enable sanity checking of pages after 673 + allocations / before freeing. This adds checks to catch 674 + double-frees, use-after-frees, and other sources of 675 + page corruption by inspecting page internals (flags, 676 + mapcount/refcount, memcg_data, etc.). 677 + Format: { "0" | "1" } 678 + Default: 0 (1 if CONFIG_DEBUG_VM is set) 679 + 672 680 checkreqprot= [SELINUX] Set initial checkreqprot flag value. 673 681 Format: { "0" | "1" } 674 682 See security/selinux/Kconfig help text.
+9 -1
mm/mm_init.c
··· 2525 2525 2526 2526 DEFINE_STATIC_KEY_MAYBE(CONFIG_DEBUG_VM, check_pages_enabled); 2527 2527 2528 + static bool check_pages_enabled_early __initdata; 2529 + 2530 + static int __init early_check_pages(char *buf) 2531 + { 2532 + return kstrtobool(buf, &check_pages_enabled_early); 2533 + } 2534 + early_param("check_pages", early_check_pages); 2535 + 2528 2536 /* 2529 2537 * Enable static keys related to various memory debugging and hardening options. 2530 2538 * Some override others, and depend on early params that are evaluated in the ··· 2542 2534 static void __init mem_debugging_and_hardening_init(void) 2543 2535 { 2544 2536 bool page_poisoning_requested = false; 2545 - bool want_check_pages = false; 2537 + bool want_check_pages = check_pages_enabled_early; 2546 2538 2547 2539 #ifdef CONFIG_PAGE_POISONING 2548 2540 /*