[PATCH] fs/super: fix memory leak of s_fs_info on setup_bdev_super failure

From: Mehdi Ben Hadj Khelifa

Date: Fri Nov 14 2025 - 10:53:16 EST


Failure in setup_bdev_super() triggers an error path where
fc->s_fs_info ownership has already been transferred to the superblock via
sget_fc() call in get_tree_bdev_flags() and calling put_fs_context() in
do_new_mount() to free the s_fs_info for the specific filesystem gets
passed in a NULL pointer.

Pass back the ownership of the s_fs_info pointer to the filesystem context
once the error path has been triggered to be cleaned up gracefully in
put_fs_context().

Fixes: cb50b348c71f ("convenience helpers: vfs_get_super() and sget_fc()")
Reported-by: syzbot+ad45f827c88778ff7df6@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=ad45f827c88778ff7df6
Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@xxxxxxxxx>
---
Note:This patch might need some more testing as I only did run selftests
with no regression, check dmesg output for no regression, run reproducer
with no bug.

fs/super.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/fs/super.c b/fs/super.c
index 5bab94fb7e03..8fadf97fcc42 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -1690,6 +1690,11 @@ int get_tree_bdev_flags(struct fs_context *fc,
if (!error)
error = fill_super(s, fc);
if (error) {
+ /*
+ * return s_fs_info ownership to fc to be cleaned up by put_fs_context()
+ */
+ fc->s_fs_info = s->s_fs_info;
+ s->s_fs_info = NULL;
deactivate_locked_super(s);
return error;
}
--
2.51.2