Skip to contentSkip to conversation

v5.12+ regression on page_poison=1 i_on_free=0 i_on_alloc=0 warnings

PATCH In review Sergei Trofimovich 4 participants 7 messages Jul 11, 2021 – Jul 17, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

In
https://bugs.gentoo.org/801481
https://bugzilla.kernel.org/show_bug.cgi?id=213697
bowsingbetee noticed that the following setup causes kernel to complain about poisoning on memset(0) pages:

- 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

v5.12 works ok, boots as:

  [    0.009691][    T0] mem auto-init: stack:off, heap alloc:off, heap free:off

v5.13 warns, boots as:

  [    0.009746][    T0] mem auto-init: stack:off, heap alloc:on, heap free:on

Current 5.14-rc1 is also affected:

[    0.009233][    T0] mem auto-init: stack:off, heap alloc:on, heap free:on
[    0.009234][    T0] mem auto-init: clearing system memory may take some time...
[    0.396784][    T0] pagealloc: memory corruption
[    0.396788][    T0] ffff888100000000: 00 00 00 00 00 00 00 00 00 00 00 00 00
                                         00 00 00  ................

I attempted to bisect it and found the follwing relevant commits:

Before the following commit no warnings were present:

commit 51cba1ebc60df9c4ce034a9f5441169c0d0956c0
Author: Kees Cook <[email protected]>
Date: Thu Apr 1 16:23:43 2021 -0700
init_on_alloc: Optimize static branches

Next after this commit kernel does not boot. Makes it harder to bisect the poisoning warning

After the commit below kernel boots and already complains about poisoning of zero pages:

commit 1bb5eab30d68c1a3d9dbc822e1895e6c06dbe748
Author: Andrey Konovalov <[email protected]>
Date: Thu Apr 29 23:00:02 2021 -0700
kasan, mm: integrate page_alloc init with HW_TAGS

It looks like a case of page_poison=1 not having enough of a priority over init_on_free=0 init_on_alloc=0 at early boot.

Signature · 1 line
  Sergei
#1 lore raw

PATCH 1/1 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

    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
     ? dup_mm+0x37/0x4f0
     mm_init+0x185/0x270
     dup_mm+0x6b/0x4f0
     ? __lock_task_sighand+0x35/0x70
     copy_process+0x190d/0x1b10
     kernel_clone+0xba/0x3b0
     __do_sys_clone+0x8f/0xb0
     do_syscall_64+0x68/0x80
     ? do_syscall_64+0x11/0x80
     entry_SYSCALL_64_after_hwframe+0x44/0xae

Before the 51cba1eb ("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 the 51cba1eb 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.

CC Andrew Morton <[email protected]>
CC Kees Cook <[email protected]>
CC Alexander Potapenko <[email protected]>
CC Thomas Gleixner <[email protected]>
CC Vlastimil Babka <[email protected]>
Reported-by [email protected]
Reported-by Mikhail Morfikov
Fixes 51cba1eb ("init_on_alloc: Optimize static branches")
---
 mm/page_alloc.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
mm/page_alloc.c +10 -6
index 3b97e17806be..46cb4a9c2b50 100644
@@ -840,18 +840,22 @@ void init_mem_debugging_and_hardening(void)
 	}
 #endif
 
-	if (_init_on_alloc_enabled_early) {
-		if (page_poisoning_requested)
+	if (_init_on_alloc_enabled_early ||
+	    IS_ENABLED(CONFIG_INIT_ON_ALLOC_DEFAULT_ON)) {
+		if (page_poisoning_requested) {
 			pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
 				"will take precedence over init_on_alloc\n");
-		else
+			static_branch_disable(&init_on_alloc);
+		} else
 			static_branch_enable(&init_on_alloc);
 	}
-	if (_init_on_free_enabled_early) {
-		if (page_poisoning_requested)
+	if (_init_on_free_enabled_early ||
+	    IS_ENABLED(CONFIG_INIT_ON_FREE_DEFAULT_ON)) {
+		if (page_poisoning_requested) {
 			pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
 				"will take precedence over init_on_free\n");
-		else
+			static_branch_disable(&init_on_free);
+		} else
 			static_branch_enable(&init_on_free);
 	}
 
Signature · 1 line
2.32.0
maintainer
#2 lore raw

