From: Xue Lei <Xue.Lei@windriver.com>
To: <gregkh@linuxfoundation.org>, <kyungmin.park@samsung.com>,
<andrzej.p@samsung.com>, <balbi@ti.com>
Cc: <linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<Xue.Lei@windriver.com>
Subject: [PATCH] usb: gadget: f_mass_storage: reject relative paths to fix sb_writers deadlock
Date: Wed, 29 Jul 2026 18:32:45 +0800 [thread overview]
Message-ID: <20260729103245.3744500-1-Xue.Lei@windriver.com> (raw)
A deadlock can occur when writing a relative path to the mass_storage
lun file attribute while the process's CWD is on the same configfs
mount:
write(configfs_fd, "relative_path", ...)
-> vfs_write()
-> file_start_write() -- acquires sb_writers (configfs sb)
-> configfs_write_iter()
-> fsg_store_file()
-> fsg_lun_open()
-> filp_open("relative_path", O_RDWR, ...)
-> path_openat()
-> open_last_lookups()
-> mnt_want_write() -- tries to acquire same sb_writers
*** DEADLOCK ***
This happens because filp_open() resolves relative paths against the
task's CWD. If the CWD is on the same configfs superblock, path_openat()
calls mnt_want_write() which calls sb_start_write() on the same
superblock, causing a recursive lock acquisition that can deadlock
during filesystem freeze.
Backing file paths for mass_storage LUNs should always be absolute
paths pointing to block devices or regular files. Reject relative
paths early in fsg_store_file() to prevent this deadlock.
Reported-by: syzbot+4c9318af45f0bf2af153@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=4c9318af45f0bf2af153
Fixes: ef0aa4b92cf1 ("usb: gadget: f_mass_storage: add configfs support")
Signed-off-by: Xue Lei <Xue.Lei@windriver.com>
---
drivers/usb/gadget/function/storage_common.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/usb/gadget/function/storage_common.c b/drivers/usb/gadget/function/storage_common.c
index 75831f2c7abe..d45c7a34df99 100644
--- a/drivers/usb/gadget/function/storage_common.c
+++ b/drivers/usb/gadget/function/storage_common.c
@@ -448,6 +448,12 @@ ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem,
if (count > 0 && buf[count-1] == '\n')
((char *) buf)[count-1] = 0; /* Ugh! */
+ /* Reject relative paths to prevent sb_writers deadlock when
+ * CWD is on the same filesystem (e.g., configfs).
+ */
+ if (count > 0 && buf[0] && buf[0] != '/')
+ return -EINVAL;
+
/* Load new medium */
down_write(filesem);
if (count > 0 && buf[0]) {
--
2.49.1
next reply other threads:[~2026-07-29 10:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 10:32 Xue Lei [this message]
2026-07-29 14:12 ` [PATCH] usb: gadget: f_mass_storage: reject relative paths to fix sb_writers deadlock Alan Stern
2026-07-30 9:27 ` Lei, Xue
2026-07-30 14:19 ` Alan Stern
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=20260729103245.3744500-1-Xue.Lei@windriver.com \
--to=xue.lei@windriver.com \
--cc=andrzej.p@samsung.com \
--cc=balbi@ti.com \
--cc=gregkh@linuxfoundation.org \
--cc=kyungmin.park@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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