From: Cheng Yongkang <teel4res@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Alan Stern <stern@rowland.harvard.edu>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] usb: usbfs: reject SETINTERFACE while suspend is allowed
Date: Mon, 16 Nov 2026 18:38:58 -0800 [thread overview]
Message-ID: <20261117023858.467683-1-teel4res@gmail.com> (raw)
In-Reply-To: <a7e6b6f9-9926-404a-b185-c9fcab5c9d10@rowland.harvard.edu>
After USBDEVFS_ALLOW_SUSPEND, a usbfs file no longer holds a runtime PM
reference and the device can be runtime suspended. When it is resumed
through reset-resume, finish_port_resume() sets USB_STATE_CONFIGURED
before usb_reset_and_verify_device() restores the altsettings. The
restore loop also runs when a driver bound to another interface calls
usb_reset_device() from its resume handler. The resume path does not
take the device lock, so a SETINTERFACE issued in that window passes
checkintf() and its usb_set_interface() runs concurrently with the
usb_set_interface() calls of the restore loop.
Fail SETINTERFACE with -EHOSTUNREACH while suspend is allowed. A
program has to call USBDEVFS_FORBID_SUSPEND or USBDEVFS_WAIT_FOR_RESUME
first, which resumes the device and keeps it from suspending until the
file allows suspend again.
Fixes: 7794f486ed0b ("usbfs: Add ioctls for runtime power management")
Suggested-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Cheng Yongkang <teel4res@gmail.com>
---
Changes in v2:
- Move the check before copy_from_user() and add a comment (Alan).
v1: https://lore.kernel.org/linux-usb/20261116060549.370140-1-teel4res@gmail.com/
drivers/usb/core/devio.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 101cb9425480..8a032f4b547b 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1531,6 +1531,13 @@ static int proc_setintf(struct usb_dev_state *ps, void __user *arg)
struct usbdevfs_setinterface setintf;
int ret;
+ /*
+ * Avoid racing with a reset during device resume, which restores
+ * the altsettings without holding the device lock. The device can
+ * only be suspended while suspend is allowed.
+ */
+ if (ps->suspend_allowed)
+ return -EHOSTUNREACH;
if (copy_from_user(&setintf, arg, sizeof(setintf)))
return -EFAULT;
ret = checkintf(ps, setintf.interface);
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.34.1
next prev parent reply other threads:[~2026-11-17 2:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 16:37 [QUESTION] usb: usbfs SETINTERFACE during a runtime reset-resume Cheng Yongkang
2026-11-15 20:54 ` Alan Stern
2026-11-16 6:05 ` [PATCH] usb: usbfs: reject SETINTERFACE while suspend is allowed Cheng Yongkang
2026-11-16 6:33 ` sashiko-bot
2026-11-16 18:17 ` Alan Stern
2026-11-17 2:38 ` Cheng Yongkang [this message]
2026-11-17 2:56 ` [PATCH v2] " sashiko-bot
2026-11-17 20:37 ` 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=20261117023858.467683-1-teel4res@gmail.com \
--to=teel4res@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.