From: Catalin Marinas <catalin.marinas@arm.com>
To: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
Cc: Qing Wang <wangqing7171@gmail.com>, Hao Li <hao.li@linux.dev>,
lorenzo.stoakes@oracle.com, jannh@google.com,
syzkaller-bugs@googlegroups.com, linux-kernel@vger.kernel.org,
Liam.Howlett@oracle.com,
syzbot+cae7809e9dc1459e4e63@syzkaller.appspotmail.com,
linux-mm@kvack.org, vbabka@suse.cz, sj1557.seo@samsung.com,
pfalcato@suse.de, linux-fsdevel@vger.kernel.org,
jaegeuk@kernel.org, akpm@linux-foundation.org,
linux-f2fs-devel@lists.sourceforge.net, linkinjeon@kernel.org,
Harry Yoo <harry.yoo@oracle.com>
Subject: Re: [f2fs-dev] [syzbot] [mm?] [f2fs?] [exfat?] memory leak in __kfree_rcu_sheaf
Date: Fri, 6 Mar 2026 19:35:01 +0000 [thread overview]
Message-ID: <aassZV5PjgFx8dSI@arm.com> (raw)
In-Reply-To: <925a916a-6dfb-48c0-985c-0bdfb96ebd26@kernel.org>
On Wed, Mar 04, 2026 at 02:39:47PM +0100, Vlastimil Babka (SUSE) wrote:
> On 3/4/26 2:30 AM, Harry Yoo wrote:
> > [+Cc adding Catalin for kmemleak bits]
> > On Mon, Mar 02, 2026 at 09:39:48AM +0100, Vlastimil Babka (SUSE) wrote:
> >> On 3/2/26 04:41, Qing Wang wrote:
> >>> #syz test
> >>>
> >>> diff --git a/mm/slub.c b/mm/slub.c
> >>> index cdc1e652ec52..387979b89120 100644
> >>> --- a/mm/slub.c
> >>> +++ b/mm/slub.c
> >>> @@ -6307,15 +6307,21 @@ bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj)
> >>> goto fail;
> >>>
> >>> if (!local_trylock(&s->cpu_sheaves->lock)) {
> >>> - barn_put_empty_sheaf(barn, empty);
> >>> + if (barn && data_race(barn->nr_empty) < MAX_EMPTY_SHEAVES)
> >>> + barn_put_empty_sheaf(barn, empty);
> >>> + else
> >>> + free_empty_sheaf(s, empty);
> >>> goto fail;
> >>> }
> >>>
> >>> pcs = this_cpu_ptr(s->cpu_sheaves);
> >>>
> >>> - if (unlikely(pcs->rcu_free))
> >>> - barn_put_empty_sheaf(barn, empty);
> >>> - else
> >>> + if (unlikely(pcs->rcu_free)) {
> >>> + if (barn && data_race(barn->nr_empty) < MAX_EMPTY_SHEAVES)
> >>> + barn_put_empty_sheaf(barn, empty);
> >>> + else
> >>> + free_empty_sheaf(s, empty);
> >>> + } else
> >>> pcs->rcu_free = empty;
> >>> }
> >>
> >> I don't think this would fix any leak, and syzbot agrees. It would limit the
> >> empty sheaves in barn more strictly, but they are not leaked.
> >> Hm I don't see any leak in __kfree_rcu_sheaf() or rcu_free_sheaf(). Wonder
> >> if kmemleak lacks visibility into barns or pcs's as roots for searching what
> >> objects are considered referenced, or something?
> >
> > Objects that are allocated from slab and percpu allocator should be
> > properly tracked by kmemleak. But those allocated with
> > gfpflags_allow_spinning() == false are not tracked by kmemleak.
> >
> > When barns and sheaves are allocated early (!gfpflags_allow_spinning()
> > due to gfp_allowed_mask) and it skips kmemleak_alloc_recursive(),
> > it could produce false positives because from kmemleak's point of view,
> > the objects are not reachable from the root set (data section, stack,
> > etc.).
>
> Good point.
>
> > To me it seems kmemleak should gain allow_spin == false support
> > sooner or later.
>
> Or we figure out how to deal with the false allow_spin == false during
> boot. Here I'm a bit confused how exactly it happens because AFAICS in
> slub we apply gfp_allowed_mask only when allocating a new slab, and in
> slab_post_alloc_hook() we apply it to init_mask. That is indeed passed
> to kmemleak_alloc_recursive() but not used for the
> gfpflags_allow_spinning() decision. kmemleak_alloc_recursive() should
> succeed because nobody should be holding any locks that would require
> spinning.
I don't fully understand what goes on. If kmemleak_alloc_recursive()
failed to allocate for some reason (other than SLAB_NOLEAKTRACE), it
would loudly disable kmemleak altogether and stop reporting leaks. Also
kmemleak doesn't care about allow_spin, it's only the slub code which
avoids calling kmemleak if spinning not allowed (as it takes some locks,
may call back into the slab allocator).
I wonder whether some early kmem_cache_node allocations like the ones in
early_kmem_cache_node_alloc() are not tracked and then kmemleak cannot
find n->barn. I got lost in the slub code, but something like this:
-----------8<-----------------------------------
diff --git a/mm/slub.c b/mm/slub.c
index 0c906fefc31b..401557ff5487 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -7513,6 +7513,7 @@ static void early_kmem_cache_node_alloc(int node)
slab->freelist = get_freepointer(kmem_cache_node, n);
slab->inuse = 1;
kmem_cache_node->node[node] = n;
+ kmemleak_alloc(n, sizeof(*n), 1, GFP_NOWAIT);
init_kmem_cache_node(n, NULL);
inc_slabs_node(kmem_cache_node, node, slab->objects);
-------------8<----------------------------------------
Another thing I noticed, not sure it's related but we should probably
ignore an object once it has been passed to kvfree_call_rcu(), similar
to what we do on the main path in this function. Also see commit
5f98fd034ca6 ("rcu: kmemleak: Ignore kmemleak false positives when
RCU-freeing objects") when we added this kmemleak_ignore().
---------8<-----------------------------------
diff --git a/mm/slab_common.c b/mm/slab_common.c
index d5a70a831a2a..73f4668d870d 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -1954,8 +1954,14 @@ void kvfree_call_rcu(struct rcu_head *head, void *ptr)
if (!head)
might_sleep();
- if (!IS_ENABLED(CONFIG_PREEMPT_RT) && kfree_rcu_sheaf(ptr))
+ if (!IS_ENABLED(CONFIG_PREEMPT_RT) && kfree_rcu_sheaf(ptr)) {
+ /*
+ * The object is now queued for deferred freeing via an RCU
+ * sheaf. Tell kmemleak to ignore it.
+ */
+ kmemleak_ignore(ptr);
return;
+ }
// Queue the object but don't yet schedule the batch.
if (debug_rcu_head_queue(ptr)) {
----------------8<-----------------------------------
--
Catalin
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
WARNING: multiple messages have this Message-ID (diff)
From: Catalin Marinas <catalin.marinas@arm.com>
To: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
Cc: Harry Yoo <harry.yoo@oracle.com>,
Qing Wang <wangqing7171@gmail.com>,
syzbot+cae7809e9dc1459e4e63@syzkaller.appspotmail.com,
Liam.Howlett@oracle.com, akpm@linux-foundation.org,
chao@kernel.org, jaegeuk@kernel.org, jannh@google.com,
linkinjeon@kernel.org, linux-f2fs-devel@lists.sourceforge.net,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, lorenzo.stoakes@oracle.com, pfalcato@suse.de,
sj1557.seo@samsung.com, syzkaller-bugs@googlegroups.com,
vbabka@suse.cz, Hao Li <hao.li@linux.dev>
Subject: Re: [syzbot] [mm?] [f2fs?] [exfat?] memory leak in __kfree_rcu_sheaf
Date: Fri, 6 Mar 2026 19:35:01 +0000 [thread overview]
Message-ID: <aassZV5PjgFx8dSI@arm.com> (raw)
In-Reply-To: <925a916a-6dfb-48c0-985c-0bdfb96ebd26@kernel.org>
On Wed, Mar 04, 2026 at 02:39:47PM +0100, Vlastimil Babka (SUSE) wrote:
> On 3/4/26 2:30 AM, Harry Yoo wrote:
> > [+Cc adding Catalin for kmemleak bits]
> > On Mon, Mar 02, 2026 at 09:39:48AM +0100, Vlastimil Babka (SUSE) wrote:
> >> On 3/2/26 04:41, Qing Wang wrote:
> >>> #syz test
> >>>
> >>> diff --git a/mm/slub.c b/mm/slub.c
> >>> index cdc1e652ec52..387979b89120 100644
> >>> --- a/mm/slub.c
> >>> +++ b/mm/slub.c
> >>> @@ -6307,15 +6307,21 @@ bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj)
> >>> goto fail;
> >>>
> >>> if (!local_trylock(&s->cpu_sheaves->lock)) {
> >>> - barn_put_empty_sheaf(barn, empty);
> >>> + if (barn && data_race(barn->nr_empty) < MAX_EMPTY_SHEAVES)
> >>> + barn_put_empty_sheaf(barn, empty);
> >>> + else
> >>> + free_empty_sheaf(s, empty);
> >>> goto fail;
> >>> }
> >>>
> >>> pcs = this_cpu_ptr(s->cpu_sheaves);
> >>>
> >>> - if (unlikely(pcs->rcu_free))
> >>> - barn_put_empty_sheaf(barn, empty);
> >>> - else
> >>> + if (unlikely(pcs->rcu_free)) {
> >>> + if (barn && data_race(barn->nr_empty) < MAX_EMPTY_SHEAVES)
> >>> + barn_put_empty_sheaf(barn, empty);
> >>> + else
> >>> + free_empty_sheaf(s, empty);
> >>> + } else
> >>> pcs->rcu_free = empty;
> >>> }
> >>
> >> I don't think this would fix any leak, and syzbot agrees. It would limit the
> >> empty sheaves in barn more strictly, but they are not leaked.
> >> Hm I don't see any leak in __kfree_rcu_sheaf() or rcu_free_sheaf(). Wonder
> >> if kmemleak lacks visibility into barns or pcs's as roots for searching what
> >> objects are considered referenced, or something?
> >
> > Objects that are allocated from slab and percpu allocator should be
> > properly tracked by kmemleak. But those allocated with
> > gfpflags_allow_spinning() == false are not tracked by kmemleak.
> >
> > When barns and sheaves are allocated early (!gfpflags_allow_spinning()
> > due to gfp_allowed_mask) and it skips kmemleak_alloc_recursive(),
> > it could produce false positives because from kmemleak's point of view,
> > the objects are not reachable from the root set (data section, stack,
> > etc.).
>
> Good point.
>
> > To me it seems kmemleak should gain allow_spin == false support
> > sooner or later.
>
> Or we figure out how to deal with the false allow_spin == false during
> boot. Here I'm a bit confused how exactly it happens because AFAICS in
> slub we apply gfp_allowed_mask only when allocating a new slab, and in
> slab_post_alloc_hook() we apply it to init_mask. That is indeed passed
> to kmemleak_alloc_recursive() but not used for the
> gfpflags_allow_spinning() decision. kmemleak_alloc_recursive() should
> succeed because nobody should be holding any locks that would require
> spinning.
I don't fully understand what goes on. If kmemleak_alloc_recursive()
failed to allocate for some reason (other than SLAB_NOLEAKTRACE), it
would loudly disable kmemleak altogether and stop reporting leaks. Also
kmemleak doesn't care about allow_spin, it's only the slub code which
avoids calling kmemleak if spinning not allowed (as it takes some locks,
may call back into the slab allocator).
I wonder whether some early kmem_cache_node allocations like the ones in
early_kmem_cache_node_alloc() are not tracked and then kmemleak cannot
find n->barn. I got lost in the slub code, but something like this:
-----------8<-----------------------------------
diff --git a/mm/slub.c b/mm/slub.c
index 0c906fefc31b..401557ff5487 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -7513,6 +7513,7 @@ static void early_kmem_cache_node_alloc(int node)
slab->freelist = get_freepointer(kmem_cache_node, n);
slab->inuse = 1;
kmem_cache_node->node[node] = n;
+ kmemleak_alloc(n, sizeof(*n), 1, GFP_NOWAIT);
init_kmem_cache_node(n, NULL);
inc_slabs_node(kmem_cache_node, node, slab->objects);
-------------8<----------------------------------------
Another thing I noticed, not sure it's related but we should probably
ignore an object once it has been passed to kvfree_call_rcu(), similar
to what we do on the main path in this function. Also see commit
5f98fd034ca6 ("rcu: kmemleak: Ignore kmemleak false positives when
RCU-freeing objects") when we added this kmemleak_ignore().
---------8<-----------------------------------
diff --git a/mm/slab_common.c b/mm/slab_common.c
index d5a70a831a2a..73f4668d870d 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -1954,8 +1954,14 @@ void kvfree_call_rcu(struct rcu_head *head, void *ptr)
if (!head)
might_sleep();
- if (!IS_ENABLED(CONFIG_PREEMPT_RT) && kfree_rcu_sheaf(ptr))
+ if (!IS_ENABLED(CONFIG_PREEMPT_RT) && kfree_rcu_sheaf(ptr)) {
+ /*
+ * The object is now queued for deferred freeing via an RCU
+ * sheaf. Tell kmemleak to ignore it.
+ */
+ kmemleak_ignore(ptr);
return;
+ }
// Queue the object but don't yet schedule the batch.
if (debug_rcu_head_queue(ptr)) {
----------------8<-----------------------------------
--
Catalin
next prev parent reply other threads:[~2026-03-06 19:50 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-09 18:26 [f2fs-dev] [syzbot] [mm?] [f2fs?] [exfat?] memory leak in __kfree_rcu_sheaf syzbot
2026-02-09 18:26 ` syzbot
2026-03-02 3:41 ` [f2fs-dev] " Qing Wang
2026-03-02 3:41 ` Qing Wang
2026-03-02 3:57 ` [f2fs-dev] " syzbot
2026-03-02 3:57 ` syzbot
2026-03-02 8:39 ` [f2fs-dev] " Vlastimil Babka (SUSE) via Linux-f2fs-devel
2026-03-02 8:39 ` Vlastimil Babka (SUSE)
2026-03-04 1:30 ` [f2fs-dev] " Harry Yoo via Linux-f2fs-devel
2026-03-04 1:30 ` Harry Yoo
2026-03-04 13:39 ` [f2fs-dev] " Vlastimil Babka (SUSE) via Linux-f2fs-devel
2026-03-04 13:39 ` Vlastimil Babka (SUSE)
2026-03-06 19:35 ` Catalin Marinas [this message]
2026-03-06 19:35 ` Catalin Marinas
2026-03-08 11:02 ` [f2fs-dev] " Catalin Marinas
2026-03-08 11:02 ` Catalin Marinas
2026-03-08 12:31 ` [f2fs-dev] " syzbot
2026-03-08 12:31 ` syzbot
2026-03-08 11:04 ` [f2fs-dev] " Catalin Marinas
2026-03-08 11:04 ` Catalin Marinas
2026-03-08 12:42 ` [f2fs-dev] " syzbot
2026-03-08 12:42 ` syzbot
2026-03-09 10:46 ` [f2fs-dev] " Harry Yoo via Linux-f2fs-devel
2026-03-09 10:46 ` Harry Yoo
2026-03-09 11:11 ` [f2fs-dev] " syzbot
2026-03-09 11:11 ` syzbot
2026-03-09 12:17 ` [f2fs-dev] " Harry Yoo via Linux-f2fs-devel
2026-03-09 12:17 ` Harry Yoo
2026-03-09 20:31 ` [f2fs-dev] " Catalin Marinas
2026-03-09 20:31 ` Catalin Marinas
2026-03-11 3:04 ` [f2fs-dev] " Harry Yoo via Linux-f2fs-devel
2026-03-11 3:04 ` Harry Yoo
2026-03-11 3:20 ` [f2fs-dev] " Harry Yoo via Linux-f2fs-devel
2026-03-11 3:20 ` Harry Yoo
2026-03-10 3:39 ` [f2fs-dev] " Harry Yoo via Linux-f2fs-devel
2026-03-10 3:39 ` Harry Yoo
2026-03-10 3:54 ` [f2fs-dev] " syzbot
2026-03-10 3:54 ` syzbot
2026-03-10 6:11 ` [f2fs-dev] " Harry Yoo via Linux-f2fs-devel
2026-03-10 6:11 ` Harry Yoo
2026-03-10 6:29 ` [f2fs-dev] " syzbot
2026-03-10 6:29 ` syzbot
2026-03-10 8:10 ` [f2fs-dev] " Harry Yoo via Linux-f2fs-devel
2026-03-10 8:10 ` Harry Yoo
2026-03-10 9:40 ` [f2fs-dev] " syzbot
2026-03-10 9:40 ` syzbot
2026-03-18 2:34 ` [f2fs-dev] " Harry Yoo via Linux-f2fs-devel
2026-03-18 2:34 ` Harry Yoo
2026-03-18 3:08 ` [f2fs-dev] " syzbot
2026-03-18 3:08 ` syzbot
2026-03-18 4:10 ` [f2fs-dev] " Harry Yoo via Linux-f2fs-devel
2026-03-18 4:10 ` Harry Yoo
2026-03-18 5:02 ` [f2fs-dev] " syzbot
2026-03-18 5:02 ` syzbot
2026-03-11 9:57 ` [f2fs-dev] " Qing Wang
2026-03-11 9:57 ` Qing Wang
2026-03-11 10:17 ` [f2fs-dev] " syzbot
2026-03-11 10:17 ` syzbot
2026-03-11 10:48 ` [f2fs-dev] " Qing Wang
2026-03-11 10:48 ` Qing Wang
2026-03-11 11:03 ` [f2fs-dev] " syzbot
2026-03-11 11:03 ` syzbot
2026-03-11 11:23 ` [f2fs-dev] " Harry Yoo via Linux-f2fs-devel
2026-03-11 11:23 ` Harry Yoo
2026-03-20 0:06 ` [f2fs-dev] " Harry Yoo via Linux-f2fs-devel
2026-03-20 0:06 ` Harry Yoo
2026-03-20 10:34 ` [f2fs-dev] " syzbot
2026-03-20 10:34 ` syzbot
2026-03-20 11:20 ` [f2fs-dev] " Harry Yoo via Linux-f2fs-devel
2026-03-20 11:20 ` Harry Yoo
2026-05-02 10:09 ` David Timber
2026-05-03 6:00 ` David Timber
2026-05-03 7:17 ` [f2fs-dev] [syzbot] [mm?] [exfat?] [f2fs?] " syzbot
2026-05-03 7:17 ` syzbot
2026-05-03 6:05 ` [syzbot] [mm?] [f2fs?] [exfat?] " David Timber
2026-05-03 7:27 ` [f2fs-dev] [syzbot] [mm?] [exfat?] [f2fs?] " syzbot
2026-05-03 7:27 ` syzbot
2026-05-03 7:41 ` [f2fs-dev] " David Timber via Linux-f2fs-devel
2026-05-03 7:41 ` David Timber
2026-05-04 20:17 ` [syzbot] [mm?] [f2fs?] [exfat?] " David Timber
2026-05-04 20:51 ` [f2fs-dev] [syzbot] [mm?] [exfat?] [f2fs?] " syzbot
2026-05-04 20:51 ` syzbot
2026-05-04 20:26 ` [syzbot] [mm?] [f2fs?] [exfat?] " David Timber
2026-05-04 21:12 ` [f2fs-dev] [syzbot] [mm?] [exfat?] [f2fs?] " syzbot
2026-05-04 21:12 ` syzbot
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=aassZV5PjgFx8dSI@arm.com \
--to=catalin.marinas@arm.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=hao.li@linux.dev \
--cc=harry.yoo@oracle.com \
--cc=jaegeuk@kernel.org \
--cc=jannh@google.com \
--cc=linkinjeon@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=pfalcato@suse.de \
--cc=sj1557.seo@samsung.com \
--cc=syzbot+cae7809e9dc1459e4e63@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=vbabka@kernel.org \
--cc=vbabka@suse.cz \
--cc=wangqing7171@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.