possible deadlock in __cachefiles_write

Status: moderation: reported on 2026/11/13 21:12
Subsystems: v9fs
Labels: prio:low
[Documentation on labels]
Reported-by: syzbot+dbdfd9783aa9519b66d0@syzkaller.appspotmail.com
First crash: 1h41m, last: 1h41m
✨ AI-generated root cause summary:

A false-positive circular locking dependency is reported by lockdep between the backing filesystem's freeze protection lock (sb_writers), the IMA integrity cache mutex (&ima_iint_mutex_key[depth]), and the upper network filesystem inode lock (&sb->s_type->i_mutex_key). In do_open() with O_TRUNC, mnt_want_write() is held across security_file_post_open(), establishing sb_writers -> ima_iint_mutex. During IMA file measurement on 9p, integrity_kernel_read() takes 9p's i_rwsem, establishing ima_iint_mutex -> 9p i_rwsem. Finally, truncating a 9p file (do_truncate()) flushes dirty pages through netfs_writepages() to cachefiles, where __cachefiles_write() acquires sb_writers on the local backing filesystem. Because neither 9p nor the local backing filesystem increments s_stack_depth, their distinct per-inode iint->mutex instances share lockdep class &ima_iint_mutex_key[0], producing a spurious circular dependency report even though the actual lock objects differ and cannot deadlock.

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

Root Cause Technical Analysis

1. Overview and Key Entities

The reported defect is a lockdep circular locking dependency warning involving three distinct locking layers:

  1. sb_writers (specifically SB_FREEZE_WRITE, acquired via sb_start_write() / mnt_want_write() / kiocb_start_write()) on the local filesystem hosting the cachefiles cache (fs/cachefiles/io.c, fs/namei.c, include/linux/fs.h).
  2. iint->mutex (struct ima_iint_cache::mutex, annotated with lockdep key &ima_iint_mutex_key[depth]) in the Integrity Measurement Architecture (IMA) subsystem (security/integrity/ima/ima_iint.c, security/integrity/ima/ima_main.c).
  3. inode->i_rwsem (&sb->s_type->i_mutex_key#30) on a network filesystem inode (v9fs / fs/9p/vfs_file.c, fs/netfs/locking.c, fs/open.c).

2. Detailed Locking Chain Breakdown

Chain #1: sb_writers -> &ima_iint_mutex_key[depth]

In fs/namei.c:do_open():

	} else if (d_is_reg(nd->path.dentry) && open_flag & O_TRUNC) {
		error = mnt_want_write(nd->path.mnt);
		if (error)
			return error;
		mnt = mntget(nd->path.mnt);
		do_truncate = true;
	}
	error = may_open(idmap, &nd->path, acc_mode, open_flag);
	if (!error && !(file->f_mode & FMODE_OPENED))
		error = vfs_open_consume(&nd->path, file);
	if (!error)
		error = security_file_post_open(file, op->acc_mode);

