Skip to content

Commit 69e5d32

Browse files
Sergei Trofimovichtorvalds
authored andcommitted
mm: page_alloc: fix page_poison=1 / INIT_ON_ALLOC_DEFAULT_ON interaction
To reproduce the failure we need the following system: - kernel command: page_poison=1 init_on_free=0 init_on_alloc=0 - kernel config: * CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y * CONFIG_INIT_ON_FREE_DEFAULT_ON=y * CONFIG_PAGE_POISONING=y Resulting in: 0000000085629bdd: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0000000022861832: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000000c597f5b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ CPU: 11 PID: 15195 Comm: bash Kdump: loaded Tainted: G U O 5.13.1-gentoo-x86_64 #1 Hardware name: System manufacturer System Product Name/PRIME Z370-A, BIOS 2801 01/13/2021 Call Trace: dump_stack+0x64/0x7c __kernel_unpoison_pages.cold+0x48/0x84 post_alloc_hook+0x60/0xa0 get_page_from_freelist+0xdb8/0x1000 __alloc_pages+0x163/0x2b0 __get_free_pages+0xc/0x30 pgd_alloc+0x2e/0x1a0 mm_init+0x185/0x270 dup_mm+0x6b/0x4f0 copy_process+0x190d/0x1b10 kernel_clone+0xba/0x3b0 __do_sys_clone+0x8f/0xb0 do_syscall_64+0x68/0x80 entry_SYSCALL_64_after_hwframe+0x44/0xae Before commit 51cba1e ("init_on_alloc: Optimize static branches") init_on_alloc never enabled static branch by default. It could only be enabed explicitly by init_mem_debugging_and_hardening(). But after commit 51cba1e, a static branch could already be enabled by default. There was no code to ever disable it. That caused page_poison=1 / init_on_free=1 conflict. This change extends init_mem_debugging_and_hardening() to also disable static branch disabling. Link: https://lkml.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected] Fixes: 51cba1e ("init_on_alloc: Optimize static branches") Signed-off-by: Sergei Trofimovich <[email protected]> Signed-off-by: Kees Cook <[email protected]> Co-developed-by: Kees Cook <[email protected]> Reported-by: Mikhail Morfikov <[email protected]> Reported-by: <[email protected]> Tested-by: <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d9a42b5 commit 69e5d32

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

mm/page_alloc.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -840,21 +840,24 @@ void init_mem_debugging_and_hardening(void)
840840
}
841841
#endif
842842

843-
if (_init_on_alloc_enabled_early) {
844-
if (page_poisoning_requested)
845-
pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
846-
"will take precedence over init_on_alloc\n");
847-
else
848-
static_branch_enable(&init_on_alloc);
849-
}
850-
if (_init_on_free_enabled_early) {
851-
if (page_poisoning_requested)
852-
pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
853-
"will take precedence over init_on_free\n");
854-
else
855-
static_branch_enable(&init_on_free);
843+
if ((_init_on_alloc_enabled_early || _init_on_free_enabled_early) &&
844+
page_poisoning_requested) {
845+
pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
846+
"will take precedence over init_on_alloc and init_on_free\n");
847+
_init_on_alloc_enabled_early = false;
848+
_init_on_free_enabled_early = false;
856849
}
857850

851+
if (_init_on_alloc_enabled_early)
852+
static_branch_enable(&init_on_alloc);
853+
else
854+
static_branch_disable(&init_on_alloc);
855+
856+
if (_init_on_free_enabled_early)
857+
static_branch_enable(&init_on_free);
858+
else
859+
static_branch_disable(&init_on_free);
860+
858861
#ifdef CONFIG_DEBUG_PAGEALLOC
859862
if (!debug_pagealloc_enabled())
860863
return;

0 commit comments

Comments
 (0)