Re: [PATCH] mm: page_alloc: fix page_poison=1 / INIT_ON_ALLOC_DEFAULT_ON interaction

Quoted 65 lines · On Mon, 12 Jul 2021 22:58:16 +0100 Sergei Trofimovich <[email protected]> wrote:

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

    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
     ? dup_mm+0x37/0x4f0
     mm_init+0x185/0x270
     dup_mm+0x6b/0x4f0
     ? __lock_task_sighand+0x35/0x70
     copy_process+0x190d/0x1b10
     kernel_clone+0xba/0x3b0
     __do_sys_clone+0x8f/0xb0
     do_syscall_64+0x68/0x80
     ? do_syscall_64+0x11/0x80
     entry_SYSCALL_64_after_hwframe+0x44/0xae

Before the 51cba1eb ("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 the 51cba1eb 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.

...

mm/page_alloc.c +6 -5
@@ -840,18 +840,22 @@ void init_mem_debugging_and_hardening(void)
 	}
 #endif
 
-	if (_init_on_alloc_enabled_early) {
-		if (page_poisoning_requested)
+	if (_init_on_alloc_enabled_early ||
+	    IS_ENABLED(CONFIG_INIT_ON_ALLOC_DEFAULT_ON)) {
+		if (page_poisoning_requested) {
 			pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
 				"will take precedence over init_on_alloc\n");
-		else
+			static_branch_disable(&init_on_alloc);
+		} else
 			static_branch_enable(&init_on_alloc);
 	}
-	if (_init_on_free_enabled_early) {
-		if (page_poisoning_requested)
+	if (_init_on_free_enabled_early ||

mm/page_alloc.c void init_mem_debugging_and_hardening(void) · line 861

Quoted 10 lines
mm/page_alloc.c +4 -1
+	    IS_ENABLED(CONFIG_INIT_ON_FREE_DEFAULT_ON)) {
+		if (page_poisoning_requested) {
 			pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
 				"will take precedence over init_on_free\n");
-		else
+			static_branch_disable(&init_on_free);
+		} else
 			static_branch_enable(&init_on_free);
 	}
 

I'm thinking this is sufficiently serious and sufficiently reported to warrant a cc:stable backport. Agree?

#3 lore raw

Re: [PATCH] mm: page_alloc: fix page_poison=1 / INIT_ON_ALLOC_DEFAULT_ON interaction

Quoted 72 lines · On Tue, 13 Jul 2021 19:00:51 -0700 Andrew Morton <[email protected]>…
Quoted 70 lines · On Mon, 12 Jul 2021 22:58:16 +0100 Sergei Trofimovich <[email protected]> wrote:

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

    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
     ? dup_mm+0x37/0x4f0
     mm_init+0x185/0x270
     dup_mm+0x6b/0x4f0
     ? __lock_task_sighand+0x35/0x70
     copy_process+0x190d/0x1b10
     kernel_clone+0xba/0x3b0
     __do_sys_clone+0x8f/0xb0
     do_syscall_64+0x68/0x80
     ? do_syscall_64+0x11/0x80
     entry_SYSCALL_64_after_hwframe+0x44/0xae

Before the 51cba1eb ("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 the 51cba1eb 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.

...

mm/page_alloc.c +8 -6
@@ -840,18 +840,22 @@ void init_mem_debugging_and_hardening(void)
 	}
 #endif
 
-	if (_init_on_alloc_enabled_early) {
-		if (page_poisoning_requested)
+	if (_init_on_alloc_enabled_early ||
+	    IS_ENABLED(CONFIG_INIT_ON_ALLOC_DEFAULT_ON)) {
+		if (page_poisoning_requested) {
 			pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
 				"will take precedence over init_on_alloc\n");
-		else
+			static_branch_disable(&init_on_alloc);
+		} else
 			static_branch_enable(&init_on_alloc);
 	}
-	if (_init_on_free_enabled_early) {
-		if (page_poisoning_requested)
+	if (_init_on_free_enabled_early ||
+	    IS_ENABLED(CONFIG_INIT_ON_FREE_DEFAULT_ON)) {
+		if (page_poisoning_requested) {
 			pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
 				"will take precedence over init_on_free\n");
-		else
Quoted 8 lines

mm/page_alloc.c void init_mem_debugging_and_hardening(void) · line 861

Quoted 5 lines
mm/page_alloc.c +2 -0
+			static_branch_disable(&init_on_free);
+		} else
 			static_branch_enable(&init_on_free);
 	}
 

