[PATCH v2] mm/slub: don't let kmemleak report rcu sheaves
From: Nguyen Ngoc Thang
Date: Mon Nov 23 2026 - 10:23:28 EST
kmemleak reports sheaves as leaked:
unreferenced object 0xffff8881009d4e00 (size 512):
hex dump (first 32 bytes):
b0 7e 81 2d 81 88 ff ff 60 bd b3 81 ff ff ff ff
00 12 04 00 81 88 ff ff 3c 00 00 00 00 00 00 00
backtrace:
__alloc_empty_sheaf mm/slub.c:2854 [inline]
alloc_empty_sheaf mm/slub.c:2874 [inline]
__pcs_replace_full_main+0xf7/0x330 mm/slub.c:6094
free_to_pcs mm/slub.c:6147 [inline]
kfree+0x353/0x390 mm/slub.c:6923
The same happens for sheaves allocated by __pcs_replace_empty_main(),
__kfree_rcu_sheaf() and kmem_cache_prefill_sheaf().
The second word is rcu_free_sheaf: the sheaf was handed to call_rcu() by
__kfree_rcu_sheaf() and is waiting for a grace period. Sheaves are
recycled between the pcs, the barn and rcu, so any sheaf can end up
there, no matter where it was allocated. While queued, the only
reference to it is the ->next pointer of the previous callback.
That callback often lives in memory kmemleak never scans. kmemleak
itself frees every kmemleak_object with call_rcu(free_object_rcu), and
those come from the SLAB_NOLEAKTRACE object_cache. struct slab of a
SLAB_TYPESAFE_BY_RCU cache pending rcu_free_slab() is another case, as
slab pages are frozen and skipped by scan_zone_pages(). The chain from
rcu_data is cut, and the sheaf, typically old, looks unreferenced. Since
it is then not scanned either, the objects it is about to free can be
reported as well.
Making kmemleak follow rcu callback lists would mean digging into rcu
internals and would still break at any untracked callback. Sheaves are
allocator metadata, always owned by a pcs, a barn or an rcu callback, so
mark them with kmemleak_not_leak() instead: they are never reported but
still scanned, so objects queued in them stay referenced. Allocations
that can't spin are not tracked by kmemleak, so skip them, as
alloc_slab_obj_exts() does.
Fixes: ec66e0d59952 ("slab: add sheaf support for batching kfree_rcu() operations")
Reported-by: syzbot+527fed49e5b988882c9a@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=527fed49e5b988882c9a
Reported-by: syzbot+4d078516add5f4f12cea@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=4d078516add5f4f12cea
Reviewed-by: Catalin Marinas <catalin.marinas@xxxxxxx>
Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@xxxxxxxxx>
---
v2:
- Rewrite the explanation. v1 blamed struct slab, but in my reproducer
most reported sheaves are queued right behind kmemleak's own
free_object_rcu() callback, whose kmemleak_object comes from the
SLAB_NOLEAKTRACE object_cache and is never scanned. struct slab
remains another possible break, as Catalin pointed out.
- Comment: "e.g. struct slab" -> "e.g. its own metadata".
- Also fixes syzbot 4d078516add5f4f12cea (sheaves allocated by
__pcs_replace_full_main()), same root cause.
- Rebased on v7.4-rc4; applies to next-20261120 as well. There,
sheaves of SLAB_NOLEAKTRACE caches are not tracked, and
kmemleak_not_leak() on them is a harmless no-op (paint_ptr() ignores
unknown objects).
- Code unchanged otherwise, so I kept Catalin's Reviewed-by.
v1: https://lore.kernel.org/all/20261113151837.123795-1-ngocthang2710.1999@xxxxxxxxx/
Tested in QEMU (syzbot config, 2 vCPUs), stalling a grace period with a
preempted reader on CPU0 while CPU1 queues rcu_free_slab() and
rcu_free_sheaf() callbacks, then running kmemleak scans:
before (v7.4-rc3): 176 reports, 82 of them sheaves (allocated by
__kfree_rcu_sheaf, kmem_cache_prefill_sheaf,
__pcs_replace_full_main, __pcs_replace_empty_main), the rest
maple nodes held by them
after (v7.4-rc4 + v2, 4 runs): no sheaf or maple node reports.
5-9 reports per run remain, all from a single exited task
(task_struct, pid, creds) waiting for its RCU callback. Same
kmemleak blind spot, not sheaf related.
mm/slub.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/mm/slub.c b/mm/slub.c
index 5c33d12470601..ed52c1c5d31da 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2856,6 +2856,14 @@ static struct slab_sheaf *__alloc_empty_sheaf(struct kmem_cache *s, gfp_t gfp,
if (unlikely(!sheaf))
return NULL;
+ /*
+ * A queued rcu sheaf may only be referenced by an earlier rcu callback
+ * in memory kmemleak doesn't scan (e.g. its own metadata). Never
+ * report sheaves, but keep scanning the objects they hold.
+ */
+ if (alloc_flags_allow_spinning(alloc_flags))
+ kmemleak_not_leak(sheaf);
+
sheaf->cache = s;
stat(s, SHEAF_ALLOC);
--
2.43.0