From: Joseph Qi <joseph.qi@linux.alibaba.com>
To: Zhiyuan Zhang <zhiyuanzhang912@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Heming Zhao <heming.zhao@suse.com>
Cc: Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>,
ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ocfs2: fix local_alloc_bh leak in ocfs2_shutdown_local_alloc()
Date: Wed, 18 Nov 2026 14:23:53 +0800 [thread overview]
Message-ID: <f983496a-7948-46d2-882a-8eed79727805@linux.alibaba.com> (raw)
In-Reply-To: <20261117145830.59864-1-zhiyuanzhang912@gmail.com>
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
prev parent reply other threads:[~2026-11-18 6:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 14:58 Zhiyuan Zhang
2026-11-18 6:23 ` Joseph Qi [this message]
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=f983496a-7948-46d2-882a-8eed79727805@linux.alibaba.com \
--to=joseph.qi@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=heming.zhao@suse.com \
--cc=jlbec@evilplan.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark@fasheh.com \
--cc=ocfs2-devel@lists.linux.dev \
--cc=zhiyuanzhang912@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 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®