When opening an existing file with O_TRUNC on the local filesystem (where cachefiles caches data, superblock #5), do_open() calls mnt_want_write(), which acquires sb_start_write(sb) (sb_writers#5). While holding this write freeze protection lock, do_open() invokes security_file_post_open(), which calls ima_file_check() -> process_measurement(), acquiring iint->mutex for that local inode. Lockdep records the dependency: $$\text{sb_writers#5} \longrightarrow \text{&ima_iint_mutex_key[depth]}$$

Chain #2: &ima_iint_mutex_key[depth] -> &sb->s_type->i_mutex_key#30

When a file is opened on v9fs (9p network filesystem, superblock #15), do_open() calls security_file_post_open() -> ima_file_check() -> process_measurement(), which locks iint->mutex for the 9p inode. To measure the file content: process_measurement() $\to$ ima_collect_measurement() $\to$ ima_calc_file_hash() $\to$ __kernel_read() $\to$ v9fs_file_read_iter() $\to$ netfs_file_read_iter() $\to$ netfs_buffered_read_iter() $\to$ netfs_start_io_read().

netfs_start_io_read() acquires inode_lock_shared(inode) (&sb->s_type->i_mutex_key#30) on the 9p inode. Lockdep records the dependency: $$\text{&ima_iint_mutex_key[depth]} \longrightarrow \text{&sb->s_type->i_mutex_key#30}$$

Chain #0: &sb->s_type->i_mutex_key#30 -> sb_writers#5

When a 9p file is opened with O_TRUNC, do_open() calls handle_truncate() $\to$ do_truncate(). do_truncate() locks the 9p inode exclusively via inode_lock_killable() (&sb->s_type->i_mutex_key#30) and calls notify_change() $\to$ v9fs_vfs_setattr().

In v9fs_vfs_setattr() (fs/9p/vfs_inode.c:1087):

	if (d_is_reg(dentry)) {
		retval = filemap_fdatawrite(inode->i_mapping);
...

Flushing dirty page cache before truncation triggers: filemap_fdatawrite() $\to$ filemap_writeback() $\to$ do_writepages() $\to$ netfs_writepages() $\to$ netfs_write_folio() $\to$ netfs_advance_write() $\to$ netfs_do_issue_write() $\to$ cachefiles_issue_write() $\to$ cachefiles_write() $\to$ __cachefiles_write().

In fs/cachefiles/io.c:355:

	ret = vfs_iocb_iter_write(file, &ki->iocb, iter);

vfs_iocb_iter_write() (fs/read_write.c:929) calls kiocb_start_write(iocb), which calls sb_start_write(file_inode(file)->i_sb) on the local backing filesystem (sb_writers#5) to ensure freeze protection while writing to the cache file. Lockdep observes: $$\text{&sb->s_type->i_mutex_key#30} \longrightarrow \text{sb_writers#5}$$

This completes the apparent circular dependency: $$\text{sb_writers#5} \longrightarrow \text{&ima_iint_mutex_key[depth]} \longrightarrow \text{&sb->s_type->i_mutex_key#30} \longrightarrow \text{sb_writers#5}$$

3. Root Cause: Lockdep Class Conflation and Stack Depth Annotations

In security/integrity/ima/ima_iint.c:

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
}
  1. Inode stacking depth (sb->s_stack_depth) was implemented to distinguish nesting levels across stacked filesystems (such as overlayfs and ecryptfs), preventing false-positive lockdep reports when IMA measures files on both the upper and lower filesystems.
  2. Neither v9fs (nor other network filesystems using netfs / fscache) nor standard local backing filesystems (e.g., ext4, xfs, tmpfs) increment s_stack_depth. Consequently, both superblocks have s_stack_depth == 0.
  3. Lockdep therefore assigns &ima_iint_mutex_key[0] to both the local cache file's iint->mutex and the 9p file's iint->mutex.
  4. While do_open() holds mnt_want_write() across security_file_post_open(), the local file's iint->mutex and the 9p file's iint->mutex are completely distinct mutex instances residing in separate struct ima_iint_cache structures. The local filesystem never invokes operations on 9p, so no actual runtime cycle exists between lock instances.
▶ ▼ ✨ AI Jobs (1)
ID Workflow Result Correct Bug Created Started Finished Revision
5c5f8a5d assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ possible deadlock in __cachefiles_write 2026/11/13 20:17 2026/11/13 20:17 2026/11/13 21:03 819ebe34

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Tainted: G             L     
------------------------------------------------------
syz.7.1192/10055 is trying to acquire lock:
ffff88802d3a6478 (sb_writers#5){.+.+}-{0:0}, at: __cachefiles_write+0x56f/0xd40 fs/cachefiles/io.c:355

but task is already holding lock:
ffff88810b968140 (&sb->s_type->i_mutex_key#30){++++}-{4:4}, at: inode_lock_killable include/linux/fs.h:1032 [inline]
ffff88810b968140 (&sb->s_type->i_mutex_key#30){++++}-{4:4}, at: do_truncate+0x14e/0x240 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#30){++++}-{4:4}:
       lock_acquire kernel/locking/lockdep.c:5942 [inline]
       lock_acquire+0x1d1/0x380 kernel/locking/lockdep.c:5899
       down_read_interruptible+0x97/0x520 kernel/locking/rwsem.c:1584
       netfs_start_io_read+0x1f/0x100 fs/netfs/locking.c:67
       netfs_buffered_read_iter+0xf3/0x190 fs/netfs/buffered_read.c:940
       netfs_file_read_iter+0x10f/0x190 fs/netfs/buffered_read.c:978
       v9fs_file_read_iter+0x9b/0x100 fs/9p/vfs_file.c:369
       __kernel_read+0x397/0xac0 fs/read_write.c:512
       integrity_kernel_read+0x7e/0xb0 security/integrity/iint.c:28
       ima_calc_file_hash_tfm+0x25e/0x350 security/integrity/ima/ima_crypto.c:222
       ima_calc_file_hash+0x1e3/0x380 security/integrity/ima/ima_crypto.c:280
       ima_collect_measurement+0x952/0xb30 security/integrity/ima/ima_api.c:300
       process_measurement+0xe04/0x2360 security/integrity/ima/ima_main.c:425
       ima_file_check+0xbf/0x110 security/integrity/ima/ima_main.c:686
       security_file_post_open+0xc4/0x210 security/security.c:2777
       do_open fs/namei.c:4853 [inline]
       path_openat+0x5d0/0x23f0 fs/namei.c:5016
       do_file_open+0x20e/0x430 fs/namei.c:5045
       do_sys_openat2+0x163/0x1d0 fs/open.c:1443
       do_sys_open fs/open.c:1449 [inline]
       __do_sys_open fs/open.c:1457 [inline]
       __se_sys_open fs/open.c:1453 [inline]
       __x64_sys_open+0xfe/0x1d0 fs/open.c:1453
       do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
       do_syscall_64+0x123/0x7b0 arch/x86/entry/syscall_64.c:89
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #1 (&ima_iint_mutex_key[depth]){+.+.}-{4:4}:
       lock_acquire kernel/locking/lockdep.c:5942 [inline]
       lock_acquire+0x1d1/0x380 kernel/locking/lockdep.c:5899
       __mutex_lock_common kernel/locking/mutex.c:646 [inline]
       __mutex_lock+0x19f/0x1c10 kernel/locking/mutex.c:821
       process_measurement+0x5ab/0x2360 security/integrity/ima/ima_main.c:319
       ima_file_check+0xbf/0x110 security/integrity/ima/ima_main.c:686
       security_file_post_open+0xc4/0x210 security/security.c:2777
       do_open fs/namei.c:4853 [inline]
       path_openat+0x5d0/0x23f0 fs/namei.c:5016
       do_file_open+0x20e/0x430 fs/namei.c:5045
       do_sys_openat2+0x163/0x1d0 fs/open.c:1443
       do_sys_open fs/open.c:1449 [inline]
       __do_sys_open fs/open.c:1457 [inline]
       __se_sys_open fs/open.c:1453 [inline]
       __x64_sys_open+0xfe/0x1d0 fs/open.c:1453
       do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
       do_syscall_64+0x123/0x7b0 arch/x86/entry/syscall_64.c:89
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #0 (sb_writers#5){.+.+}-{0:0}:
       check_prev_add+0xeb/0xe60 kernel/locking/lockdep.c:3209
       check_prevs_add kernel/locking/lockdep.c:3328 [inline]
       validate_chain kernel/locking/lockdep.c:3952 [inline]
       __lock_acquire+0x1528/0x1f40 kernel/locking/lockdep.c:5288
       lock_acquire kernel/locking/lockdep.c:5942 [inline]
       lock_acquire+0x1d1/0x380 kernel/locking/lockdep.c:5899
       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 include/linux/fs/super.h:125 [inline]
       kiocb_start_write include/linux/fs.h:2799 [inline]
       vfs_iocb_iter_write+0x1fe/0xa50 fs/read_write.c:929
       __cachefiles_write+0x56f/0xd40 fs/cachefiles/io.c:355
       cachefiles_write+0xc2/0x150 fs/cachefiles/io.c:395
       cachefiles_issue_write+0x513/0x810 fs/cachefiles/io.c:607
       netfs_do_issue_write+0xee/0x340 fs/netfs/write_issue.c:256
       netfs_issue_write fs/netfs/write_issue.c:290 [inline]
       netfs_advance_write fs/netfs/write_issue.c:331 [inline]
       netfs_advance_write+0x37e/0x4c0 fs/netfs/write_issue.c:299
       netfs_write_folio fs/netfs/write_issue.c:510 [inline]
       netfs_writepages+0x10bb/0x2390 fs/netfs/write_issue.c:600
       do_writepages+0x278/0x600 mm/page-writeback.c:2562
       filemap_writeback+0x22d/0x2e0 mm/filemap.c:386
       v9fs_vfs_setattr+0x9d6/0xb80 fs/9p/vfs_inode.c:1087
       notify_change+0xb09/0x1350 fs/attr.c:556
       do_truncate+0x1df/0x240 fs/open.c:68
       handle_truncate fs/namei.c:4306 [inline]
       do_open fs/namei.c:4855 [inline]
       path_openat+0x1e93/0x23f0 fs/namei.c:5016
       do_file_open+0x20e/0x430 fs/namei.c:5045
       do_sys_openat2+0x163/0x1d0 fs/open.c:1443
       do_sys_open fs/open.c:1449 [inline]
       __do_sys_open fs/open.c:1457 [inline]
       __se_sys_open fs/open.c:1453 [inline]
       __x64_sys_open+0xfe/0x1d0 fs/open.c:1453
       do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
       do_syscall_64+0x123/0x7b0 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#5 --> &ima_iint_mutex_key[depth] --> &sb->s_type->i_mutex_key#30

 Possible unsafe locking scenario:

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

 *** DEADLOCK ***

locks held by syz.7.1192/10055: 2, on CPU#0:
 #0: ffff88802ed0c478 (sb_writers#15){.+.+}-{0:0}, at: do_open fs/namei.c:4838 [inline]
 #0: ffff88802ed0c478 (sb_writers#15){.+.+}-{0:0}, at: path_openat+0x1920/0x23f0 fs/namei.c:5016
 #1: ffff88810b968140 (&sb->s_type->i_mutex_key#30){++++}-{4:4}, at: inode_lock_killable include/linux/fs.h:1032 [inline]
 #1: ffff88810b968140 (&sb->s_type->i_mutex_key#30){++++}-{4:4}, at: do_truncate+0x14e/0x240 fs/open.c:63

stack backtrace:
CPU: 0 UID: 0 PID: 10055 Comm: syz.7.1192 Tainted: G             L      syzkaller #0 PREEMPT(full) 
Tainted: [L]=SOFTLOCKUP
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 lib/dump_stack.c:94 [inline]
 dump_stack_lvl+0x100/0x190 lib/dump_stack.c:120
 print_circular_bug.cold+0x178/0x1be kernel/locking/lockdep.c:2087
 check_noncircular+0x146/0x160 kernel/locking/lockdep.c:2219
 check_prev_add+0xeb/0xe60 kernel/locking/lockdep.c:3209
 check_prevs_add kernel/locking/lockdep.c:3328 [inline]
 validate_chain kernel/locking/lockdep.c:3952 [inline]
 __lock_acquire+0x1528/0x1f40 kernel/locking/lockdep.c:5288
 lock_acquire kernel/locking/lockdep.c:5942 [inline]
 lock_acquire+0x1d1/0x380 kernel/locking/lockdep.c:5899
 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 include/linux/fs/super.h:125 [inline]
 kiocb_start_write include/linux/fs.h:2799 [inline]
 vfs_iocb_iter_write+0x1fe/0xa50 fs/read_write.c:929
 __cachefiles_write+0x56f/0xd40 fs/cachefiles/io.c:355
 cachefiles_write+0xc2/0x150 fs/cachefiles/io.c:395
 cachefiles_issue_write+0x513/0x810 fs/cachefiles/io.c:607
 netfs_do_issue_write+0xee/0x340 fs/netfs/write_issue.c:256
 netfs_issue_write fs/netfs/write_issue.c:290 [inline]
 netfs_advance_write fs/netfs/write_issue.c:331 [inline]
 netfs_advance_write+0x37e/0x4c0 fs/netfs/write_issue.c:299
 netfs_write_folio fs/netfs/write_issue.c:510 [inline]
 netfs_writepages+0x10bb/0x2390 fs/netfs/write_issue.c:600
 do_writepages+0x278/0x600 mm/page-writeback.c:2562
 filemap_writeback+0x22d/0x2e0 mm/filemap.c:386
 v9fs_vfs_setattr+0x9d6/0xb80 fs/9p/vfs_inode.c:1087
 notify_change+0xb09/0x1350 fs/attr.c:556
 do_truncate+0x1df/0x240 fs/open.c:68
 handle_truncate fs/namei.c:4306 [inline]
 do_open fs/namei.c:4855 [inline]
 path_openat+0x1e93/0x23f0 fs/namei.c:5016
 do_file_open+0x20e/0x430 fs/namei.c:5045
 do_sys_openat2+0x163/0x1d0 fs/open.c:1443
 do_sys_open fs/open.c:1449 [inline]
 __do_sys_open fs/open.c:1457 [inline]
 __se_sys_open fs/open.c:1453 [inline]
 __x64_sys_open+0xfe/0x1d0 fs/open.c:1453
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x123/0x7b0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f4b4eba94d9
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:00007f4b4f9a7028 EFLAGS: 00000246 ORIG_RAX: 0000000000000002
RAX: ffffffffffffffda RBX: 00007f4b4ee25fa0 RCX: 00007f4b4eba94d9
RDX: 000000000000015b RSI: 00000000001e3342 RDI: 00002000000009c0
RBP: 00007f4b4ec3804e R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f4b4ee26038 R14: 00007f4b4ee25fa0 R15: 00007ffd7b80c5f8
 </TASK>

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/13 20:17 upstream 2800868f6322 0dd86ee6 .config console log report info [disk image (non-bootable)] [vmlinux] [kernel image] ci-qemu-upstream possible deadlock in __cachefiles_write
* Struck through repros no longer work on HEAD.