f2fs: fix to avoid NULL pointer dereference in f2fs_check_quota_consistency()
Chao Yu
maintainerPATCH 1/2 f2fs: fix to avoid NULL pointer dereference in f2fs_check_quota_consistency()
syzbot reported a f2fs bug as below:
Oops: gen[ 107.736417][ T5848] Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] SMP KASAN PTI
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
CPU: 1 UID: 0 PID: 5848 Comm: syz-executor263 Tainted: G W 6.17.0-rc1-syzkaller-00014-g0e39a731820a #0 PREEMPT_{RT,(full)}
RIP: 0010:strcmp+0x3c/0xc0 lib/string.c:284
Call Trace:
<TASK>
f2fs_check_quota_consistency fs/f2fs/super.c:1188 [inline]
f2fs_check_opt_consistency+0x1378/0x2c10 fs/f2fs/super.c:1436
__f2fs_remount fs/f2fs/super.c:2653 [inline]
f2fs_reconfigure+0x482/0x1770 fs/f2fs/super.c:5297
reconfigure_super+0x224/0x890 fs/super.c:1077
do_remount fs/namespace.c:3314 [inline]
path_mount+0xd18/0xfe0 fs/namespace.c:4112
do_mount fs/namespace.c:4133 [inline]
__do_sys_mount fs/namespace.c:4344 [inline]
__se_sys_mount+0x317/0x410 fs/namespace.c:4321
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7fThe direct reason is f2fs_check_quota_consistency() may suffer null-ptr-deref issue in strcmp().
The bug can be reproduced w/ below scripts:
mkfs.f2fs -f /dev/vdb
mount -t f2fs -o usrquota /dev/vdb /mnt/f2fs
quotacheck -uc /mnt/f2fs/
umount /mnt/f2fs
mount -t f2fs -o usrjquota=aquota.user,jqfmt=vfsold /dev/vdb /mnt/f2fs mount -t f2fs -o remount,usrjquota=,jqfmt=vfsold /dev/vdb /mnt/f2fs umount /mnt/f2fs
So, before old_qname and new_qname comparison, we need to check whether they are all valid pointers, fix it.
--- fs/f2fs/super.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/f2fs/super.c +2 -1
@@ -1219,7 +1219,8 @@ static int f2fs_check_quota_consistency(struct fs_context *fc, goto err_jquota_change;if (old_qname) { -if (strcmp (old_qname, new_qname) ==0 ) { +if (new_qname && +strcmp (old_qname, new_qname) ==0 ) { ctx->qname_mask &= ~(1 << i);continue ; }
Signature · 1 line
2.49.0
Chao Yu
maintainerPATCH 2/2 f2fs: fix to allow removing qf_name
The mount behavior changed after commit d18535132523 ("f2fs: separate the options parsing and options checking"), let's fix it.
[Scripts]
mkfs.f2fs -f /dev/vdb
mount -t f2fs -o usrquota /dev/vdb /mnt/f2fs
quotacheck -uc /mnt/f2fs
umount /mnt/f2fs
mount -t f2fs -o usrjquota=aquota.user,jqfmt=vfsold /dev/vdb /mnt/f2fs mount|grep f2fs
mount -t f2fs -o remount,usrjquota=,jqfmt=vfsold /dev/vdb /mnt/f2fs mount|grep f2fs
dmesg
[Before commit]
mount#1: ...,quota,jqfmt=vfsold,usrjquota=aquota.user,... mount#2: ...,quota,jqfmt=vfsold,...
kmsg: no output
[After commit]
mount#1: ...,quota,jqfmt=vfsold,usrjquota=aquota.user,... mount#2: ...,quota,jqfmt=vfsold,usrjquota=aquota.user,...
kmsg: "user quota file already specified"
[After patch]
mount#1: ...,quota,jqfmt=vfsold,usrjquota=aquota.user,... mount#2: ...,quota,jqfmt=vfsold,...
kmsg: "remove qf_name aquota.user"
--- fs/f2fs/super.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/f2fs/super.c +5 -2
@@ -1219,8 +1219,11 @@ static int f2fs_check_quota_consistency(struct fs_context *fc, goto err_jquota_change;if (old_qname) { -if (new_qname && -strcmp (old_qname, new_qname) ==0 ) { +if (!new_qname) { +f2fs_info (sbi,"remove qf_name %s" , + old_qname); +continue ; + }else if (strcmp (old_qname, new_qname) ==0 ) { ctx->qname_mask &= ~(1 << i);continue ; }
Signature · 1 line
2.49.0
Re: [PATCH 2/2] f2fs: fix to allow removing qf_name
Hi Chao,
Quoted 41 lines · Chao Yu
The mount behavior changed after commit
d18535132523("f2fs: separate the options parsing and options checking"), let's fix it.[Scripts]
mkfs.f2fs -f/dev/vdb
mount -t f2fs -o usrquota/dev/vdb/mnt/f2fs
quotacheck -uc/mnt/f2fs
umount/mnt/f2fs
mount -t f2fs -o usrjquota=aquota.user,jqfmt=vfsold/dev/vdb/mnt/f2fsmount|grep f2fs
mount -t f2fs -o remount,usrjquota=,jqfmt=vfsold/dev/vdb/mnt/f2fsmount|grep f2fs
dmesg[Before commit]
mount#1: ...,quota,jqfmt=vfsold,usrjquota=aquota.user,... mount#2: ...,quota,jqfmt=vfsold,...
kmsg: no output[After commit]
mount#1: ...,quota,jqfmt=vfsold,usrjquota=aquota.user,... mount#2: ...,quota,jqfmt=vfsold,usrjquota=aquota.user,...
kmsg: "user quota file already specified"[After patch]
mount#1: ...,quota,jqfmt=vfsold,usrjquota=aquota.user,... mount#2: ...,quota,jqfmt=vfsold,...
kmsg: "removeqf_nameaquota.user"Fixes d18535132523 ("f2fs: separate the options parsing and options checking")Cc Hongbo Li <[email protected]>Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/super.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)fs/f2fs/super.c +0
-0
fs/f2fs/super.c static int f2fs_check_quota_consistency(struct fs_context *fc, · line 1222
Quoted 6 lines
fs/f2fs/super.c +1
-2@@ -1219,8 +1219,11 @@ static int f2fs_check_quota_consistency(struct fs_context *fc, goto err_jquota_change;if (old_qname) { -if (new_qname && -strcmp (old_qname, new_qname) ==0 ) { +if (!new_qname) {
Thanks for catching this. Do we also need the patch 1/2 ? It seems this patch also solve the syzbot problems.
Thanks,
Hongbo
Quoted 7 lines
fs/f2fs/super.c +4
-0+f2fs_info (sbi,"remove qf_name %s" , + old_qname); +continue ; + }else if (strcmp (old_qname, new_qname) ==0 ) { ctx->qname_mask &= ~(1 << i);continue ; }
Chao Yu
maintainerRe: [PATCH 2/2] f2fs: fix to allow removing qf_name
Quoted 39 lines · Hongbo Li
Hi Chao,
Quoted 36 lines · Chao Yu
The mount behavior changed after commit
d18535132523("f2fs: separate the options parsing and options checking"), let's fix it.[Scripts]
mkfs.f2fs -f/dev/vdb
mount -t f2fs -o usrquota/dev/vdb/mnt/f2fs
quotacheck -uc/mnt/f2fs
umount/mnt/f2fs
mount -t f2fs -o usrjquota=aquota.user,jqfmt=vfsold/dev/vdb/mnt/f2fsmount|grep f2fs
mount -t f2fs -o remount,usrjquota=,jqfmt=vfsold/dev/vdb/mnt/f2fsmount|grep f2fs
dmesg[Before commit]
mount#1: ...,quota,jqfmt=vfsold,usrjquota=aquota.user,... mount#2: ...,quota,jqfmt=vfsold,...
kmsg: no output[After commit]
mount#1: ...,quota,jqfmt=vfsold,usrjquota=aquota.user,... mount#2: ...,quota,jqfmt=vfsold,usrjquota=aquota.user,...
kmsg: "user quota file already specified"[After patch]
mount#1: ...,quota,jqfmt=vfsold,usrjquota=aquota.user,... mount#2: ...,quota,jqfmt=vfsold,...
kmsg: "removeqf_nameaquota.user"Fixes d18535132523 ("f2fs: separate the options parsing and options checking")Cc Hongbo Li <[email protected]>Signed-off-by Chao Yu <[email protected]>---
fs/f2fs/super.c| 7 +++++--1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 12 lines
fs/f2fs/super.c static int f2fs_check_quota_consistency(struct fs_context *fc, · line 1221
Quoted 10 lines
fs/f2fs/super.c +1
-2@@ -1219,8 +1219,11 @@ static int f2fs_check_quota_consistency(struct fs_context *fc, goto err_jquota_change; if (old_qname) { - if (new_qname && - strcmp(old_qname, new_qname) == 0) { + if (!new_qname) {Thanks for catching this. Do we also need the patch 1/2 ? It seems this patch also solve the syzbot problems.
I prefer to split it, since it'd better to use one patch to resolve one problem. :)
Thanks,
Quoted 11 lines
Thanks,
HongboQuoted 7 lines
fs/f2fs/super.c +4
-0+ f2fs_info(sbi, "remove qf_name %s", + old_qname); + continue; + } else if (strcmp(old_qname, new_qname) == 0) { ctx->qname_mask &= ~(1 << i); continue; }
Re: [PATCH 2/2] f2fs: fix to allow removing qf_name
In reply to Chao YuQuoted 29 lines · Chao Yu
The mount behavior changed after commit
d18535132523("f2fs: separate the options parsing and options checking"), let's fix it.[Scripts]
mkfs.f2fs -f/dev/vdb
mount -t f2fs -o usrquota/dev/vdb/mnt/f2fs
quotacheck -uc/mnt/f2fs
umount/mnt/f2fs
mount -t f2fs -o usrjquota=aquota.user,jqfmt=vfsold/dev/vdb/mnt/f2fsmount|grep f2fs
mount -t f2fs -o remount,usrjquota=,jqfmt=vfsold/dev/vdb/mnt/f2fsmount|grep f2fs
dmesg[Before commit]
mount#1: ...,quota,jqfmt=vfsold,usrjquota=aquota.user,... mount#2: ...,quota,jqfmt=vfsold,...
kmsg: no output[After commit]
mount#1: ...,quota,jqfmt=vfsold,usrjquota=aquota.user,... mount#2: ...,quota,jqfmt=vfsold,usrjquota=aquota.user,...
kmsg: "user quota file already specified"[After patch]
mount#1: ...,quota,jqfmt=vfsold,usrjquota=aquota.user,... mount#2: ...,quota,jqfmt=vfsold,...
kmsg: "removeqf_nameaquota.user"
Quoted 4 lines
Fixes d18535132523 ("f2fs: separate the options parsing and options checking")Cc Hongbo Li <[email protected]>Signed-off-by Chao Yu <[email protected]>---
Thanks,
Hongbo
Quoted 21 lines
fs/f2fs/super.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)fs/f2fs/super.c +5
-2@@ -1219,8 +1219,11 @@ static int f2fs_check_quota_consistency(struct fs_context *fc, goto err_jquota_change;if (old_qname) { -if (new_qname && -strcmp (old_qname, new_qname) ==0 ) { +if (!new_qname) { +f2fs_info (sbi,"remove qf_name %s" , + old_qname); +continue ; + }else if (strcmp (old_qname, new_qname) ==0 ) { ctx->qname_mask &= ~(1 << i);continue ; }
Quoted 37 lines · Chao Yu
syzbot reported a f2fs bug as below:
Oops: gen[ 107.736417][ T5848] Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] SMP KASAN PTI KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] CPU: 1 UID: 0 PID: 5848 Comm: syz-executor263 Tainted: G W 6.17.0-rc1-syzkaller-00014-g0e39a731820a #0 PREEMPT_{RT,(full)} RIP: 0010:strcmp+0x3c/0xc0 lib/string.c:284 Call Trace: <TASK> f2fs_check_quota_consistency fs/f2fs/super.c:1188 [inline] f2fs_check_opt_consistency+0x1378/0x2c10 fs/f2fs/super.c:1436 __f2fs_remount fs/f2fs/super.c:2653 [inline] f2fs_reconfigure+0x482/0x1770 fs/f2fs/super.c:5297 reconfigure_super+0x224/0x890 fs/super.c:1077 do_remount fs/namespace.c:3314 [inline] path_mount+0xd18/0xfe0 fs/namespace.c:4112 do_mount fs/namespace.c:4133 [inline] __do_sys_mount fs/namespace.c:4344 [inline] __se_sys_mount+0x317/0x410 fs/namespace.c:4321 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7fThe direct reason is
f2fs_check_quota_consistency()may suffer null-ptr-deref issue instrcmp().The bug can be reproduced w/ below scripts:
mkfs.f2fs -f/dev/vdb
mount -t f2fs -o usrquota/dev/vdb/mnt/f2fs
quotacheck -uc/mnt/f2fs/
umount/mnt/f2fs
mount -t f2fs -o usrjquota=aquota.user,jqfmt=vfsold/dev/vdb/mnt/f2fsmount -t f2fs -o remount,usrjquota=,jqfmt=vfsold/dev/vdb/mnt/f2fsumount/mnt/f2fsSo, before
old_qnameandnew_qnamecomparison, we need to check whether they are all valid pointers, fix it.
Quoted 6 lines
Reported-by [email protected]Fixes d18535132523 ("f2fs: separate the options parsing and options checking")Cc Hongbo Li <[email protected]>Signed-off-by Chao Yu <[email protected]>---
Thanks,
Hongbo
Quoted 17 lines
fs/f2fs/super.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/f2fs/super.c +2
-1@@ -1219,7 +1219,8 @@ static int f2fs_check_quota_consistency(struct fs_context *fc, goto err_jquota_change;if (old_qname) { -if (strcmp (old_qname, new_qname) ==0 ) { +if (new_qname && +strcmp (old_qname, new_qname) ==0 ) { ctx->qname_mask &= ~(1 << i);continue ; }
This series was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:
Hello:
This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:
Quoted 22 lines · On Mon, 18 Aug 2025 10:09:38 +0800 you wrote:
syzbot reported a f2fs bug as below:
Oops: gen[ 107.736417][ T5848] Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] SMP KASAN PTI KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] CPU: 1 UID: 0 PID: 5848 Comm: syz-executor263 Tainted: G W 6.17.0-rc1-syzkaller-00014-g0e39a731820a #0 PREEMPT_{RT,(full)} RIP: 0010:strcmp+0x3c/0xc0 lib/string.c:284 Call Trace: <TASK> f2fs_check_quota_consistency fs/f2fs/super.c:1188 [inline] f2fs_check_opt_consistency+0x1378/0x2c10 fs/f2fs/super.c:1436 __f2fs_remount fs/f2fs/super.c:2653 [inline] f2fs_reconfigure+0x482/0x1770 fs/f2fs/super.c:5297 reconfigure_super+0x224/0x890 fs/super.c:1077 do_remount fs/namespace.c:3314 [inline] path_mount+0xd18/0xfe0 fs/namespace.c:4112 do_mount fs/namespace.c:4133 [inline] __do_sys_mount fs/namespace.c:4344 [inline] __se_sys_mount+0x317/0x410 fs/namespace.c:4321 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f
Quoted 1 line
[...]
Here is the summary with links:
- [f2fs-dev,1/2] f2fs: fix to avoid NULL pointer dereference in f2fs_check_quota_consistency()
https://git.kernel.org/jaegeuk/f2fs/c/930a9a6ee8e7 - [f2fs-dev,2/2] f2fs: fix to allow removing qf_name https://git.kernel.org/jaegeuk/f2fs/c/ff11d8701b77
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html