* [PATCH] ocfs2: fix local_alloc_bh leak in ocfs2_shutdown_local_alloc()
@ 2026-11-17 14:58 Zhiyuan Zhang
2026-11-18 6:23 ` Joseph Qi
0 siblings, 1 reply; 2+ messages in thread
From: Zhiyuan Zhang @ 2026-11-17 14:58 UTC (permalink / raw)
To: Joseph Qi, Mark Fasheh, Joel Becker, Heming Zhao
Cc: Andrew Morton, ocfs2-devel, linux-kernel, Zhiyuan Zhang
From: Zhiyuan Zhang <zhiyuanzhang912@gmail.com>
ocfs2_shutdown_local_alloc() owns the buffer_head reference stored in
osb->local_alloc_bh, but only its success path drops it: after clearing
and journalling the local alloc inode it calls brelse() and clears the
pointer. Every error exit after the local allocator has been enabled
returns with the reference still held:
- failure to look up the local alloc or global bitmap system inode
- ocfs2_inode_lock() failure on the global bitmap
- ocfs2_start_trans() failure, e.g. on an aborted journal
- kmemdup() of the local alloc dinode returning NULL
- ocfs2_journal_access_di() failure
Nothing else releases it, so the buffer_head and its page stay pinned
after the unmount.
Drop the reference at the common out: label and clear the pointer
there. The success path has already set osb->local_alloc_bh to NULL
before it reaches out:, so nothing is released twice. The reservation
path is not affected: it takes its own reference with get_bh() and
drops it in ocfs2_free_ac_resource(). Also mark the local allocator
unused when the buffer is dropped, so that a NULL local_alloc_bh is
never left behind with the allocator still marked as in use.
Fixes: ccd979bdbce9 ("[PATCH] OCFS2: The Second Oracle Cluster Filesystem")
Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Zhiyuan Zhang <zhiyuanzhang912@gmail.com>
---
Notes:
Testing: QEMU (x86_64), local mount on a loop device, kernel built with
KASAN, PROVE_LOCKING, DEBUG_ATOMIC_SLEEP, DEBUG_VM and DEBUG_LIST. A
test-only pr_info() printed the pfn and b_count of local_alloc_bh on
entry and exit of ocfs2_shutdown_local_alloc(), and the page was looked
up in /proc/kpageflags after umount, losetup -d and drop_caches.
All six error exits were exercised, twice per boot, two boots per
kernel. The ocfs2_start_trans() failure is the real one: the loop
device is shrunk under the mounted filesystem so that jbd2 aborts the
journal. The other five were forced with a test-only knob.
- Unpatched, 24 of 24: the function returns with b_count still 1, and
the page is still allocated at the end of the run.
- Patched, 24 of 24: the reference is dropped and the page is free.
- A clean unmount frees the page on both kernels (8 of 8).
- No KASAN, lockdep or other warnings on either kernel.
The leak is one page per failed shutdown. kmemleak does not report it,
and neither Buffers in /proc/meminfo nor the buffer_head slab count
shows it.
AI assistants were used to find the leak, to write the patch and the
changelog, and to run the tests above.
fs/ocfs2/localalloc.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
index 82d290cf4432..d8d81cef92fc 100644
--- a/fs/ocfs2/localalloc.c
+++ b/fs/ocfs2/localalloc.c
@@ -462,6 +462,17 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb)
iput(main_bm_inode);
out:
+ /*
+ * The success path has already dropped the reference and cleared
+ * the pointer, so this is a no-op there. Every error exit after
+ * the local allocator was enabled used to leak local_alloc_bh.
+ */
+ if (osb->local_alloc_bh) {
+ brelse(osb->local_alloc_bh);
+ osb->local_alloc_bh = NULL;
+ osb->local_alloc_state = OCFS2_LA_UNUSED;
+ }
+
iput(local_alloc_inode);
kfree(alloc_copy);
base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
--
2.50.1 (Apple Git-155)
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] ocfs2: fix local_alloc_bh leak in ocfs2_shutdown_local_alloc()
2026-11-17 14:58 [PATCH] ocfs2: fix local_alloc_bh leak in ocfs2_shutdown_local_alloc() Zhiyuan Zhang
@ 2026-11-18 6:23 ` Joseph Qi
0 siblings, 0 replies; 2+ messages in thread
From: Joseph Qi @ 2026-11-18 6:23 UTC (permalink / raw)
To: Zhiyuan Zhang, Andrew Morton, Heming Zhao
Cc: Mark Fasheh, Joel Becker, ocfs2-devel, linux-kernel
On 11/17/26 10:58 PM, Zhiyuan Zhang wrote:
> From: Zhiyuan Zhang <zhiyuanzhang912@gmail.com>
>
> ocfs2_shutdown_local_alloc() owns the buffer_head reference stored in
> osb->local_alloc_bh, but only its success path drops it: after clearing
> and journalling the local alloc inode it calls brelse() and clears the
> pointer. Every error exit after the local allocator has been enabled
> returns with the reference still held:
>
> - failure to look up the local alloc or global bitmap system inode
> - ocfs2_inode_lock() failure on the global bitmap
> - ocfs2_start_trans() failure, e.g. on an aborted journal
> - kmemdup() of the local alloc dinode returning NULL
> - ocfs2_journal_access_di() failure
>
> Nothing else releases it, so the buffer_head and its page stay pinned
> after the unmount.
>
> Drop the reference at the common out: label and clear the pointer
> there. The success path has already set osb->local_alloc_bh to NULL
> before it reaches out:, so nothing is released twice. The reservation
> path is not affected: it takes its own reference with get_bh() and
> drops it in ocfs2_free_ac_resource(). Also mark the local allocator
> unused when the buffer is dropped, so that a NULL local_alloc_bh is
> never left behind with the allocator still marked as in use.
>
> Fixes: ccd979bdbce9 ("[PATCH] OCFS2: The Second Oracle Cluster Filesystem")
> Assisted-by: Claude:claude-fable-5-2
> Signed-off-by: Zhiyuan Zhang <zhiyuanzhang912@gmail.com>
Looks fine.
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> ---
>
> Notes:
> Testing: QEMU (x86_64), local mount on a loop device, kernel built with
> KASAN, PROVE_LOCKING, DEBUG_ATOMIC_SLEEP, DEBUG_VM and DEBUG_LIST. A
> test-only pr_info() printed the pfn and b_count of local_alloc_bh on
> entry and exit of ocfs2_shutdown_local_alloc(), and the page was looked
> up in /proc/kpageflags after umount, losetup -d and drop_caches.
>
> All six error exits were exercised, twice per boot, two boots per
> kernel. The ocfs2_start_trans() failure is the real one: the loop
> device is shrunk under the mounted filesystem so that jbd2 aborts the
> journal. The other five were forced with a test-only knob.
>
> - Unpatched, 24 of 24: the function returns with b_count still 1, and
> the page is still allocated at the end of the run.
> - Patched, 24 of 24: the reference is dropped and the page is free.
> - A clean unmount frees the page on both kernels (8 of 8).
> - No KASAN, lockdep or other warnings on either kernel.
>
> The leak is one page per failed shutdown. kmemleak does not report it,
> and neither Buffers in /proc/meminfo nor the buffer_head slab count
> shows it.
>
> AI assistants were used to find the leak, to write the patch and the
> changelog, and to run the tests above.
>
> fs/ocfs2/localalloc.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
> index 82d290cf4432..d8d81cef92fc 100644
> --- a/fs/ocfs2/localalloc.c
> +++ b/fs/ocfs2/localalloc.c
> @@ -462,6 +462,17 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb)
> iput(main_bm_inode);
>
> out:
> + /*
> + * The success path has already dropped the reference and cleared
> + * the pointer, so this is a no-op there. Every error exit after
> + * the local allocator was enabled used to leak local_alloc_bh.
> + */
> + if (osb->local_alloc_bh) {
> + brelse(osb->local_alloc_bh);
> + osb->local_alloc_bh = NULL;
> + osb->local_alloc_state = OCFS2_LA_UNUSED;
> + }
> +
> iput(local_alloc_inode);
>
> kfree(alloc_copy);
>
> base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-18 6:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 14:58 [PATCH] ocfs2: fix local_alloc_bh leak in ocfs2_shutdown_local_alloc() Zhiyuan Zhang
2026-11-18 6:23 ` Joseph Qi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®