possible deadlock in vfs_iocb_iter_write

Status: moderation: reported on 2026/11/16 13:53
Subsystems: netfs
Labels: prio:low
[Documentation on labels]
Reported-by: syzbot+c953eaac709eb23ecf60@syzkaller.appspotmail.com
First crash: 1h52m, last: 1h52m
✨ AI-generated root cause summary:

In security/integrity/ima/ima_iint.c, ima_iint_lockdep_annotate() assigns iint->mutex to a static lockdep class array ima_iint_mutex_key[IMA_MAX_NESTING] indexed solely by inode->i_sb->s_stack_depth. When a network filesystem using netfs/fscache (such as 9p) caches data on a local backing filesystem (such as XFS via cachefiles), both filesystems have s_stack_depth == 0, causing their iint->mutex instances to share the same lockdep key ima_iint_mutex_key[0]. This collapses distinct locking tiers into one class, causing lockdep to flag a false circular locking dependency among sb_writers (acquired during do_open(O_TRUNC)), ima_iint_mutex_key[0], and inode->i_rwsem (acquired during netfs_buffered_read_iter() when IMA measures a file).

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

Technical Analysis of the Root Cause

1. Overview and Key Components

The reported issue is a lockdep warning (WARNING: possible circular locking dependency detected) involving three lock classes:

  • sb_writers#12 (the superblock freeze/write protection lock for the local cache backing filesystem, e.g., XFS)
  • &sb->s_type->i_mutex_key#25 (the inode->i_rwsem lock for 9p network filesystem inodes)
  • &ima_iint_mutex_key[depth] (the IMA integrity inode cache mutex iint->mutex)

The key files and functions involved are:


2. Root Cause Mechanism

In the kernel, VFS separates lock classes per struct file_system_type for inode locks (sb->s_type->i_mutex_key) and superblock freeze locks (sb->s_type->s_writers_key[]), enabling lockdep to distinguish between lock instances belonging to different filesystem types (e.g., a network filesystem on top of a local cache backing filesystem).

However, in security/integrity/ima/ima_iint.c, IMA annotates iint->mutex using a static array indexed solely by inode->i_sb->s_stack_depth:

static inline void ima_iint_lockdep_annotate(struct ima_iint_cache *iint,
					     struct inode *inode)
{
#ifdef CONFIG_LOCKDEP
	static struct lock_class_key ima_iint_mutex_key[IMA_MAX_NESTING];

	int depth = inode->i_sb->s_stack_depth;

	if (WARN_ON_ONCE(depth < 0 || depth >= IMA_MAX_NESTING))
		depth = 0;

	lockdep_set_class(&iint->mutex, &ima_iint_mutex_key[depth]);
#endif
}

While overlayfs increments s_stack_depth for stacked mounts, network filesystems (such as 9p) and local cache filesystems (such as XFS providing backing storage for cachefiles) both have inode->i_sb->s_stack_depth == 0. As a result:

  • Both 9p inodes and XFS inodes share the exact same lockdep key: ima_iint_mutex_key[0].

3. How the False Circular Dependency is Established