I'm thinking this is sufficiently serious and sufficiently reported to warrant a cc:stable backport. Agree?

I agree. The patch might be tricky to apply as is too far back. But current release should be fine.

Signature · 1 line
  Sergei
#4 lore raw

Re: [PATCH] mm: page_alloc: fix page_poison=1 / INIT_ON_ALLOC_DEFAULT_ON interaction

In reply to Sergei Trofimovich
Quoted 31 lines · Sergei Trofimovich

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

    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
     ? dup_mm+0x37/0x4f0
     mm_init+0x185/0x270
     dup_mm+0x6b/0x4f0
     ? __lock_task_sighand+0x35/0x70
     copy_process+0x190d/0x1b10
     kernel_clone+0xba/0x3b0
     __do_sys_clone+0x8f/0xb0
     do_syscall_64+0x68/0x80
     ? do_syscall_64+0x11/0x80
     entry_SYSCALL_64_after_hwframe+0x44/0xae
Quoted 3 lines

Before the 51cba1eb ("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 init_mem_debugging_and_hardening() is always called (by mm_init()).

Quoted 26 lines

But after the 51cba1eb 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.

CC Andrew Morton <[email protected]>
CC Kees Cook <[email protected]>
CC Alexander Potapenko <[email protected]>
CC Thomas Gleixner <[email protected]>
CC Vlastimil Babka <[email protected]>
Reported-by [email protected]
Reported-by Mikhail Morfikov
Fixes 51cba1eb ("init_on_alloc: Optimize static branches")
---
 mm/page_alloc.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
mm/page_alloc.c +0 -0
index 3b97e17806be..46cb4a9c2b50 100644

mm/page_alloc.c void init_mem_debugging_and_hardening(void) · line 844

Quoted 7 lines
mm/page_alloc.c +2 -2
@@ -840,18 +840,22 @@ void init_mem_debugging_and_hardening(void)
 	}
 #endif
 
-	if (_init_on_alloc_enabled_early) {
-		if (page_poisoning_requested)
+	if (_init_on_alloc_enabled_early ||
+	    IS_ENABLED(CONFIG_INIT_ON_ALLOC_DEFAULT_ON)) {

This doesn't look right. _init_on_alloc_enabled_early already has the same value:

static bool _init_on_alloc_enabled_early __read_mostly

                                = IS_ENABLED(CONFIG_INIT_ON_ALLOC_DEFAULT_ON);

So checking this is just a side-effect of how static_branch_maybe() happens to be behaving.

Quoted 10 lines
mm/page_alloc.c +3 -3
+		if (page_poisoning_requested) {
 			pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
 				"will take precedence over init_on_alloc\n");
-		else
+			static_branch_disable(&init_on_alloc);
+		} else
 			static_branch_enable(&init_on_alloc);
 	}
-	if (_init_on_free_enabled_early) {
-		if (page_poisoning_requested)

mm/page_alloc.c void init_mem_debugging_and_hardening(void) · line 860

Quoted 10 lines
mm/page_alloc.c +5 -1
+	if (_init_on_free_enabled_early ||
+	    IS_ENABLED(CONFIG_INIT_ON_FREE_DEFAULT_ON)) {
+		if (page_poisoning_requested) {
 			pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
 				"will take precedence over init_on_free\n");
-		else
+			static_branch_disable(&init_on_free);
+		} else
 			static_branch_enable(&init_on_free);
 	}

I think it would be better to clean this up without additional confusion involving the CONFIGs:

mm/page_alloc.c +16 -13
index 3b97e17806be..1f19365bc158 100644
@@ -840,21 +840,24 @@ void init_mem_debugging_and_hardening(void)
 	}
 #endif
 
-	if (_init_on_alloc_enabled_early) {
-		if (page_poisoning_requested)
-			pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
-				"will take precedence over init_on_alloc\n");
-		else
-			static_branch_enable(&init_on_alloc);
-	}
-	if (_init_on_free_enabled_early) {
-		if (page_poisoning_requested)
-			pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
-				"will take precedence over init_on_free\n");
-		else
-			static_branch_enable(&init_on_free);
+	if ((_init_on_alloc_enabled_early || _init_on_free_enabled_early) &&
+	    page_poisoning_requested) {
+		pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
+			"will take precedence over init_on_alloc and init_on_free\n");
+		_init_on_alloc_enabled_early = false;
+		_init_on_free_enabled_early = false;
 	}
 
