From: Zhan Xusheng <zhanxusheng1024@gmail.com>
To: jaegeuk@kernel.org, chao@kernel.org
Cc: lihongbo22@huawei.com, sandeen@redhat.com,
linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, zhanxusheng@xiaomi.com,
syzbot+e818dd42ada3b583bed1@syzkaller.appspotmail.com,
stable@vger.kernel.org
Subject: [PATCH 1/2] f2fs: fix use-after-free of quota file names on failed remount
Date: Fri, 30 Oct 2026 15:24:22 +0800 [thread overview]
Message-ID: <20261030072423.197883-1-zhanxusheng1024@gmail.com> (raw)
From: Zhan Xusheng <zhanxusheng@xiaomi.com>
f2fs_show_options() prints the journalled quota file names without any
lock that excludes remount, and a failed remount frees the current names
before restoring the old ones. Reading /proc/mounts at that moment is a
use-after-free.
Read the names under rcu_read_lock() and free them only after a grace
period.
Fixes: 4b2414d04e99 ("f2fs: support journalled quota")
Reported-by: syzbot+e818dd42ada3b583bed1@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=e818dd42ada3b583bed1
Cc: stable@vger.kernel.org
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
The names are not marked __rcu: every other access holds s_umount,
except is_journalled_quota(), which only tests them for NULL.
fs/f2fs/super.c | 30 +++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 1071059f2cc2..510df7998c18 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -2325,6 +2325,7 @@ static inline void f2fs_show_quota_options(struct seq_file *seq,
{
#ifdef CONFIG_QUOTA
struct f2fs_sb_info *sbi = F2FS_SB(sb);
+ char *qf_name;
if (F2FS_OPTION(sbi).s_jquota_fmt) {
char *fmtname = "";
@@ -2343,17 +2344,20 @@ static inline void f2fs_show_quota_options(struct seq_file *seq,
seq_printf(seq, ",jqfmt=%s", fmtname);
}
- if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA])
- seq_show_option(seq, "usrjquota",
- F2FS_OPTION(sbi).s_qf_names[USRQUOTA]);
+ /* Remount frees replaced names only after a grace period */
+ rcu_read_lock();
+ qf_name = READ_ONCE(F2FS_OPTION(sbi).s_qf_names[USRQUOTA]);
+ if (qf_name)
+ seq_show_option(seq, "usrjquota", qf_name);
- if (F2FS_OPTION(sbi).s_qf_names[GRPQUOTA])
- seq_show_option(seq, "grpjquota",
- F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]);
+ qf_name = READ_ONCE(F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]);
+ if (qf_name)
+ seq_show_option(seq, "grpjquota", qf_name);
- if (F2FS_OPTION(sbi).s_qf_names[PRJQUOTA])
- seq_show_option(seq, "prjjquota",
- F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]);
+ qf_name = READ_ONCE(F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]);
+ if (qf_name)
+ seq_show_option(seq, "prjjquota", qf_name);
+ rcu_read_unlock();
#endif
}
@@ -3151,8 +3155,12 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
#ifdef CONFIG_QUOTA
F2FS_OPTION(sbi).s_jquota_fmt = org_mount_opt.s_jquota_fmt;
for (i = 0; i < MAXQUOTAS; i++) {
- kfree(F2FS_OPTION(sbi).s_qf_names[i]);
- F2FS_OPTION(sbi).s_qf_names[i] = org_mount_opt.s_qf_names[i];
+ char *qf_name = F2FS_OPTION(sbi).s_qf_names[i];
+
+ /* Pairs with READ_ONCE() in f2fs_show_quota_options() */
+ smp_store_release(&F2FS_OPTION(sbi).s_qf_names[i],
+ org_mount_opt.s_qf_names[i]);
+ kfree_rcu_mightsleep(qf_name);
}
#endif
sbi->mount_opt = org_mount_opt;
base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
--
2.43.0
next reply other threads:[~2026-10-30 7:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 7:24 Zhan Xusheng [this message]
2026-10-30 7:24 ` [PATCH 2/2] f2fs: free the quota file name that remount drops Zhan Xusheng
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=20261030072423.197883-1-zhanxusheng1024@gmail.com \
--to=zhanxusheng1024@gmail.com \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=lihongbo22@huawei.com \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=sandeen@redhat.com \
--cc=stable@vger.kernel.org \
--cc=syzbot+e818dd42ada3b583bed1@syzkaller.appspotmail.com \
--cc=zhanxusheng@xiaomi.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®