Linux Security Modules development
 help / color / mirror / Atom feed
From: Mimi Zohar <zohar@linux.ibm.com>
To: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>,
	Roberto Sassu <roberto.sassu@huawei.com>
Cc: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>,
	Eric Snowberg	 <eric.snowberg@oracle.com>,
	Amir Goldstein <amir73il@gmail.com>,
	Alexander Viro	 <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>, Jan Kara	 <jack@suse.cz>,
	David Howells <dhowells@redhat.com>,
	Paulo Alcantara	 <pc@manguebit.org>,
	linux-integrity@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, netfs@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	syzbot+deb8af81d91415fabac1@syzkaller.appspotmail.com
Subject: Re: [PATCH] ima: key iint mutex lockdep class per filesystem type
Date: Tue, 24 Nov 2026 17:05:14 -0500	[thread overview]
Message-ID: <0313398fef7c1bd62ce4c3b849d581bdf90274ae.camel@linux.ibm.com> (raw)
In-Reply-To: <20261123111452.237422-1-ngocthang2710.1999@gmail.com>

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
>  }
>  

      parent reply	other threads:[~2026-11-24 22:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0313398fef7c1bd62ce4c3b849d581bdf90274ae.camel@linux.ibm.com \
    --to=zohar@linux.ibm.com \
    --cc=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=eric.snowberg@oracle.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=netfs@lists.linux.dev \
    --cc=ngocthang2710.1999@gmail.com \
    --cc=pc@manguebit.org \
    --cc=roberto.sassu@huawei.com \
    --cc=syzbot+deb8af81d91415fabac1@syzkaller.appspotmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox