From: Alan Stern <stern@rowland.harvard.edu>
To: Cheng Yongkang <teel4res@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] usb: usbfs: reject SETINTERFACE while suspend is allowed
Date: Tue, 17 Nov 2026 15:37:27 -0500 [thread overview]
Message-ID: <44d9ed8f-c2c5-414e-a5cf-9dea30866574@rowland.harvard.edu> (raw)
In-Reply-To: <20261117023858.467683-1-teel4res@gmail.com>
On Mon, Nov 16, 2026 at 06:38:58PM -0800, Cheng Yongkang wrote:
> 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>
> ---
Acked-by: Alan Stern <stern@rowland.harvard.edu>
> 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
prev parent reply other threads:[~2026-11-17 20:37 UTC|newest]
Thread overview: 6+ 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 18:17 ` Alan Stern
2026-11-17 2:38 ` [PATCH v2] " Cheng Yongkang
2026-11-17 20:37 ` Alan Stern [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=44d9ed8f-c2c5-414e-a5cf-9dea30866574@rowland.harvard.edu \
--to=stern@rowland.harvard.edu \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=teel4res@gmail.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
all inboxes | Powered by JetHome®