Lockdep constructed the circular dependency graph through the following interactions:

  1. Dependency #1 (XFS sb_writers#12 -> ima_iint_mutex_key[0]): When opening a file on the local filesystem (XFS) with O_TRUNC, do_open() (fs/namei.c:4838-4853) calls mnt_want_write() before calling security_file_post_open().

    • mnt_want_write() acquires sb_writers on XFS (sb_writers#12).
    • security_file_post_open() calls ima_file_check() -> process_measurement(), which locks iint->mutex (ima_iint_mutex_key[0]) on the XFS inode.
    • Lockdep records: sb_writers#12 -> ima_iint_mutex_key[0].
  2. Dependency #2 (ima_iint_mutex_key[0] -> 9p i_mutex_key#25): When measuring a file on the network filesystem (9p), process_measurement() (security/integrity/ima/ima_main.c:319) holds iint->mutex (ima_iint_mutex_key[0]) and calls ima_collect_measurement() (line 425).

    • ima_collect_measurement() reads file contents via __kernel_read() -> file->f_op->read_iter().
    • On 9p (using netfs), this invokes netfs_buffered_read_iter() -> netfs_start_io_read() (fs/netfs/locking.c:67), which acquires down_read_interruptible(&inode->i_rwsem) (i_mutex_key#25).
    • Lockdep records: ima_iint_mutex_key[0] -> 9p i_mutex_key#25.
  3. Current execution path (9p i_mutex_key#25 -> XFS sb_writers#12): In syz.0.0, a file on 9p is truncated (do_truncate() in fs/open.c:63-68), holding 9p's inode->i_rwsem (i_mutex_key#25).

    • v9fs_vfs_setattr_dotl() flushes dirty pages via filemap_fdatawrite().
    • netfs_writepages() writes back through cachefiles (fs/cachefiles/io.c:355).
    • __cachefiles_write() calls vfs_iocb_iter_write() (fs/read_write.c:929) on the backing file on XFS, which invokes kiocb_start_write() (include/linux/fs.h:2799) -> sb_start_write() (sb_writers#12).

Because ima_iint_lockdep_annotate() collapsed XFS iint->mutex and 9p iint->mutex into ima_iint_mutex_key[0], lockdep treats the two distinct locks as identical, forming an apparent circular dependency:

sb_writers#12 (XFS) -> ima_iint_mutex_key[0] -> i_mutex_key#25 (9p) -> sb_writers#12 (XFS)

In reality, the runtime acquisition order across distinct lock instances is strictly top-down and unidirectional:

9p sb_writers#13 -> 9p iint->mutex -> 9p inode->i_rwsem -> XFS sb_writers#12 -> XFS iint->mutex -> XFS inode->i_rwsem

Thus, no real deadlock can occur; the warning is a lockdep class aliasing false positive caused by ima_iint_lockdep_annotate() not differentiating between distinct filesystem types that share s_stack_depth == 0.

▶ ▼ ✨ AI Jobs (1)
ID Workflow Result Correct Bug Created Started Finished Revision
57591888 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ possible deadlock in vfs_iocb_iter_write 2026/11/16 13:00 2026/11/16 13:01 2026/11/16 13:45 819ebe34

Sample crash report:
loop0: detected capacity change from 0 to 32768
=======================================================
WARNING: The mand mount option has been deprecated and
         and is ignored by this kernel. Remove the mand
         option from the mount to silence this warning.
=======================================================
XFS (loop0): Mounting V5 Filesystem bfdc47fc-10d8-4eed-a562-11a831b3f791
XFS (loop0): Ending clean mount
XFS (loop0): Quotacheck needed: Please wait.
XFS (loop0): Quotacheck: Done.

======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Not tainted
------------------------------------------------------
syz.0.0/5351 is trying to acquire lock:
ffff88804421c478 (sb_writers#12){.+.+}-{0:0}, at: kiocb_start_write include/linux/fs.h:2799 [inline]
ffff88804421c478 (sb_writers#12){.+.+}-{0:0}, at: vfs_iocb_iter_write+0x1cb/0x5e0 fs/read_write.c:929

but task is already holding lock:
ffff888047183c00 (&sb->s_type->i_mutex_key#25){++++}-{4:4}, at: inode_lock_killable include/linux/fs.h:1032 [inline]
ffff888047183c00 (&sb->s_type->i_mutex_key#25){++++}-{4:4}, at: do_truncate+0x18f/0x250 fs/open.c:63

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #2 (&sb->s_type->i_mutex_key#25){++++}-{4:4}:
       down_read_interruptible+0x4b/0x3b0 kernel/locking/rwsem.c:1584
       netfs_start_io_read+0x25/0x180 fs/netfs/locking.c:67
       netfs_buffered_read_iter+0xd6/0x160 fs/netfs/buffered_read.c:940
       __kernel_read+0x4ca/0x960 fs/read_write.c:512
       integrity_kernel_read+0x89/0xd0 security/integrity/iint.c:28
       ima_calc_file_hash_tfm security/integrity/ima/ima_crypto.c:222 [inline]
       ima_calc_file_hash+0x451/0x890 security/integrity/ima/ima_crypto.c:280
       ima_collect_measurement+0x51b/0xa00 security/integrity/ima/ima_api.c:300
       process_measurement+0x1272/0x1c10 security/integrity/ima/ima_main.c:425
       ima_file_check+0xdc/0x130 security/integrity/ima/ima_main.c:686
       security_file_post_open+0xb3/0x260 security/security.c:2777
       do_open fs/namei.c:4853 [inline]
       path_openat+0x1748/0x20f0 fs/namei.c:5016
       do_file_open+0x23e/0x4a0 fs/namei.c:5045
       do_sys_openat2+0x115/0x200 fs/open.c:1443
       do_sys_open fs/open.c:1449 [inline]
       __do_sys_openat fs/open.c:1465 [inline]
       __se_sys_openat fs/open.c:1460 [inline]
       __x64_sys_openat+0x138/0x170 fs/open.c:1460
       do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
       do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #1 (&ima_iint_mutex_key[depth]){+.+.}-{4:4}:
       __mutex_lock_common kernel/locking/mutex.c:646 [inline]
       __mutex_lock+0x197/0x15a0 kernel/locking/mutex.c:821
       process_measurement+0x7d0/0x1c10 security/integrity/ima/ima_main.c:319
       ima_file_check+0xdc/0x130 security/integrity/ima/ima_main.c:686
       security_file_post_open+0xb3/0x260 security/security.c:2777
       do_open fs/namei.c:4853 [inline]
       path_openat+0x1748/0x20f0 fs/namei.c:5016
       do_file_open+0x23e/0x4a0 fs/namei.c:5045
       do_sys_openat2+0x115/0x200 fs/open.c:1443
       do_sys_open fs/open.c:1449 [inline]
       __do_sys_openat fs/open.c:1465 [inline]
       __se_sys_openat fs/open.c:1460 [inline]
       __x64_sys_openat+0x138/0x170 fs/open.c:1460
       do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
       do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #0 (sb_writers#12){.+.+}-{0:0}:
       check_prev_add kernel/locking/lockdep.c:3209 [inline]
       check_prevs_add kernel/locking/lockdep.c:3328 [inline]
       validate_chain kernel/locking/lockdep.c:3952 [inline]
       __lock_acquire+0x164c/0x2de0 kernel/locking/lockdep.c:5288
       lock_acquire+0x115/0x350 kernel/locking/lockdep.c:5942
       percpu_down_read_internal include/linux/percpu-rwsem.h:53 [inline]
       percpu_down_read_freezable include/linux/percpu-rwsem.h:83 [inline]
       __sb_start_write include/linux/fs/super.h:19 [inline]
       sb_start_write+0x48/0x1c0 include/linux/fs/super.h:125
       kiocb_start_write include/linux/fs.h:2799 [inline]
       vfs_iocb_iter_write+0x1cb/0x5e0 fs/read_write.c:929
       __cachefiles_write+0x6c9/0xbd0 fs/cachefiles/io.c:355
       netfs_issue_write fs/netfs/write_issue.c:290 [inline]
       netfs_advance_write+0x328/0x4b0 fs/netfs/write_issue.c:331
       netfs_write_folio fs/netfs/write_issue.c:510 [inline]
       netfs_writepages+0x12d3/0x22b0 fs/netfs/write_issue.c:600
       do_writepages+0x338/0x560 mm/page-writeback.c:2562
       filemap_writeback mm/filemap.c:386 [inline]
       filemap_fdatawrite_range mm/filemap.c:411 [inline]
       filemap_fdatawrite+0x1e9/0x2f0 mm/filemap.c:417
       v9fs_vfs_setattr_dotl+0x4dc/0xab0 fs/9p/vfs_inode_dotl.c:585
       notify_change+0xbba/0xea0 fs/attr.c:556
       do_truncate+0x1c2/0x250 fs/open.c:68
       handle_truncate fs/namei.c:4306 [inline]
       do_open fs/namei.c:4855 [inline]
       path_openat+0x18a6/0x20f0 fs/namei.c:5016
       do_file_open+0x23e/0x4a0 fs/namei.c:5045
       do_sys_openat2+0x115/0x200 fs/open.c:1443
       do_sys_open fs/open.c:1449 [inline]
       __do_sys_openat fs/open.c:1465 [inline]
       __se_sys_openat fs/open.c:1460 [inline]
       __x64_sys_openat+0x138/0x170 fs/open.c:1460
       do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
       do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

other info that might help us debug this:

Chain exists of:
  sb_writers#12 --> &ima_iint_mutex_key[depth] --> &sb->s_type->i_mutex_key#25

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&sb->s_type->i_mutex_key#25);
                               lock(&ima_iint_mutex_key[depth]);
                               lock(&sb->s_type->i_mutex_key#25);
  rlock(sb_writers#12);

 *** DEADLOCK ***

locks held by syz.0.0/5351: 2, on CPU#0:
 #0: ffff888042230478 (sb_writers#13){.+.+}-{0:0}, at: mnt_want_write+0x41/0x90 fs/namespace.c:531
 #1: ffff888047183c00 (&sb->s_type->i_mutex_key#25){++++}-{4:4}, at: inode_lock_killable include/linux/fs.h:1032 [inline]
 #1: ffff888047183c00 (&sb->s_type->i_mutex_key#25){++++}-{4:4}, at: do_truncate+0x18f/0x250 fs/open.c:63

stack backtrace:
CPU: 0 UID: 0 PID: 5351 Comm: syz.0.0 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
 <TASK>
 dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
 print_circular_bug+0x2e2/0x300 kernel/locking/lockdep.c:2087
 check_noncircular+0x12f/0x150 kernel/locking/lockdep.c:2219
 check_prev_add kernel/locking/lockdep.c:3209 [inline]
 check_prevs_add kernel/locking/lockdep.c:3328 [inline]
 validate_chain kernel/locking/lockdep.c:3952 [inline]
 __lock_acquire+0x164c/0x2de0 kernel/locking/lockdep.c:5288
 lock_acquire+0x115/0x350 kernel/locking/lockdep.c:5942
 percpu_down_read_internal include/linux/percpu-rwsem.h:53 [inline]
 percpu_down_read_freezable include/linux/percpu-rwsem.h:83 [inline]
 __sb_start_write include/linux/fs/super.h:19 [inline]
 sb_start_write+0x48/0x1c0 include/linux/fs/super.h:125
 kiocb_start_write include/linux/fs.h:2799 [inline]
 vfs_iocb_iter_write+0x1cb/0x5e0 fs/read_write.c:929
 __cachefiles_write+0x6c9/0xbd0 fs/cachefiles/io.c:355
 netfs_issue_write fs/netfs/write_issue.c:290 [inline]
 netfs_advance_write+0x328/0x4b0 fs/netfs/write_issue.c:331
 netfs_write_folio fs/netfs/write_issue.c:510 [inline]
 netfs_writepages+0x12d3/0x22b0 fs/netfs/write_issue.c:600
 do_writepages+0x338/0x560 mm/page-writeback.c:2562
 filemap_writeback mm/filemap.c:386 [inline]
 filemap_fdatawrite_range mm/filemap.c:411 [inline]
 filemap_fdatawrite+0x1e9/0x2f0 mm/filemap.c:417
 v9fs_vfs_setattr_dotl+0x4dc/0xab0 fs/9p/vfs_inode_dotl.c:585
 notify_change+0xbba/0xea0 fs/attr.c:556
 do_truncate+0x1c2/0x250 fs/open.c:68
 handle_truncate fs/namei.c:4306 [inline]
 do_open fs/namei.c:4855 [inline]
 path_openat+0x18a6/0x20f0 fs/namei.c:5016
 do_file_open+0x23e/0x4a0 fs/namei.c:5045
 do_sys_openat2+0x115/0x200 fs/open.c:1443
 do_sys_open fs/open.c:1449 [inline]
 __do_sys_openat fs/open.c:1465 [inline]
 __se_sys_openat fs/open.c:1460 [inline]
 __x64_sys_openat+0x138/0x170 fs/open.c:1460
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fae7e7a94d9
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fae7f5b4fe8 EFLAGS: 00000246 ORIG_RAX: 0000000000000101
RAX: ffffffffffffffda RBX: 00007fae7ea25fa0 RCX: 00007fae7e7a94d9
RDX: 0000000000000300 RSI: 000020000001cac0 RDI: 0000000000000009
RBP: 00007fae7e83804e R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fae7ea26038 R14: 00007fae7ea25fa0 R15: 00007ffedf7b33b8
 </TASK>

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/16 13:01 upstream aebb72744764 31830773 .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root possible deadlock in vfs_iocb_iter_write
2026/11/16 13:00 upstream aebb72744764 31830773 .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root possible deadlock in vfs_iocb_iter_write
2026/11/16 13:00 upstream aebb72744764 31830773 .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root possible deadlock in vfs_iocb_iter_write
* Struck through repros no longer work on HEAD.