kernel BUG in f2fs_put_super (6)

Status: moderation: reported on 2026/11/28 07:56
Subsystems: f2fs
Labels: prio:low
[Documentation on labels]
Reported-by: syzbot+b9fe816c11c6684fe7dc@syzkaller.appspotmail.com
First crash: 1h49m, last: 1h45m
✨ AI cause bisection: introduced by (AI job) :
commit 2c8a4a28233482ad697db92d86da10fcb498eaf7
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date: Tue Nov 14 01:46:38 2017 +0000

  f2fs: expose quota information in debugfs

✨ AI-generated root cause summary:

In f2fs, sbi->nr_caches[F2FS_DIRTY_QDATA] is incremented in inode_inc_dirty_pages() and decremented in inode_dec_dirty_pages() conditionally on IS_NOQUOTA(inode) (S_NOQUOTA), which assumes S_NOQUOTA cannot change while an inode has dirty folios. However, f2fs_quota_on() flushes dirty pages via filemap_fdatawrite()/filemap_fdatawait() without holding inode_lock, filemap_invalidate_lock, or denying concurrent writes/mmap faults before dquot_quota_on() -> vfs_setup_quota_inode() sets S_NOQUOTA on the inode. A folio dirtied during that window increments F2FS_DIRTY_DATA without incrementing F2FS_DIRTY_QDATA, and when subsequently written back or invalidated (including by sync_filesystem() inside dquot_load_quota_sb()) after S_NOQUOTA is set, inode_dec_dirty_pages() decrements both F2FS_DIRTY_DATA and F2FS_DIRTY_QDATA, driving F2FS_DIRTY_QDATA to -1 and triggering f2fs_bug_on(sbi, 1) in f2fs_put_super().

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 822ba3a89c78:

Root Cause Analysis

The crash in f2fs_put_super() (fs/f2fs/super.c:2084) reports:

F2FS-fs (loop7): detect filesystem reference count leak during umount, type: 2, count: -1, err: -5, cp_err: 1

Here, type: 2 is F2FS_DIRTY_QDATA in enum count_type (fs/f2fs/f2fs.h:1238-1254), count: -1 is sbi->nr_caches[F2FS_DIRTY_QDATA], err: -5 (-EIO) is returned by f2fs_write_checkpoint() at fs/f2fs/super.c:2038, and cp_err: 1 reflects f2fs_cp_error(sbi) (SBI_CP_ERROR set prior to/during unmount). Notice that f2fs_put_super() loops from i = 0 (F2FS_DIRTY_DENTS) to NR_COUNT_TYPE - 1 (fs/f2fs/super.c:2078-2085), so both F2FS_DIRTY_DENTS (0) and F2FS_DIRTY_DATA (1) are 0, while F2FS_DIRTY_QDATA (2) is -1.

Broken Invariant in Dirty-Page Accounting

sbi->nr_caches[F2FS_DIRTY_QDATA] is modified in only two functions, both in fs/f2fs/f2fs.h:

  • inode_inc_dirty_pages(struct inode *inode) (fs/f2fs/f2fs.h:2869-2876) increments F2FS_I(inode)->dirty_pages and sbi->nr_caches[F2FS_DIRTY_DENTS] or sbi->nr_caches[F2FS_DIRTY_DATA], and conditionally increments sbi->nr_caches[F2FS_DIRTY_QDATA] if IS_NOQUOTA(inode) (inode->i_flags & S_NOQUOTA) is true.
  • inode_dec_dirty_pages(struct inode *inode) (fs/f2fs/f2fs.h:2883-2894) decrements F2FS_I(inode)->dirty_pages and sbi->nr_caches[F2FS_DIRTY_DENTS] or sbi->nr_caches[F2FS_DIRTY_DATA], and conditionally decrements sbi->nr_caches[F2FS_DIRTY_QDATA] if IS_NOQUOTA(inode) is true.

For F2FS_DIRTY_DATA to balance to 0 while F2FS_DIRTY_QDATA underflows to -1, a folio belonging to a regular (or symlink) inode must be dirtied (inode_inc_dirty_pages()) while S_NOQUOTA is clear (incrementing F2FS_DIRTY_DATA only), and later written back or invalidated (inode_dec_dirty_pages()) while S_NOQUOTA is set (decrementing both F2FS_DIRTY_DATA and F2FS_DIRTY_QDATA).

