From: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
To: Christian Brauner <brauner@kernel.org>
Cc: slava@dubeyko.com, glaubitz@physik.fu-berlin.de,
frank.li@vivo.com, jack@suse.cz, viro@zeniv.linux.org.uk,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
skhan@linuxfoundation.org, david.hunter.linux@gmail.com,
khalid@kernel.org,
linux-kernel-mentees@lists.linuxfoundation.org,
syzbot+ad45f827c88778ff7df6@syzkaller.appspotmail.com
Subject: Re: [PATCH v2] fs/hfs: fix s_fs_info leak on setup_bdev_super() failure
Date: Wed, 19 Nov 2025 16:27:47 +0100 [thread overview]
Message-ID: <dc78b78d-14fc-456d-ae21-e79225b77afa@gmail.com> (raw)
In-Reply-To: <20251119-delfin-bioladen-6bf291941d4f@brauner>
On 11/19/25 3:14 PM, Christian Brauner wrote:
> On Wed, Nov 19, 2025 at 08:38:20AM +0100, Mehdi Ben Hadj Khelifa wrote:
>> The regression introduced by commit aca740cecbe5 ("fs: open block device
>> after superblock creation") allows setup_bdev_super() to fail after a new
>> superblock has been allocated by sget_fc(), but before hfs_fill_super()
>> takes ownership of the filesystem-specific s_fs_info data.
>>
>> In that case, hfs_put_super() and the failure paths of hfs_fill_super()
>> are never reached, leaving the HFS mdb structures attached to s->s_fs_info
>> unreleased.The default kill_block_super() teardown also does not free
>> HFS-specific resources, resulting in a memory leak on early mount failure.
>>
>> Fix this by moving all HFS-specific teardown (hfs_mdb_put()) from
>> hfs_put_super() and the hfs_fill_super() failure path into a dedicated
>> hfs_kill_sb() implementation. This ensures that both normal unmount and
>> early teardown paths (including setup_bdev_super() failure) correctly
>> release HFS metadata.
>>
>> This also preserves the intended layering: generic_shutdown_super()
>> handles VFS-side cleanup, while HFS filesystem state is fully destroyed
>> afterwards.
>>
>> Fixes: aca740cecbe5 ("fs: open block device after superblock creation")
>
> I don't think that's correct.
>
> The bug was introduced when hfs was converted to the new mount api as
> this was the point where sb->s_fs_info allocation was moved from
> fill_super() to init_fs_context() in ffcd06b6d13b ("hfs: convert hfs to
> use the new mount api") which was way after that commit.
Ah, That then is definitely the cause since the allocation is from
init_fs_context() and in this error path that leaks it didn't call
fill_super() yet where in old code would be the allocation of the
s_fs_info struct that is being leaked... so that would be where the bug
is introduced as you have mentionned thanks for pointing that out!
>
> I also think this isn't the best way to do it. There's no need to
> open-code kill_block_super() at all.
>
I did think do call kill_block_super() instead in hfs_kill_sb() instead
of open-coding it but I went with what Al Viro has suggested...
> That whole hfs_mdb_get() calling hfs_mdb_put() is completely backwards
> and the cleanup labels make no sense - predated anything you did ofc. It
> should not call hfs_mdb_put(). It's only caller is fill_super() which
> already cleans everything up. So really hfs_kill_super() should just
> free the allocation and it should be moved out of hfs_mdb_put().
>
I also thought of such solution to make things clearer of the
deallocation of the memory of s_fs_info and to separate it from the
deloading/freeing of it's contents.
> And that solution is already something I mentioned in my earlier review.
I thought you have suggested the same as what the al viro has suggested
by your second point here:"
or add a wrapper
around kill_block_super() for hfs and free it after ->kill_sb() has run.
"
> Let me test a patch.
I just checked your patch and seems to be what I'm thinking about except
the stuff that is in hfs_mdb_get() which I didn't know about.But since
the hfs_kill_super() is now implemented with freeing the s_fs_info
instead of just referring to kill_block_super(), It should fix the issue.
I did just download your patch and test it by running local repro, boot
the kernel, run selftests before and after with no seen regression.Does
that add the Tested-by tag?
Thanks for you insights Christian! Tell me if I should send something as
a follow up for my patch.
Best Regards,
Mehdi Ben Hadj Khelifa
next prev parent reply other threads:[~2025-11-19 15:27 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-19 7:38 [PATCH v2] fs/hfs: fix s_fs_info leak on setup_bdev_super() failure Mehdi Ben Hadj Khelifa
2025-11-19 14:14 ` Christian Brauner
2025-11-19 15:27 ` Mehdi Ben Hadj Khelifa [this message]
2025-11-19 19:58 ` Viacheslav Dubeyko
2025-11-19 22:21 ` Mehdi Ben Hadj Khelifa
2025-11-19 22:24 ` Mehdi Ben Hadj Khelifa
2025-11-21 19:44 ` Mehdi Ben Hadj Khelifa
2025-11-21 21:15 ` Viacheslav Dubeyko
2025-11-21 22:48 ` Mehdi Ben Hadj Khelifa
2025-11-21 22:04 ` Viacheslav Dubeyko
2025-11-21 23:16 ` Mehdi Ben Hadj Khelifa
2025-11-21 22:28 ` Viacheslav Dubeyko
2025-11-21 23:36 ` Mehdi Ben Hadj Khelifa
2025-11-21 23:01 ` Viacheslav Dubeyko
2025-11-25 22:14 ` Mehdi Ben Hadj Khelifa
2025-11-25 22:36 ` Viacheslav Dubeyko
2025-11-27 17:45 ` David Hunter
2025-11-29 13:06 ` Mehdi Ben Hadj Khelifa
2025-11-26 13:48 ` Christian Brauner
2025-11-26 16:06 ` Mehdi Ben Hadj Khelifa
2025-11-26 22:30 ` Viacheslav Dubeyko
2025-11-27 8:59 ` Christian Brauner
2025-11-27 20:19 ` Viacheslav Dubeyko
2025-11-29 12:48 ` Mehdi Ben Hadj Khelifa
2025-12-01 19:24 ` Viacheslav Dubeyko
2025-12-01 21:19 ` Mehdi Ben Hadj Khelifa
2025-12-01 20:37 ` Viacheslav Dubeyko
2025-12-01 21:57 ` Mehdi Ben Hadj Khelifa
2026-01-17 18:51 ` Mehdi Ben Hadj Khelifa
2026-01-19 17:48 ` Viacheslav Dubeyko
2026-01-19 19:03 ` Mehdi Ben Hadj Khelifa
2026-01-19 18:27 ` Viacheslav Dubeyko
2026-01-19 21:34 ` Mehdi Ben Hadj Khelifa
2026-01-19 20:55 ` Viacheslav Dubeyko
2026-01-20 13:52 ` Mehdi Ben Hadj Khelifa
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=dc78b78d-14fc-456d-ae21-e79225b77afa@gmail.com \
--to=mehdi.benhadjkhelifa@gmail.com \
--cc=brauner@kernel.org \
--cc=david.hunter.linux@gmail.com \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=jack@suse.cz \
--cc=khalid@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=slava@dubeyko.com \
--cc=syzbot+ad45f827c88778ff7df6@syzkaller.appspotmail.com \
--cc=viro@zeniv.linux.org.uk \
/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.