[PATCH 1/2] f2fs: fix use-after-free of quota file names on failed remount
From: Zhan Xusheng
Date: Fri Oct 30 2026 - 03:24:45 EST
From: Zhan Xusheng <zhanxusheng@xxxxxxxxxx>
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@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=e818dd42ada3b583bed1
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Zhan Xusheng <zhanxusheng@xxxxxxxxxx>
---
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