From: sashiko-bot@kernel.org
To: tao <tao.wangtao@honor.com>
Cc: damon@lists.linux.dev
Subject: Re: [RFC PATCH v2 13/13] mm: Enable CONFIG_ANON_VMA_FRACTAL by default
Date: Tue, 07 Jul 2026 10:21:14 +0000 [thread overview]
Message-ID: <20260707102114.B2B791F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707063308.29176-14-tao.wangtao@honor.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] RMAP walker Use-After-Free of `mm_struct` and VMA during VMA lock release due to skipped `mmgrab()` stabilization and flawed synchronization with `exit_mmap()`.
- [High] Enabling `CONFIG_ANON_VMA_SHARED_SEMS` exposes a Use-After-Free vulnerability because the dynamically allocated semaphores are freed without RCU protection but accessed under RCU.
--
--- Patch [13]: [RFC PATCH v2 13/13] mm: Enable CONFIG_ANON_VMA_FRACTAL by default ---
commit e2497626d5f9a80886b8bd9853568725462fff8d
Author: tao <tao.wangtao@honor.com>
mm: Enable CONFIG_ANON_VMA_FRACTAL by default
Everything is now in place to enable CONFIG_ANON_VMA_FRACTAL and
CONFIG_ANON_VMA_SHARED_SEMS for further testing.
> diff --git a/mm/Kconfig b/mm/Kconfig
> index 1a2c8085b12d5..7916c0127de0a 100644
> --- a/mm/Kconfig
> +++ b/mm/Kconfig
> @@ -1453,7 +1453,7 @@ config LOCK_MM_AND_FIND_VMA
>
> config ANON_VMA_FRACTAL
> bool "anon_vma fractal list"
> - def_bool n
> + def_bool y
[Severity: High]
This isn't a bug introduced by this patch, but enabling this feature by
default exposes a use-after-free race between the RMAP walker and
exit_mmap().
Looking at trylock_leaf_vma_rmap() in mm/rmap.c, it sets other_mm to NULL if
vma->vm_mm == mm, which skips the mmgrab() stabilization:
mm/rmap.c:trylock_leaf_vma_rmap() {
...
*other_mm = (vma->vm_mm == mm) ? NULL : vma->vm_mm;
...
}
Then in folio_lock_anon_vma_read(), RCU protection is dropped while holding
an unpinned leaf_vma:
mm/rmap.c:folio_lock_anon_vma_read() {
...
if (leaf_vma && !other_mm && folio_mapped(folio)) {
rcu_read_unlock();
return (void *)leaf_vma + ANON_RMAP_LEAF_VMA;
}
...
}
Concurrently, if exit_mmap() acquires mmap_write_lock() but doesn't drain
per-VMA lock readers via vma_start_write(), it can free the VMA and the
unpinned mm_struct.
When the RMAP walker later calls anon_node_unlock_rmap(), it dereferences
the freed VMA and vm_mm to wake up writers:
mm/rmap.c:anon_node_unlock_rmap() {
...
if (anon_rmap_is_leaf_vma(anon_nod)) {
vma_refcount_put(anon_rmap_to_leaf_vma(anon_nod));
return;
}
...
}
Should the RMAP walker ensure the mm_struct is stabilized before dropping
RCU protection to prevent this?
> depends on MMU
> help
> This option uses vma_rmap_base(vma) during rmap to compute the page
> @@ -1481,7 +1481,7 @@ config ANON_VMA_FRACTAL
>
> config ANON_VMA_SHARED_SEMS
> bool "anon_vma shared semaphores"
> - def_bool n
> + def_bool y
[Severity: High]
This isn't a bug introduced by this patch, but enabling ANON_VMA_SHARED_SEMS
by default exposes a use-after-free vulnerability with the dynamically
allocated semaphores.
In anon_vma_init() in mm/rmap.c, the slab cache for the shared semaphores is
created without SLAB_TYPESAFE_BY_RCU:
mm/rmap.c:anon_vma_init() {
...
anon_sema_cachep = KMEM_CACHE(anon_semaphore, SLAB_PANIC|SLAB_ACCOUNT);
...
}
When the semaphore is freed in anon_root_sema_free(), it happens immediately
without an RCU grace period:
mm/rmap.c:anon_root_sema_free() {
...
kmem_cache_free(anon_sema_cachep, root_sema);
...
}
However, folio_lock_anon_vma_read() locklessly accesses root->root_anon_sema
under rcu_read_lock() and attempts to modify it:
mm/rmap.c:folio_lock_anon_vma_read() {
...
root_rwsem = anon_root_rmap_sem(root_anon_vma);
if (down_read_trylock(root_rwsem)) {
...
}
Since the semaphore slab is not RCU-safe, the memory can be immediately
reclaimed by the buddy allocator or reallocated.
Will down_read_trylock() end up modifying freed or completely unrelated
memory if a reclaim runs concurrently with an unmap?
> depends on ANON_VMA_FRACTAL
> help
> As rmap operations rarely run concurrently, and fork/delete updates
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260707063308.29176-1-tao.wangtao@honor.com?part=13
next prev parent reply other threads:[~2026-07-07 10:21 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 6:32 [RFC PATCH v2 00/13] mm: rework anon_vma and remove anon_vma_chain tao
2026-07-07 6:32 ` [RFC PATCH v2 01/13] mm: add CONFIG_ANON_VMA_FRACTAL tao
2026-07-07 7:11 ` sashiko-bot
2026-07-07 6:32 ` [RFC PATCH v2 02/13] mm: implement helpers for ANON_VMA_FRACTAL tao
2026-07-07 7:23 ` sashiko-bot
2026-07-07 6:32 ` [RFC PATCH v2 03/13] mm: implement __anon_node_prepare " tao
2026-07-07 7:39 ` sashiko-bot
2026-07-07 6:32 ` [RFC PATCH v2 04/13] mm: implement anon_node_clone " tao
2026-07-07 8:00 ` sashiko-bot
2026-07-07 6:33 ` [RFC PATCH v2 05/13] mm: implement anon_node_fork_with_prev " tao
2026-07-07 8:22 ` sashiko-bot
2026-07-07 6:33 ` [RFC PATCH v2 06/13] mm: implement unlink_anon_nodes " tao
2026-07-07 6:33 ` [RFC PATCH v2 07/13] mm: handle rmap_base changes " tao
2026-07-07 8:45 ` sashiko-bot
2026-07-07 6:33 ` [RFC PATCH v2 08/13] mm: implement anonymous folio rmap " tao
2026-07-07 9:01 ` sashiko-bot
2026-07-07 6:33 ` [RFC PATCH v2 09/13] mm: prepare anon_node replacement " tao
2026-07-07 9:12 ` sashiko-bot
2026-07-07 6:33 ` [RFC PATCH v2 10/13] mm: replace anon_vma with anon_node " tao
2026-07-07 9:25 ` sashiko-bot
2026-07-07 6:33 ` [RFC PATCH v2 11/13] mm: optimize rmap for ANON_VMA_FRACTAL with PVL tao
2026-07-07 9:41 ` sashiko-bot
2026-07-07 6:33 ` [RFC PATCH v2 12/13] mm: shared semaphores for ANON_VMA_FRACTAL tao
2026-07-07 9:59 ` sashiko-bot
2026-07-07 6:33 ` [RFC PATCH v2 13/13] mm: Enable CONFIG_ANON_VMA_FRACTAL by default tao
2026-07-07 10:21 ` sashiko-bot [this message]
2026-07-07 7:01 ` [RFC PATCH v2 00/13] mm: rework anon_vma and remove anon_vma_chain David Hildenbrand (Arm)
2026-07-07 8:21 ` wangtao
2026-07-07 8:31 ` David Hildenbrand (Arm)
2026-07-07 9:20 ` wangtao
2026-07-07 16:19 ` Gregory Price
2026-07-07 17:09 ` David Hildenbrand (Arm)
2026-07-08 3:26 ` wangtao
2026-07-08 8:18 ` David Hildenbrand (Arm)
2026-07-07 9:07 ` Pedro Falcato
2026-07-07 15:27 ` Borislav Petkov
2026-07-07 21:32 ` [syzbot ci] " syzbot ci
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=20260707102114.B2B791F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=damon@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tao.wangtao@honor.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