From: Pedro Falcato <pfalcato@suse.de>
To: Andi Kleen <ak@kernel.org>
Cc: akpm@linux-foundation.org, liam@infradead.org, ljs@kernel.org,
jannh@google.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] RCU safety for vma maple tree walks
Date: Mon, 31 Aug 2026 15:58:56 +0100 [thread overview]
Message-ID: <apWUsc-a6k1YkuMv@pedro-suse> (raw)
In-Reply-To: <20260831143511.1133029-1-ak@kernel.org>
On Mon, Aug 31, 2026 at 07:35:11AM -0700, Andi Kleen wrote:
> I ran into the following scenario in a slightly modified kernel:
>
> 1. vms_gather_munmap_vmas walks the unmap range and caches a maple node N
> in the maple iterator.
> 2. It triggers a __split_vma to fix up a range and during that node N
> is queued for freeing with kfree_rcu
> 3. There is another __split_vma that allocates memory and sleeps due to
> memory pressure.
> 4. During the sleep the grace period expires and node N gets freed for
> real.
> 5. The iterator still has node N cached
> 6. When the iteration continues it accesses the freed node and KASAN
> trips:
>
> BUG: KASAN: slab-use-after-free in mas_next_slot+0x1e95/0x2860
> Read of size 8 at addr ffff8881160bdc00 by task pool-e/5770
> CPU: 1 UID: 0 PID: 5770 Comm: pool-e Not tainted 7.2.0-rc7-1-debug+ #106
> Allocated by task 5770:
> mas_alloc_nodes <- mas_preallocate <- __split_vma <- vms_gather_munmap_vmas
> <- do_vmi_align_munmap <- do_vmi_munmap <- __vm_munmap <- elf_load
> <- load_elf_binary <- bprm_execve (pool-e's exec)
> Freed by task 25 (ksoftirqd):
> __rcu_free_sheaf_prepare <- rcu_free_sheaf_nobarn <- rcu_do_batch <- rcu_core
> The buggy address ... cache maple_node of size 256
> freed 256-byte region [ffff8881160bdc00, ffff8881160bdd00)
>
> There was also a more complex scenario when the node was immediately
> recycled for the next split VMA insert, modified, but the access by
> the iterator for the previous walk saw corrupted state and triggered
> KASAN too.
>
> Basically the problem is that any sleeping during VMA walks breaks the
> RCU reader guarantees for the RCU Maple tree iterators. But sleeping
> is unavoidable for various reasons.
>
> I hit it with a kernel modification that makes this more likely
> (It can do VMA splits on exec mm teardown)
> and also in a very memory constrained environment (4GB guest running a
> stress test), but based on code review I believe it's a generic problem that
> could happen in a unmodified kernel.
>
> That said I wasn't actually able to trigger it in a unmodified kernel
> so far with stress testing.
>
> The following old unsolved syzkaller report has a similar signature,
> so maybe it was already seen:
> https://syzkaller.appspot.com/bug?id=4c5268fbb1d6d508a4c34dc425e2693d1ff9911a
>
> I guess in many cases where it happens for real you don't notice it
> if you don't have KASAN active.
>
> The patch fixes up all callers to maintain the RCU reader lock
> regions correctly during the VMA walk. If they cannot be maintained the
> iterator is refreshed by a new VMA address lookup in a new region, unless
> it is proven safe not to.
>
But none of this code uses RCU? I'm confused. The maple tree state should not
be keeping bad state. That is a bug.
All of these functions take the mmap write lock. That should exclude
against other concurrent changes. Using RCU here makes no logical sense.
Does the kernel say anything interesting when CONFIG_DEBUG_VM_MAPLE_TREE=y?
--
Pedro
next prev parent reply other threads:[~2026-08-31 14:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 14:35 [PATCH] RCU safety for vma maple tree walks Andi Kleen
2026-08-31 14:58 ` Pedro Falcato [this message]
2026-08-31 19:35 ` Andi Kleen
2026-08-31 19:55 ` Lorenzo Stoakes (ARM)
2026-09-01 21:05 ` Andi Kleen
2026-09-02 16:21 ` Lorenzo Stoakes (ARM)
2026-08-31 15:50 ` Lorenzo Stoakes (ARM)
2026-08-31 16:29 ` Liam R. Howlett
2026-08-31 16:52 ` Andi Kleen
2026-08-31 22:13 ` Liam R. Howlett
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=apWUsc-a6k1YkuMv@pedro-suse \
--to=pfalcato@suse.de \
--cc=ak@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=jannh@google.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
/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