From: Shardul Bankar <shardulsb08@gmail.com>
To: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: janak@mpiricsoftware.com, shardulsb08@gmail.com,
slava@dubeyko.com, Shardul Bankar <shardul.b@mpiricsoftware.com>,
syzbot+99f6ed51479b86ac4c41@syzkaller.appspotmail.com
Subject: [PATCH] fs/super: fix s_fs_info leak when setup_bdev_super() fails
Date: Sun, 1 Feb 2026 13:02:26 +0530 [thread overview]
Message-ID: <20260201073226.3445853-1-shardul.b@mpiricsoftware.com> (raw)
In get_tree_bdev_flags(), sget_dev() calls sget_fc(), which transfers
ownership of fc->s_fs_info to the new superblock (s->s_fs_info) and
clears fc->s_fs_info. If setup_bdev_super() then fails, the superblock
is torn down via deactivate_locked_super(). However,
generic_shutdown_super() only calls the filesystem's ->put_super()
when sb->s_root is non-NULL. Since setup_bdev_super() fails before
fill_super() runs, sb->s_root is never set, so ->put_super() is never
called and the allocated s_fs_info is leaked.
Return ownership of s_fs_info to fc when setup_bdev_super() fails so
put_fs_context() can free it via the filesystem's ->free() callback.
Clear s->s_fs_info to avoid a stale reference. Do this only when
setup_bdev_super() fails; when fill_super() fails, it already frees
s_fs_info in its own error path.
Reported-by: syzbot+99f6ed51479b86ac4c41@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=99f6ed51479b86ac4c41
Signed-off-by: Shardul Bankar <shardul.b@mpiricsoftware.com>
---
fs/super.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/super.c b/fs/super.c
index 3d85265d1400..1aa8dbd19bb6 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -1687,6 +1687,11 @@ int get_tree_bdev_flags(struct fs_context *fc,
}
} else {
error = setup_bdev_super(s, fc->sb_flags, fc);
+ if (error) {
+ fc->s_fs_info = s->s_fs_info;
+ s->s_fs_info = NULL;
+ }
+
if (!error)
error = fill_super(s, fc);
if (error) {
--
2.34.1
next reply other threads:[~2026-02-01 7:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-01 7:32 Shardul Bankar [this message]
2026-02-01 8:27 ` Al Viro
2026-02-01 11:39 ` Shardul Bankar
2026-02-01 11:50 ` [syzbot ci] " syzbot ci
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=20260201073226.3445853-1-shardul.b@mpiricsoftware.com \
--to=shardulsb08@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=janak@mpiricsoftware.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shardul.b@mpiricsoftware.com \
--cc=slava@dubeyko.com \
--cc=syzbot+99f6ed51479b86ac4c41@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome