From: William Chuang <founder@logarcheon.com>
To: Breno Leitao <leitao@debian.org>
Cc: Andreas Hindborg <a.hindborg@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org,
syzbot+c75a7db5ca6ae96ed2d4@syzkaller.appspotmail.com,
syzkaller-bugs@googlegroups.com
Subject: [PATCH] configfs: give the root directory inode its own lockdep class
Date: Tue, 17 Nov 2026 06:53:20 +0000 [thread overview]
Message-ID: <20261117065314.4309-1-founder@logarcheon.com> (raw)
Directories created with mkdir(2) and the configfs root directory share
the default i_rwsem lock class of configfs; only default groups get
their own depth-based classes in configfs_set_inode_lock_class().
Lockdep therefore treats the root inode's lock and the lock of any
user-created directory as the same lock.
That produces a false circular dependency between the USB gadget and
target subsystems, which syzbot keeps reporting:
(3) tpg_instances_lock -> configfs i_rwsem
usbg_make_tpg() calls configfs_depend_item_unlocked(), which
locks the configfs root inode for a target in another subsystem
(2) func_lock -> tpg_instances_lock (tcm_alloc_inst)
(1) gadget_subsys.su_mutex -> func_lock (configfs_mkdir, function_make)
(0) configfs i_rwsem -> gadget_subsys.su_mutex
configfs_symlink() runs with the parent directory locked, and
uvcg_streaming_header_allow_link() takes su_mutex
The inode in (0) is a directory under the gadget subsystem; the inode in
(3) is the configfs root. A real deadlock would need something to take
a subsystem su_mutex while holding the root inode's lock, and nothing
does:
- the root has only ->lookup and ->setattr, so mkdir, rmdir, symlink,
unlink and rename in the root fail in the VFS before configfs runs;
- configfs_lookup(), configfs_setattr(), configfs_readdir(),
configfs_dir_open() and configfs_dir_close() take no subsystem lock;
- configfs_register_subsystem(), configfs_unregister_subsystem(),
configfs_depend_item() and configfs_depend_item_unlocked() lock the
root but take no su_mutex while holding it.
Give the root inode its own class so that lockdep keeps the two apart.
This changes nothing without CONFIG_LOCKDEP.
Tested in QEMU (x86_64, PROVE_LOCKING) at 666539eec with an initramfs
that runs the three operations above (a UVC streaming header symlink,
mkdir functions/tcm.0, mkdir target/usb_gadget/naa.*/tpgt_1), then
readdir, chmod and mkdir on the configfs root, and tears everything
down again. Without this patch lockdep reports the cycle above; with
it there is no report and every step gives the same result.
With the patch, the configfs kselftest passes (25/25, including its
symlink-versus-rmdir race test) with no lockdep report, as it does
without it. Three processes looping for 60 seconds over tpgt_1
mkdir/rmdir (which locks the configfs root through
configfs_depend_item_unlocked()), the UVC symlink/unlink, and readdir
plus chmod of the configfs root never stalled, with or without the
patch; without it, lockdep reports the cycle during that run. Without
CONFIG_LOCKDEP the patch changes no code: fs/configfs/mount.o
disassembles identically before and after. It builds cleanly with
W=1. Not tested: syzbot's own C reproducer.
Fixes: 4bb8548df632 ("usb: gadget: f_tcm: add configfs support")
Reported-by: syzbot+c75a7db5ca6ae96ed2d4@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c75a7db5ca6ae96ed2d4
Signed-off-by: William Chuang <founder@logarcheon.com>
---
fs/configfs/mount.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c
index d8cac1cbf..d20d2fd1e 100644
--- a/fs/configfs/mount.c
+++ b/fs/configfs/mount.c
@@ -58,6 +58,15 @@ static struct configfs_dirent configfs_root = {
.s_iattr = NULL,
};
+/*
+ * configfs_depend_item_unlocked() takes the root inode's lock while a
+ * subsystem's own locks may be held, but nothing takes a subsystem lock
+ * while holding the root inode's lock. Directories created by mkdir(2)
+ * share the default i_rwsem class and are locked before their subsystem's
+ * su_mutex, so give the root inode a class of its own.
+ */
+static struct lock_class_key configfs_root_inode_class;
+
static int configfs_fill_super(struct super_block *sb, struct fs_context *fc)
{
struct inode *inode;
@@ -74,6 +83,7 @@ static int configfs_fill_super(struct super_block *sb, struct fs_context *fc)
if (inode) {
inode->i_op = &configfs_root_inode_operations;
inode->i_fop = &configfs_dir_operations;
+ lockdep_set_class(&inode->i_rwsem, &configfs_root_inode_class);
/* directory inodes start off with i_nlink == 2 (for "." entry) */
inc_nlink(inode);
} else {
--
2.43.0
next reply other threads:[~2026-11-17 6:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 6:53 William Chuang [this message]
2026-11-17 7:13 ` [PATCH] configfs: give the root directory inode its own lockdep class sashiko-bot
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=20261117065314.4309-1-founder@logarcheon.com \
--to=founder@logarcheon.com \
--cc=a.hindborg@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=leitao@debian.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=syzbot+c75a7db5ca6ae96ed2d4@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.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