From: bowsingbetee <bowsingbetee@protonmail.com>
To: Kees Cook <keescook@chromium.org>
Cc: Sergei Trofimovich <slyfox@gentoo.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Alexander Potapenko <glider@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
Vlastimil Babka <vbabka@suse.cz>
Subject: Re: [PATCH] mm: page_alloc: fix page_poison=1 / INIT_ON_ALLOC_DEFAULT_ON interaction
Date: Wed, 14 Jul 2021 11:11:18 +0000 [thread overview]
Message-ID: <Uw6pNgiHmif9MJPCW3QYgIzcFUoL5wATgnqN4rNUrbpzsGtNvEg0CjiUnqu_LVpuf2Zs8uHUQ8Jz6fpdf30VZdAKpSH0we8NN2iNZVY2YVY=@protonmail.com> (raw)
In-Reply-To: <202107131953.BB3627156@keescook>
[-- Attachment #1.1: Type: text/plain, Size: 8604 bytes --]
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Wednesday, July 14th, 2021 at 5:10 AM, Kees Cook <keescook@chromium.org> wrote:
> On Mon, Jul 12, 2021 at 10:58:16PM +0100, Sergei Trofimovich 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 init_mem_debugging_and_hardening() is always called (by mm_init()).
>
> > 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 akpm@linux-foundation.org
> >
> > CC: Kees Cook keescook@chromium.org
> >
> > CC: Alexander Potapenko glider@google.com
> >
> > CC: Thomas Gleixner tglx@linutronix.de
> >
> > CC: Vlastimil Babka vbabka@suse.cz
> >
> > CC: linux-mm@kvack.org
> >
> > Reported-by: bowsingbetee@pm.me
> >
> > Reported-by: Mikhail Morfikov
> >
> > Fixes: 51cba1eb ("init_on_alloc: Optimize static branches")
> >
> > Signed-off-by: Sergei Trofimovich slyfox@gentoo.org
> > -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> >
> > mm/page_alloc.c | 16 ++++++++++------
> >
> > 1 file changed, 10 insertions(+), 6 deletions(-)
> >
> > diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> >
> > index 3b97e17806be..46cb4a9c2b50 100644
> >
> > --- a/mm/page_alloc.c
> >
> > +++ b/mm/page_alloc.c
> >
> > @@ -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.
>
> > - 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);
> >
> >
> > }
>
> I think it would be better to clean this up without additional
>
> confusion involving the CONFIGs:
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>
> index 3b97e17806be..1f19365bc158 100644
>
> --- a/mm/page_alloc.c
>
> +++ b/mm/page_alloc.c
>
> @@ -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");
>
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)
>
> - _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;
>
> ------------------------------------------------------------------------
>
> 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!
[-- Attachment #1.2: publickey - bowsingbetee@protonmail.com - 0x65EDD6AE.asc --]
[-- Type: application/pgp-keys, Size: 1873 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 509 bytes --]
next prev parent reply other threads:[~2021-07-14 11:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-11 23:57 v5.12+ regression on page_poison=1 i_on_free=0 i_on_alloc=0 warnings Sergei Trofimovich
2021-07-12 21:58 ` [PATCH] mm: page_alloc: fix page_poison=1 / INIT_ON_ALLOC_DEFAULT_ON interaction Sergei Trofimovich
2021-07-14 2:00 ` Andrew Morton
2021-07-17 18:18 ` Sergei Trofimovich
2021-07-14 3:10 ` Kees Cook
2021-07-14 11:11 ` bowsingbetee [this message]
2021-07-14 21:14 ` Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='Uw6pNgiHmif9MJPCW3QYgIzcFUoL5wATgnqN4rNUrbpzsGtNvEg0CjiUnqu_LVpuf2Zs8uHUQ8Jz6fpdf30VZdAKpSH0we8NN2iNZVY2YVY=@protonmail.com' \
--to=bowsingbetee@protonmail.com \
--cc=akpm@linux-foundation.org \
--cc=glider@google.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=slyfox@gentoo.org \
--cc=tglx@linutronix.de \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).