[BUG] gfs2: spinlock bad magic in ifs_clear_range_dirty due to non-jdata quota inode
From: Xinyuan Zhao
Date: Fri Nov 27 2026 - 02:28:08 EST
Hi Andreas and GFS2 maintainers,
While fuzzing Linux 7.4.0-rc3 (upstream commit 4405c18) on x86_64 with
syzkaller, we encountered a "BUG: spinlock bad magic" in
ifs_clear_range_dirty() triggered during unmount of a crafted GFS2 image.
The issue is reproducible on an untainted 7.4.0-rc3 kernel. We also
checked the latest mainline (v7.4-rc4), and the relevant paths in
init_inodes(), gfs2_adjust_quota(), and gfs2_write_buf_to_page() remain
unchanged.
Summary / Root Cause Analysis
=============================
It appears to be a folio->private type confusion between struct buffer_head
and struct iomap_folio_state on the hidden quota system inode:
1. In init_inodes() (fs/gfs2/ops_fstype.c:859), sdp->sd_quota_inode is
loaded via gfs2_lookup_meta(master, "quota"), without checking whether
GFS2_DIF_JDATA is set in di_flags.
2. If the on-disk quota inode in a corrupted/crafted GFS2 image is a
stuffed regular file without GFS2_DIF_JDATA, gfs2_dinode_in()
(fs/gfs2/glops.c:475-476) calls gfs2_set_aops(inode), which assigns
gfs2_aops (iomap-based) instead of gfs2_jdata_aops (buffer_head-based).
3. During quota sync (e.g., on unmount via gfs2_sync_fs() ->
gfs2_quota_sync() -> do_sync() -> gfs2_adjust_quota()):
- gfs2_adjust_quota() (fs/gfs2/quota.c:863-864) calls
gfs2_unstuff_dinode(ip). Because !gfs2_is_jdata(ip),
gfs2_unstuff_dinode() (fs/gfs2/bmap.c:84-85) marks the folio dirty
and adds the quota inode to sdp->sd_log_ordered via
gfs2_ordered_add_inode(ip).
- gfs2_adjust_quota() then calls gfs2_write_disk_quota() ->
gfs2_write_buf_to_page() (fs/gfs2/quota.c:760-762), which
unconditionally calls create_empty_buffers(folio, bsize, 0),
attaching a struct buffer_head to folio->private.
- Next, do_sync() (fs/gfs2/quota.c:1000) calls gfs2_log_flush() ->
__gfs2_log_flush() -> gfs2_ordered_write() (fs/gfs2/log.c:730) ->
filemap_fdatawrite() -> gfs2_writepages() (fs/gfs2/aops.c:175) ->
iomap_writepages() -> iomap_writeback_folio()
(fs/iomap/buffered-io.c:2045) -> iomap_clear_range_dirty() ->
ifs_clear_range_dirty() (fs/iomap/buffered-io.c:203).
- iomap_clear_range_dirty() interprets folio->private (actually a
struct buffer_head *) as a struct iomap_folio_state * and calls
spin_lock_irqsave(&ifs->state_lock, flags), triggering
"BUG: spinlock bad magic".
Possible Fix
============
Since gfs2_write_buf_to_page() always operates on buffer_heads and
journals quota data via gfs2_trans_add_data(), validating in init_inodes()
that sdp->sd_quota_inode is a regular file with GFS2_DIF_JDATA set (and
rejecting the mount with an error such as -EFSCORRUPTED/-EIO otherwise)
should prevent this mismatch.
Crash Report
============
BUG: spinlock bad magic on CPU#1, syz-executor/30690
lock: 0xffff88804ff7b0e0, .magic: 00000000, .owner: /0, .owner_cpu: 1341632736
CPU: 1 UID: 0 PID: 30690 Comm: syz-executor Tainted: G L 7.4.0-rc3 #1 PREEMPT(full)
Tainted: [L]=SOFTLOCKUP
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:120
debug_spin_lock_before kernel/locking/spinlock_debug.c:86 [inline]
do_raw_spin_lock+0x1f7/0x270 kernel/locking/spinlock_debug.c:115
__raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:156 [inline]
_raw_spin_lock_irqsave+0x42/0x60 kernel/locking/spinlock.c:181
ifs_clear_range_dirty+0x1d7/0x250 fs/iomap/buffered-io.c:203
iomap_clear_range_dirty fs/iomap/buffered-io.c:214 [inline]
iomap_writeback_folio+0xd93/0x1de0 fs/iomap/buffered-io.c:2045
iomap_writepages+0x138/0x2a0 fs/iomap/buffered-io.c:2089
gfs2_writepages+0x165/0x2a0 fs/gfs2/aops.c:175
do_writepages+0x27a/0x600 mm/page-writeback.c:2562
filemap_writeback+0x225/0x2d0 mm/filemap.c:386
gfs2_ordered_write fs/gfs2/log.c:730 [inline]
__gfs2_log_flush+0x4cf/0x21f0 fs/gfs2/log.c:1135
gfs2_log_flush+0x35/0x50 fs/gfs2/log.c:1217
do_sync+0x55f/0xd30 fs/gfs2/quota.c:1000
gfs2_quota_sync+0x322/0x570 fs/gfs2/quota.c:1378
gfs2_sync_fs+0x44/0xb0 fs/gfs2/super.c:664
sync_filesystem fs/sync.c:56 [inline]
sync_filesystem+0x117/0x290 fs/sync.c:30
generic_shutdown_super+0x82/0x3a0 fs/super.c:702
kill_block_super+0x43/0x130 fs/super.c:1852
gfs2_kill_sb+0x4a6/0x580 fs/gfs2/ops_fstype.c:1796
deactivate_locked_super+0xbd/0x130 fs/super.c:558
deactivate_super fs/super.c:586 [inline]
deactivate_super+0xe1/0x110 fs/super.c:582
cleanup_mnt+0xb7/0x160 fs/namespace.c:1396
task_work_run+0x150/0x240 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+0x24c/0x810 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+0x677/0x800 arch/x86/entry/syscall_64.c:107
entry_SYSCALL_64_after_hwframe+0x77/0x7f
</TASK>
We also verified the same crash on an untainted 7.4.0-rc3 kernel with the
standalone C reproducer:
BUG: spinlock bad magic on CPU#1, gfs2_1591/26353
lock: 0xffff8880631c7620, .magic: 00000000, .owner: /0, .owner_cpu: 1662809632
CPU: 1 UID: 0 PID: 26353 Comm: gfs2_1591 Not tainted 7.4.0-rc3 #1 PREEMPT(full)
Reproducer & Config
===================
The C reproducer (gfs2_1591.c), syzkaller program (gfs2_1591.prog), and
kernel .config are available at:
https://gist.github.com/ilidanZtormrage/beffb7a9573d7d0873f06a99dc2cde64
Best regards,
Xinyuan Zhao