+	if (_init_on_alloc_enabled_early)
+		static_branch_enable(&init_on_alloc);
+	else
+		static_branch_disable(&init_on_alloc);
+
+	if (_init_on_free_enabled_early)
+		static_branch_enable(&init_on_free);
+	else
+		static_branch_disable(&init_on_free);
+
 #ifdef CONFIG_DEBUG_PAGEALLOC
 	if (!debug_pagealloc_enabled())
 		return;
Signature · 1 line
Kees Cook
#5 lore raw

Re: [PATCH] mm: page_alloc: fix page_poison=1 / INIT_ON_ALLOC_DEFAULT_ON interaction

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

Quoted 366 lines · Kees Cook
Quoted 85 lines · Sergei Trofimovich

To reproduce the failure we need the following system:

(quoted diff) +0 -2
-   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
 
 
    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
 
 
    ? dup_mm+0x37/0x4f0
 
 
    mm_init+0x185/0x270
 
 
    dup_mm+0x6b/0x4f0
 
 
    ? __lock_task_sighand+0x35/0x70
 
 
    copy_process+0x190d/0x1b10
 
 
    kernel_clone+0xba/0x3b0
 
 
    __do_sys_clone+0x8f/0xb0
 
 
    do_syscall_64+0x68/0x80
 
 
    ? do_syscall_64+0x11/0x80
 
 
    entry_SYSCALL_64_after_hwframe+0x44/0xae
Quoted 7 lines

Before the 51cba1eb ("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 init_mem_debugging_and_hardening() is always called (by mm_init()).

Quoted 76 lines

But after the 51cba1eb 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.

CC Andrew Morton [email protected]
CC Kees Cook [email protected]
CC Alexander Potapenko [email protected]
CC Thomas Gleixner [email protected]
CC Vlastimil Babka [email protected]
Reported-by [email protected]
Reported-by Mikhail Morfikov
Fixes 51cba1eb ("init_on_alloc: Optimize static branches")

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

mm/page_alloc.c | 16 ++++++++++------

1 file changed, 10 insertions(+), 6 deletions(-)
mm/page_alloc.c +0 -0

index 3b97e17806be..46cb4a9c2b50 100644

--- a/mm/page_alloc.c

+++ b/mm/page_alloc.c

mm/page_alloc.c +0 -0
@@ -840,18 +840,22 @@ void init_mem_debugging_and_hardening(void)
 
 
 }
 
 
 #endif
 
 

mm/page_alloc.c void init_mem_debugging_and_hardening(void) · line 857

Quoted 10 lines
mm/page_alloc.c +0 -4
-   if (_init_on_alloc_enabled_early) {
-       if (page_poisoning_requested)
 
 
 
 
 
 
-   if (_init_on_alloc_enabled_early ||
-       IS_ENABLED(CONFIG_INIT_ON_ALLOC_DEFAULT_ON)) {

This doesn't look right. _init_on_alloc_enabled_early already has the

same value:

static bool _init_on_alloc_enabled_early __read_mostly

= IS_ENABLED(CONFIG_INIT_ON_ALLOC_DEFAULT_ON);

So checking this is just a side-effect of how static_branch_maybe()

happens to be behaving.

Quoted 62 lines
mm/page_alloc.c +0 -11
-       if (page_poisoning_requested) {
        	pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
        		"will take precedence over init_on_alloc\\n");
 
 
 
 
 
 
-       else
 
 
 
 
 
 
-       	static_branch_disable(&init_on_alloc);
 
 
 
 
-       } else
        	static_branch_enable(&init_on_alloc);
 
 
 
 
    }
 
 
-   if (_init_on_free_enabled_early) {
-       if (page_poisoning_requested)
 
 
 
 
 
 
-   if (_init_on_free_enabled_early ||
-       IS_ENABLED(CONFIG_INIT_ON_FREE_DEFAULT_ON)) {
 
 
 
 
-       if (page_poisoning_requested) {
        	pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
        		"will take precedence over init_on_free\\n");
 
 
 
 
 
 
-       else
 
 
 
 
 
 
-       	static_branch_disable(&init_on_free);
 

mm/page_alloc.c void init_mem_debugging_and_hardening(void)

Quoted 10 lines
mm/page_alloc.c +0 -1
 
 
 
-       } else
        	static_branch_enable(&init_on_free);
 
 
 
 
    }

