From: Mike Rapoport <rppt@kernel.org>
To: Breno Leitao <leitao@debian.org>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
Ben Segall <bsegall@google.com>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Frederic Weisbecker <frederic@kernel.org>,
Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
Mel Gorman <mgorman@suse.de>,
Peter Zijlstra <peterz@infradead.org>,
Steven Rostedt <rostedt@goodmis.org>,
Valentin Schneider <vschneid@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Waiman Long <longman@redhat.com>,
linux-kernel@vger.kernel.org, kernel-team@meta.com
Subject: Re: [PATCH] memblock: don't touch memblock arrays when memblock_free() is called late
Date: Wed, 13 May 2026 17:29:04 +0300 [thread overview]
Message-ID: <agSKsPZH8J22kguc@kernel.org> (raw)
In-Reply-To: <agRyMXYfoww-7Z4X@gmail.com>
On Wed, May 13, 2026 at 05:47:34AM -0700, Breno Leitao wrote:
> On Wed, May 13, 2026 at 01:51:22PM +0300, Mike Rapoport wrote:
> > From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> >
> > When memblock_free() is called after memblock_discard() on architectures
> > that don't select ARCH_KEEP_MEMBLOCK, it tries to update memblock.reserved
> > that was already discarded and it causes use-after-free, for example
> >
> > [ 8.514775] BUG: KASAN: use-after-free in memblock_isolate_range+0x4ac/0x650
> > [ 8.514775] Read of size 8 at addr ffff88a07fe6a000 by task swapper/0/1
> > [ 8.514775] Call Trace:
> > [ 8.514775] <TASK>
> > [ 8.514775] kasan_report+0xb2/0x1b0
> > [ 8.514775] memblock_isolate_range+0x4ac/0x650
> > [ 8.514775] memblock_phys_free+0xc4/0x190
> > [ 8.514775] housekeeping_late_init+0x257/0x280
> > [ 8.514775] do_one_initcall+0xaa/0x470
> > [ 8.514775] do_initcalls+0x1b4/0x1f0
> > [ 8.514775] kernel_init_freeable+0x4b5/0x550
> > [ 8.514775] kernel_init+0x1c/0x150
> > [ 8.514775] ret_from_fork+0x5dc/0x8e0
> > [ 8.514775] ret_from_fork_asm+0x1a/0x30
> > [ 8.514775] </TASK>
> >
> > Make sure memblock_free() updates memblock.reserved only when called early
> > enough or when ARCH_KEEP_MEMBLOCK is enabled.
> >
> > Reported-by: Waiman Long <longman@redhat.com>
> > Reported-by: Breno Leitao <leitao@debian.org>
> > Closes: https://lore.kernel.org/all/20260505051821.1107133-1-longman@redhat.com
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> > Tested-by: Waiman Long <longman@redhat.com>
>
> Tested-by: Breno Leitao <leitao@debian.org>
Thanks!
> Don't you want a Fixes: tag?
Right,
Fixes: 87ce9e83ab8b ("memblock, treewide: make memblock_free() handle late freeing")
> > @@ -989,13 +989,15 @@ void __init_memblock memblock_free(void *ptr, size_t size)
> > int __init_memblock memblock_phys_free(phys_addr_t base, phys_addr_t size)
> > {
> > phys_addr_t end = base + size - 1;
> > - int ret;
> > + int ret = 0;
> >
> > memblock_dbg("%s: [%pa-%pa] %pS\n", __func__,
> > &base, &end, (void *)_RET_IP_);
> >
> > kmemleak_free_part_phys(base, size);
> > - ret = memblock_remove_range(&memblock.reserved, base, size);
> > +
> > + if (!slab_is_available() || IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK))
> > + ret = memblock_remove_range(&memblock.reserved, base, size);
> >
> > if (slab_is_available())
> > __free_reserved_area(base, base + size, -1);
>
> given slab_is_available() is a cheap function, it is fine to call it
> switch in here.
>
> Thanks for the fix!
> --breno
>
--
Sincerely yours,
Mike.
prev parent reply other threads:[~2026-05-13 14:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-13 10:51 [PATCH] memblock: don't touch memblock arrays when memblock_free() is called late Mike Rapoport
2026-05-13 12:47 ` Breno Leitao
2026-05-13 14:29 ` Mike Rapoport [this message]
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=agSKsPZH8J22kguc@kernel.org \
--to=rppt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=frederic@kernel.org \
--cc=juri.lelli@redhat.com \
--cc=kernel-team@meta.com \
--cc=kprateek.nayak@amd.com \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=longman@redhat.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/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