memblock: introduce check_pages boot parameter

... to decouple simple checks for page state on allocation and free from
 CONFIG_DEBUG_VM.
 
 check_pages parameter allows enabling page checking without building kernel
 with CONFIG_DEBUG_VM or forcing init_on_{alloc, free} or other heavier
 mechanisms.
 -----BEGIN PGP SIGNATURE-----
 
 iQFEBAABCgAuFiEEeOVYVaWZL5900a/pOQOGJssO/ZEFAmk1p20QHHJwcHRAa2Vy
 bmVsLm9yZwAKCRA5A4Ymyw79kZT4B/4wGhbJjAe6RbBsco9jR6p5veLPOj1DFGgf
 nk8MWqgij1clDvOKzXfJPDiXWzsfbt1/z1nak0DMOx5jjqpsZe9RmIfVZA48nMQS
 WJdPC44NQU/xCwnxZ2xRvf6tzc9ehuvELDXAfT+Qg+4YqGtre2HxLy7hSDduMuJG
 p5/9Crt5sf4d2S9J2ctlZYIBf6GB8I6OGQ419eGN7tn5bvQfUNxgpcIYO6CDXw2A
 mNVqYrlHvzeOkQ78cmnj/gBDLyo8KUvYd2ZavSK9SiIJK3XIV2+Goq5KfTpM0yvS
 XC0x1IP/upOO3fYKfpc1tA3vGDc9PPtCK9RqApj1U2oG7X4H/VJu
 =7raZ
 -----END PGP SIGNATURE-----

Merge tag 'memblock-6.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock

Pull memblock update from Mike Rapoport:
 "Introduce a 'check_pages' boot parameter to decouple simple checks for
  page state on allocation and free from CONFIG_DEBUG_VM.

  This allows enabling page checking without building kernel with
  CONFIG_DEBUG_VM or forcing init_on_{alloc, free} or other heavier
  mechanisms"

* tag 'memblock-6.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock:
  mm/mm_init: Introduce a boot parameter for check_pages
master
Linus Torvalds 2025-12-07 08:56:10 -08:00
commit 67a454e6b1
2 changed files with 17 additions and 1 deletions

View File

@ -767,6 +767,14 @@ Kernel parameters
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.

View 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
/*