How the State Transition Happens

  1. Missing synchronization in f2fs_quota_on() (fs/f2fs/super.c:3561-3608): When quotactl(Q_QUOTAON) is invoked on a regular file (when F2FS_FEATURE_QUOTA_INO is not enabled), f2fs_quota_on() attempts to flush dirty pages before handing the inode to the quota subsystem:

    err = f2fs_quota_convert_inline(inode);
    ...
    err = filemap_fdatawrite(inode->i_mapping);
    ...
    err = filemap_fdatawait(inode->i_mapping);
    ...
    err = dquot_quota_on(sb, type, format_id, path);
    

    f2fs_quota_on() does not hold inode_lock(inode), does not hold filemap_invalidate_lock(inode->i_mapping), and does not prevent concurrent writable opens or mmap page faults (e.g. via deny_write_access()).

  2. Window between flush and S_NOQUOTA: Between filemap_fdatawait(inode->i_mapping) (fs/f2fs/super.c:3592) and dquot_quota_on() -> dquot_load_quota_inode() -> vfs_setup_quota_inode() (fs/quota/dquot.c:2365-2367, which acquires inode_lock(inode) and sets inode->i_flags |= S_NOQUOTA), another thread can dirty a folio of inode via write() or a shared mmap fault (f2fs_vm_page_mkwrite() -> folio_mark_dirty() -> f2fs_dirty_data_folio() -> f2fs_update_dirty_folio()). Because S_NOQUOTA is still clear at that moment, inode_inc_dirty_pages(inode) increments F2FS_DIRTY_DATA by 1 and leaves F2FS_DIRTY_QDATA unchanged.

  3. Underflow on writeback or invalidation: Immediately after vfs_setup_quota_inode() sets S_NOQUOTA, dquot_load_quota_inode() (fs/quota/dquot.c:2466-2472) calls dquot_load_quota_sb(). Before check_quota_file() even validates whether the target file is a valid quota file, dquot_load_quota_sb() calls sync_filesystem(sb) (fs/quota/dquot.c:2420). Writing back or invalidating that folio (in f2fs_write_single_data_page() at fs/f2fs/data.c:3425, f2fs_write_compressed_pages() at fs/f2fs/compress.c:1417, or f2fs_invalidate_folio() at fs/f2fs/data.c:4319) calls inode_dec_dirty_pages(inode) while IS_NOQUOTA(inode) is now true:

    • F2FS_DIRTY_DATA is decremented back to 0.
    • F2FS_DIRTY_QDATA is decremented from 0 to -1.

    Even if dquot_load_quota_sb() subsequently fails (e.g., -EINVAL from check_quota_file() on an arbitrary file) and vfs_cleanup_quota_inode() (fs/quota/dquot.c:2196-2210) clears S_NOQUOTA, the -1 underflow in sbi->nr_caches[F2FS_DIRTY_QDATA] persists.

    (Note: A secondary path with the same pattern exists in f2fs_quota_enable() at fs/f2fs/super.c:3410-3436, which sets qf_inode->i_flags |= S_NOQUOTA on qf_inum without flushing dirty folios if a corrupted image or RO->RW remount in __f2fs_remount() exposed qf_inum with dirty pages beforehand; by contrast, f2fs_new_inode()'s fail_drop: at fs/f2fs/namei.c:358 only sets S_NOQUOTA on an unexposed I_NEW inode with no dirty folios.)

  4. Failure at unmount: During umount, f2fs_put_super() checks all sbi->nr_caches[i] counters after dropping caches (fs/f2fs/super.c:2078-2085), finds get_nr_caches(sbi, F2FS_DIRTY_QDATA) == -1, logs the reference count leak error, and hits f2fs_bug_on(sbi, 1) at fs/f2fs/super.c:2084.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
afdc04f1 bisect-cause IsRelease: ❌ ❓ kernel BUG in f2fs_put_super (6) 2026/11/28 07:23 2026/11/28 07:23 2026/11/28 08:30 e1f06033
a024558d assessment-security DenialOfService: ✅ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ kernel BUG in f2fs_put_super (6) 2026/11/28 07:02 2026/11/28 07:03 2026/11/28 07:55 e1f06033
▶ ▼ Similar bugs (5)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream kernel BUG in f2fs_put_super (4) f2fs -1 1 337d 333d 0/30 auto-obsoleted due to no activity on 2026/04/04 12:44
upstream kernel BUG in f2fs_put_super f2fs -1 2 1149d 1179d 25/30 fixed on 2023/12/21 03:45
upstream kernel BUG in f2fs_put_super (5) prio:low f2fs -1 1 202d 198d 0/30 auto-obsoleted due to no activity on 2026/08/18 05:21
upstream kernel BUG in f2fs_put_super (3) f2fs -1 1 599d 595d 0/30 auto-obsoleted due to no activity on 2025/07/17 03:15
upstream kernel BUG in f2fs_put_super (2) f2fs -1 1 708d 704d 0/30 auto-obsoleted due to no activity on 2025/03/29 22:05

Sample crash report:
F2FS-fs (loop0): detect filesystem reference count leak during umount, type: 2, count: -1, err: -5, cp_err: 1
------------[ cut here ]------------
kernel BUG at fs/f2fs/super.c:2084!
Oops: invalid opcode: 0000 [#1] SMP KASAN PTI
CPU: 1 UID: 0 PID: 5608 Comm: syz-executor Not tainted syzkaller #0 PREEMPT_{RT,(full)} 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
RIP: 0010:f2fs_put_super+0x145a/0x1460 fs/f2fs/super.c:2084
Code: c1 e8 03 83 e0 01 48 8b 7c 24 18 31 f6 48 c7 c2 20 54 df 8b 44 89 f9 4d 89 f0 44 8b 4c 24 28 50 e8 fb 21 fd ff 48 83 c4 08 90 <0f> 0b 0f 1f 40 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90
RSP: 0018:ffffc90004d878c0 EFLAGS: 00010296
RAX: 13140eff92de3600 RBX: dffffc0000000000 RCX: 13140eff92de3600
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
RBP: ffffc90004d87b38 R08: 0000000000000000 R09: 0000000000000000
R10: dffffc0000000000 R11: fffff520009b0ea1 R12: ffff888039530084
R13: ffff888039530087 R14: ffffffffffffffff R15: 0000000000000002
FS:  000055557bc1c500(0000) GS:ffff8881247fb000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00005555623bea68 CR3: 0000000037812000 CR4: 00000000003526f0
Call Trace:
 <TASK>
 generic_shutdown_super+0x140/0x2d0 fs/super.c:723
 kill_block_super+0x44/0xa0 fs/super.c:1852
 kill_f2fs_super+0x3b5/0x700 fs/f2fs/super.c:5788
 deactivate_locked_super+0xbe/0x110 fs/super.c:558
 cleanup_mnt+0x204/0x2a0 fs/namespace.c:1396
 task_work_run+0x1d9/0x260 kernel/task_work.c:233
 resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
 __exit_to_user_mode_loop kernel/entry/common.c:70 [inline]
 exit_to_user_mode_loop+0x204/0x770 kernel/entry/common.c:101
 __exit_to_user_mode_prepare include/linux/irq-entry-common.h:207 [inline]
 syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:230 [inline]
 syscall_exit_to_user_mode include/linux/entry-common.h:343 [inline]
 do_syscall_64+0x336/0x540 arch/x86/entry/syscall_64.c:107
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fbf0e7aadc7
Code: a2 c7 05 2c 69 25 00 00 00 00 00 eb 96 e8 b1 13 00 00 90 31 f6 e9 09 00 00 00 66 0f 1f 84 00 00 00 00 00 b8 a6 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 01 c3 48 c7 c2 e8 ff ff ff f7 d8 64 89 02 b8
RSP: 002b:00007ffdab4d8638 EFLAGS: 00000246 ORIG_RAX: 00000000000000a6
RAX: 0000000000000000 RBX: 00007fbf0e83955b RCX: 00007fbf0e7aadc7
RDX: 0000000000000000 RSI: 0000000000000009 RDI: 00007ffdab4d86f0
RBP: 00007ffdab4d86f0 R08: 00007ffdab4d96f0 R09: 00000000ffffffff
R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffdab4d9780
R13: 00007fbf0e83955b R14: 000000000002391c R15: 00007ffdab4d97c0
 </TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:f2fs_put_super+0x145a/0x1460 fs/f2fs/super.c:2084
Code: c1 e8 03 83 e0 01 48 8b 7c 24 18 31 f6 48 c7 c2 20 54 df 8b 44 89 f9 4d 89 f0 44 8b 4c 24 28 50 e8 fb 21 fd ff 48 83 c4 08 90 <0f> 0b 0f 1f 40 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90
RSP: 0018:ffffc90004d878c0 EFLAGS: 00010296
RAX: 13140eff92de3600 RBX: dffffc0000000000 RCX: 13140eff92de3600
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
RBP: ffffc90004d87b38 R08: 0000000000000000 R09: 0000000000000000
R10: dffffc0000000000 R11: fffff520009b0ea1 R12: ffff888039530084
R13: ffff888039530087 R14: ffffffffffffffff R15: 0000000000000002
FS:  000055557bc1c500(0000) GS:ffff8881247fb000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f52f21b2000 CR3: 0000000037812000 CR4: 00000000003526f0

Crashes (5):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/28 07:06 upstream 822ba3a89c78 e1f06033 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs kernel BUG in f2fs_put_super
2026/11/28 07:06 upstream 822ba3a89c78 e1f06033 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs kernel BUG in f2fs_put_super
2026/11/28 07:05 upstream 822ba3a89c78 e1f06033 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs kernel BUG in f2fs_put_super
2026/11/28 07:03 upstream 822ba3a89c78 e1f06033 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs kernel BUG in f2fs_put_super
2026/11/28 07:02 upstream 822ba3a89c78 e1f06033 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs kernel BUG in f2fs_put_super
* Struck through repros no longer work on HEAD.