I think it would be better to clean this up without additional

confusion involving the CONFIGs:

mm/page_alloc.c +0 -0

index 3b97e17806be..1f19365bc158 100644

--- a/mm/page_alloc.c

+++ b/mm/page_alloc.c

mm/page_alloc.c +0 -15
@@ -840,21 +840,24 @@ void init_mem_debugging_and_hardening(void)
 
 
 }
 
 
 #endif
 
 
-   if (_init_on_alloc_enabled_early) {
-         if (page_poisoning_requested)
 
 
 
 
-         	pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
 
 
 
 
-         		"will take precedence over init_on_alloc\\n");
 
 
 
 
-         else
 
 
 
 
-         	static_branch_enable(&init_on_alloc);
 
 
 
 
-   }
-   if (_init_on_free_enabled_early) {
-         if (page_poisoning_requested)
 
 
 
 
-         	pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
 
 
 
 
-         		"will take precedence over init_on_free\\n");
 
 
 
 
-         else
 
 
 
 
-         	static_branch_enable(&init_on_free);
 
 
 
 
 
 
-   if ((_init_on_alloc_enabled_early || _init_on_free_enabled_early) &&
-         page_poisoning_requested) {

mm/page_alloc.c void init_mem_debugging_and_hardening(void)

Quoted 10 lines
mm/page_alloc.c +0 -2
 
 
 
 
-         pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
 
 
 
 
-         	"will take precedence over init_on_alloc and init_on_free\\n");

B & C variants show this message and A does not, which is what I would expect to happen.

Tested variants:

A. "page_poison=1 init_on_free=0 init_on_alloc=0 slub_debug=P"
B. "page_poison=1 init_on_free=0 init_on_alloc=0 slub_debug=P init_on_free=1" C. "page_poison=1 slub_debug=P"

in common:
CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y
CONFIG_INIT_ON_FREE_DEFAULT_ON=y
CONFIG_PAGE_POISONING=y
CONFIG_SLUB_DEBUG=y
CONFIG_SLUB=y

(the slub parts don't matter, ignore them)

Quoted 47 lines
mm/page_alloc.c +0 -10
-         _init_on_alloc_enabled_early = false;
 
 
 
 
-         _init_on_free_enabled_early = false;
 
 
 
 
    }
-   if (_init_on_alloc_enabled_early)
-         static_branch_enable(&init_on_alloc);
 
 
 
 
-   else
-         static_branch_disable(&init_on_alloc);
 
 
 
 
 
 
-   if (_init_on_free_enabled_early)
-         static_branch_enable(&init_on_free);
 
 
 
 
-   else
-         static_branch_disable(&init_on_free);

#ifdef CONFIG_DEBUG_PAGEALLOC

if (!debug_pagealloc_enabled())

Quoted 7 lines

return;

------------------------------------------------------------------------

Kees Cook

While both patches(Sergei's, and yours) work for me, I'll be using this one for now.

Thank you for your work!
Cheers!

#6 lore raw

Re: [PATCH] mm: page_alloc: fix page_poison=1 / INIT_ON_ALLOC_DEFAULT_ON interaction

Quoted 15 lines · bowsingbetee

B & C variants show this message and A does not, which is what I would expect to happen.

Tested variants:

A. "page_poison=1 init_on_free=0 init_on_alloc=0 slub_debug=P"
B. "page_poison=1 init_on_free=0 init_on_alloc=0 slub_debug=P init_on_free=1" C. "page_poison=1 slub_debug=P"

in common:
CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y
CONFIG_INIT_ON_FREE_DEFAULT_ON=y
CONFIG_PAGE_POISONING=y
CONFIG_SLUB_DEBUG=y
CONFIG_SLUB=y

Quoted 8 lines

(the slub parts don't matter, ignore them)

[...]

While both patches(Sergei's, and yours) work for me, I'll be using this one for now.

Thank you for your work!
Cheers!

Awesome; thanks for testing it!

-Kees

Signature · 1 line
Kees Cook