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:
-
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].
-
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.
-
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.