* [PATCH] ima: key iint mutex lockdep class per filesystem type
@ 2026-11-23 11:14 Nguyen Ngoc Thang
2026-11-23 11:20 ` sashiko-bot
2026-11-24 22:05 ` Mimi Zohar
0 siblings, 2 replies; 3+ messages in thread
From: Nguyen Ngoc Thang @ 2026-11-23 11:14 UTC (permalink / raw)
To: Mimi Zohar, Roberto Sassu
Cc: Dmitry Kasatkin, Eric Snowberg, Amir Goldstein, Alexander Viro,
Christian Brauner, Jan Kara, David Howells, Paulo Alcantara,
linux-integrity, linux-security-module, linux-fsdevel, netfs,
linux-kernel, syzbot+deb8af81d91415fabac1
syzbot reports a circular locking dependency between the iint mutex,
a 9p inode's i_rwsem and the sb_writers of the cachefiles backing fs:
sb_writers#12 --> &ima_iint_mutex_key[depth] --> &sb->s_type->i_mutex_key#25
The three edges are:
backing fs O_TRUNC open: sb_writers(backing) -> iint(backing inode)
9p open + IMA hash: iint(9p inode) -> i_rwsem(9p inode)
9p truncate/writeback: i_rwsem(9p inode) -> sb_writers(backing)
The last one is inherent to netfs: it writes to its cachefiles backing
file under its own inode lock. The cycle only closes because the iint
mutex is keyed by s_stack_depth alone, so the 9p and backing fs iints,
both at depth 0, share one lockdep class. They are different inodes
and nothing waits on a netfs iint while holding the backing fs's
sb_writers, so this is a false positive.
Key the iint mutex per filesystem type as well as depth, as is done for
i_rwsem with s_type->i_mutex_key. The overlayfs case covered by the
depth annotation is unchanged.
Fixes: e044374a8a0a ("ima: annotate iint mutex to avoid lockdep false positive warnings")
Reported-by: syzbot+deb8af81d91415fabac1@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=deb8af81d91415fabac1
Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
---
Tested in QEMU on v7.4-rc4 (syzbot config, ima_policy=tcb): cachefiles
bound on an ext4 disk, 9p over virtio with cache=fscache, then 50 rounds
of write + O_RDONLY|O_TRUNC open on 9p and on the backing fs, followed by
20 IMA-measured O_TRUNC opens through an overlayfs on the backing fs.
unpatched: "possible circular locking dependency detected", same chain
patched: no lockdep report, debug_locks still 1; the syzbot C repro
also ran 90s with no report
include/linux/fs.h | 3 +++
security/integrity/ima/ima_iint.c | 11 +++++++----
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 5b3a100aba77b..dab32eea21fc7 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2325,6 +2325,9 @@ struct file_system_type {
struct lock_class_key i_mutex_dir_key;
struct lock_class_key d_lookup_key;
+#ifdef CONFIG_IMA
+ struct lock_class_key ima_iint_key[FILESYSTEM_MAX_STACK_DEPTH + 1];
+#endif
};
#define MODULE_ALIAS_FS(NAME) MODULE_ALIAS("fs-" NAME)
diff --git a/security/integrity/ima/ima_iint.c b/security/integrity/ima/ima_iint.c
index 00b249101f98d..bb964847af149 100644
--- a/security/integrity/ima/ima_iint.c
+++ b/security/integrity/ima/ima_iint.c
@@ -39,19 +39,22 @@ struct ima_iint_cache *ima_iint_find(struct inode *inode)
* files both on overlayfs and on underlying fs, we need to annotate the iint
* mutex to avoid lockdep false positives related to IMA + overlayfs.
* See ovl_lockdep_annotate_inode_mutex_key() for more details.
+ *
+ * Depth alone is not enough: a netfs inode writes to its cachefiles backing
+ * fs under its own i_rwsem, and both are at depth 0. So, like i_rwsem, key
+ * the mutex per filesystem type too.
*/
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;
+ struct super_block *sb = inode->i_sb;
+ int depth = 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]);
+ lockdep_set_class(&iint->mutex, &sb->s_type->ima_iint_key[depth]);
#endif
}
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ima: key iint mutex lockdep class per filesystem type
2026-11-23 11:14 [PATCH] ima: key iint mutex lockdep class per filesystem type Nguyen Ngoc Thang
@ 2026-11-23 11:20 ` sashiko-bot
2026-11-24 22:05 ` Mimi Zohar
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-23 11:20 UTC (permalink / raw)
Cc: linux-security-module
> syzbot reports a circular locking dependency between the iint mutex,
> a 9p inode's i_rwsem and the sb_writers of the cachefiles backing fs:
>
> sb_writers#12 --> &ima_iint_mutex_key[depth] --> &sb->s_type->i_mutex_key#25
>
> The three edges are:
>
> backing fs O_TRUNC open: sb_writers(backing) -> iint(backing inode)
> 9p open + IMA hash: iint(9p inode) -> i_rwsem(9p inode)
> 9p truncate/writeback: i_rwsem(9p inode) -> sb_writers(backing)
>
> The last one is inherent to netfs: it writes to its cachefiles backing
> file under its own inode lock. The cycle only closes because the iint
> mutex is keyed by s_stack_depth alone, so the 9p and backing fs iints,
> both at depth 0, share one lockdep class. They are different inodes
> and nothing waits on a netfs iint while holding the backing fs's
> sb_writers, so this is a false positive.
>
> Key the iint mutex per filesystem type as well as depth, as is done for
> i_rwsem with s_type->i_mutex_key. The overlayfs case covered by the
> depth annotation is unchanged.
>
> Fixes: e044374a8a0a ("ima: annotate iint mutex to avoid lockdep false positive warnings")
> Reported-by: syzbot+deb8af81d91415fabac1@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=deb8af81d91415fabac1
> Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123111452.237422-1-ngocthang2710.1999@gmail.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ima: key iint mutex lockdep class per filesystem type
2026-11-23 11:14 [PATCH] ima: key iint mutex lockdep class per filesystem type Nguyen Ngoc Thang
2026-11-23 11:20 ` sashiko-bot
@ 2026-11-24 22:05 ` Mimi Zohar
1 sibling, 0 replies; 3+ messages in thread
From: Mimi Zohar @ 2026-11-24 22:05 UTC (permalink / raw)
To: Nguyen Ngoc Thang, Roberto Sassu
Cc: Dmitry Kasatkin, Eric Snowberg, Amir Goldstein, Alexander Viro,
Christian Brauner, Jan Kara, David Howells, Paulo Alcantara,
linux-integrity, linux-security-module, linux-fsdevel, netfs,
linux-kernel, syzbot+deb8af81d91415fabac1
On Mon, 2026-11-23 at 18:14 +0700, Nguyen Ngoc Thang wrote:
> syzbot reports a circular locking dependency between the iint mutex,
> a 9p inode's i_rwsem and the sb_writers of the cachefiles backing fs:
>
> sb_writers#12 --> &ima_iint_mutex_key[depth] --> &sb->s_type->i_mutex_key#25
>
> The three edges are:
>
> backing fs O_TRUNC open: sb_writers(backing) -> iint(backing inode)
> 9p open + IMA hash: iint(9p inode) -> i_rwsem(9p inode)
> 9p truncate/writeback: i_rwsem(9p inode) -> sb_writers(backing)
>
> The last one is inherent to netfs: it writes to its cachefiles backing
> file under its own inode lock. The cycle only closes because the iint
> mutex is keyed by s_stack_depth alone, so the 9p and backing fs iints,
> both at depth 0, share one lockdep class. They are different inodes
> and nothing waits on a netfs iint while holding the backing fs's
> sb_writers, so this is a false positive.
>
> Key the iint mutex per filesystem type as well as depth, as is done for
> i_rwsem with s_type->i_mutex_key. The overlayfs case covered by the
> depth annotation is unchanged.
>
> Fixes: e044374a8a0a ("ima: annotate iint mutex to avoid lockdep false positive warnings")
> Reported-by: syzbot+deb8af81d91415fabac1@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=deb8af81d91415fabac1
> Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
> ---
> Tested in QEMU on v7.4-rc4 (syzbot config, ima_policy=tcb): cachefiles
> bound on an ext4 disk, 9p over virtio with cache=fscache, then 50 rounds
> of write + O_RDONLY|O_TRUNC open on 9p and on the backing fs, followed by
> 20 IMA-measured O_TRUNC opens through an overlayfs on the backing fs.
>
> unpatched: "possible circular locking dependency detected", same chain
> patched: no lockdep report, debug_locks still 1; the syzbot C repro
> also ran 90s with no report
>
> include/linux/fs.h | 3 +++
> security/integrity/ima/ima_iint.c | 11 +++++++----
> 2 files changed, 10 insertions(+), 4 deletions(-)
Hi Nguyen,
Thanks for the patch. Keying the iint mutex per filesystem type, as is done for
i_rwsem, makes sense to break the 9p/cachefiles cycle.
One suggestion: instead of an array of lock_class_keys in struct
file_system_type, consider using lockdep_set_class_and_subclass() with a single
key and pass the stack depth as the subclass:
lockdep_set_class_and_subclass(&iint->mutex,
&sb->s_type->ima_iint_key, depth);
A lock_class_key already provides MAX_LOCKDEP_SUBCLASSES subkeys, so this gives
the same distinct classes (overlayfs is unaffected) without allocating
FILESYSTEM_MAX_STACK_DEPTH + 1 full keys per filesystem type, and it avoids
having the array size in fs.h and IMA_MAX_NESTING in ima_iint.c defined
independently. A BUILD_BUG_ON(IMA_MAX_NESTING > MAX_LOCKDEP_SUBCLASSES) would
keep the bound honest.
thanks,
Mimi
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 5b3a100aba77b..dab32eea21fc7 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -2325,6 +2325,9 @@ struct file_system_type {
> struct lock_class_key i_mutex_dir_key;
>
> struct lock_class_key d_lookup_key;
> +#ifdef CONFIG_IMA
> + struct lock_class_key ima_iint_key[FILESYSTEM_MAX_STACK_DEPTH + 1];
> +#endif
> };
>
> #define MODULE_ALIAS_FS(NAME) MODULE_ALIAS("fs-" NAME)
> diff --git a/security/integrity/ima/ima_iint.c b/security/integrity/ima/ima_iint.c
> index 00b249101f98d..bb964847af149 100644
> --- a/security/integrity/ima/ima_iint.c
> +++ b/security/integrity/ima/ima_iint.c
> @@ -39,19 +39,22 @@ struct ima_iint_cache *ima_iint_find(struct inode *inode)
> * files both on overlayfs and on underlying fs, we need to annotate the iint
> * mutex to avoid lockdep false positives related to IMA + overlayfs.
> * See ovl_lockdep_annotate_inode_mutex_key() for more details.
> + *
> + * Depth alone is not enough: a netfs inode writes to its cachefiles backing
> + * fs under its own i_rwsem, and both are at depth 0. So, like i_rwsem, key
> + * the mutex per filesystem type too.
> */
> 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;
> + struct super_block *sb = inode->i_sb;
> + int depth = 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]);
> + lockdep_set_class(&iint->mutex, &sb->s_type->ima_iint_key[depth]);
> #endif
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-24 22:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 11:14 [PATCH] ima: key iint mutex lockdep class per filesystem type Nguyen Ngoc Thang
2026-11-23 11:20 ` sashiko-bot
2026-11-24 22:05 ` Mimi Zohar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox