Linux Integrity Measurement development
 help / color / mirror / Atom feed
From: "syzbot" <syzbot@kernel.org>
To: syzkaller-bugs@googlegroups.com,
	Krystian Kaniewski <krystianmkaniewski@gmail.com>,
	"Christian Brauner" <brauner@kernel.org>,
	"Dmitry Kasatkin" <dmitry.kasatkin@gmail.com>,
	"James Morris" <jmorris@namei.org>,
	<linux-fsdevel@vger.kernel.org>,
	<linux-integrity@vger.kernel.org>,
	<linux-security-module@vger.kernel.org>,
	"Paul Moore" <paul@paul-moore.com>,
	"Roberto Sassu" <roberto.sassu@huawei.com>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	"Alexander Viro" <viro@zeniv.linux.org.uk>,
	"Mimi Zohar" <zohar@linux.ibm.com>
Cc: eric.snowberg@oracle.com, jack@suse.cz, syzbot@lists.linux.dev
Subject: [PATCH] ima: annotate iint->mutex per filesystem type and stacking depth
Date: Thu,  3 Dec 2026 12:19:58 +0000 (UTC)	[thread overview]
Message-ID: <4281b2df-1f40-4c78-ae36-c5f1b05df7ee@mail.kernel.org> (raw)

From: Krystian Kaniewski <krystianmkaniewski@gmail.com>

ima_iint_lockdep_annotate() currently assigns a global lockdep class
ima_iint_mutex_key[depth] indexed solely by inode->i_sb->s_stack_depth.
Consequently, all non-stacked filesystems (s_stack_depth == 0) share the
same lockdep class for iint->mutex, allowing lockdep to falsely bridge lock
dependencies across unrelated filesystems.

With a custom IMA FILE_CHECK policy measuring files across filesystems,
lockdep observes a false circular dependency cycle between overlayfs, ext4,
and sysfs: overlayfs directory creation links ovl_i_mutex_dir_key to ext4
sb_writers, opening an ext4 file with O_TRUNC links sb_writers to
ima_iint_mutex_key[0] in process_measurement(), opening /sys/power/resume
with O_RDWR links the same ima_iint_mutex_key[0] to kernfs of->mutex via
integrity_kernel_read(), and writing an overlayfs path to /sys/power/resume
acquires ovl_i_mutex_dir_key while holding of->mutex in resume_store().

Fix this by adding per-filesystem-type lockdep keys
i_ima_iint_key[FILESYSTEM_MAX_STACK_DEPTH + 1] (guarded by CONFIG_IMA) to
struct file_system_type and updating ima_iint_lockdep_annotate() to set the
class of iint->mutex to &sb->s_type->i_ima_iint_key[depth]. This isolates
iint->mutex across unrelated filesystems, breaks the false cycle between
ext4 and sysfs, and preserves distinct lockdep classes for each stacking
layer (including nested overlayfs and pseudo-filesystems with s_stack_depth
== FILESYSTEM_MAX_STACK_DEPTH).

Assisted-by: Gemini:gemini-4-hydrogen Gemini:gemini-3.8-flash syzbot
Reported-by: syzbot+da1d15f707a556f6e48c@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=da1d15f707a556f6e48c
Link: https://syzkaller.appspot.com/ai_job?id=f0feaef1-2d84-47cc-908f-143543aa7da9
Signed-off-by: Krystian Kaniewski <krystianmkaniewski@gmail.com>

---
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 5b3a100ab..8fd02c303 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2323,6 +2323,9 @@ struct file_system_type {
 	struct lock_class_key i_mutex_key;
 	struct lock_class_key invalidate_lock_key;
 	struct lock_class_key i_mutex_dir_key;
+#ifdef CONFIG_IMA
+	struct lock_class_key i_ima_iint_key[FILESYSTEM_MAX_STACK_DEPTH + 1];
+#endif
 
 	struct lock_class_key d_lookup_key;
 };
diff --git a/security/integrity/ima/ima_iint.c b/security/integrity/ima/ima_iint.c
index 00b249101..9372a2eec 100644
--- a/security/integrity/ima/ima_iint.c
+++ b/security/integrity/ima/ima_iint.c
@@ -32,26 +32,26 @@ struct ima_iint_cache *ima_iint_find(struct inode *inode)
 	return ima_inode_get_iint(inode);
 }
 
-#define IMA_MAX_NESTING (FILESYSTEM_MAX_STACK_DEPTH + 1)
-
 /*
- * It is not clear that IMA should be nested at all, but as long is it measures
- * 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.
+ * Annotate the iint mutex per filesystem type and stacking depth to avoid
+ * lockdep false positives across unrelated filesystems as well as between
+ * stacked filesystems (e.g. overlayfs, including nested overlayfs) and their
+ * underlying filesystems.
+ * See lockdep_annotate_inode_mutex_key() and
+ * ovl_lockdep_annotate_inode_mutex_key() for more details.
  */
 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;
+	struct file_system_type *type = sb->s_type;
+	int depth = sb->s_stack_depth;
 
-	if (WARN_ON_ONCE(depth < 0 || depth >= IMA_MAX_NESTING))
+	if (WARN_ON_ONCE(depth < 0 || depth > FILESYSTEM_MAX_STACK_DEPTH))
 		depth = 0;
 
-	lockdep_set_class(&iint->mutex, &ima_iint_mutex_key[depth]);
+	lockdep_set_class(&iint->mutex, &type->i_ima_iint_key[depth]);
 #endif
 }
 


base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
-- 
See https://goo.gle/syzbot-ai-patches for information about AI-generated patches.
The person who has signed off on the patch is responsible for
addressing comments.
syzbot engineers can be reached at syzkaller@googlegroups.com.

                 reply	other threads:[~2026-12-03 12:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=4281b2df-1f40-4c78-ae36-c5f1b05df7ee@mail.kernel.org \
    --to=syzbot@kernel.org \
    --cc=brauner@kernel.org \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=eric.snowberg@oracle.com \
    --cc=jack@suse.cz \
    --cc=jmorris@namei.org \
    --cc=krystianmkaniewski@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=roberto.sassu@huawei.com \
    --cc=serge@hallyn.com \
    --cc=syzbot@lists.linux.dev \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=zohar@linux.ibm.com \
    /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