mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
Cc: Michal Pecio <michal.pecio@gmail.com>,
	Mathias Nyman <mathias.nyman@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, Bin Yu <byu@xidian.edu.cn>,
	Cheng Wen <wencheng@xidian.edu.cn>
Subject: Re: [PATCH v5] usb: xhci: Fix use-after-free race in xhci_stop_device()
Date: Wed, 4 Nov 2026 23:28:48 -0500	[thread overview]
Message-ID: <82a746b7-4e87-4d46-88c3-bb881f11b8de@rowland.harvard.edu> (raw)
In-Reply-To: <20261104151544.26672-1-25031212351@stu.xidian.edu.cn>

On Wed, Nov 04, 2026 at 11:15:44PM +0800, YuanZhe Liu wrote:
> Alan,
> 
> Thanks - that is a fair point, and I agree that the generic exposure is in
> the core: usbfs can drive port state on a hub whose driver is being
> unbound, and usb core does not serialize the two.
> 
> The awkward part is where the lock would go.  do_proc_control() releases
> usb_lock_device() around usbfs_start_wait_urb(), so the control request to
> the hub runs without the device lock, while usb_unbind_interface() ->
> hub_disconnect() holds it.  Making those two exclude each other on that
> mutex would mean holding it across a synchronous URB, which I do not think
> is acceptable.
> 
> Two shapes I can see on the core side:
> 
>  - refuse or queue hub class requests to a hub while its driver is being
>    unbound, or
>  - make usb_disconnect() of that hub's children wait for in-flight
>    port-state requests on that hub first.
> 
> I am happy to prototype either one; tell me which you would prefer.

I'm still not certain I fully understand what's going on here.  It 
sounds like one thread uses usbfs's do_proc_control() to send a 
Set-Port-Feature(suspend) request to a hub, presumably without claiming 
the hub interface.  At the same time, another thread tells usbfs to call 
usb_driver_release_interface() for the hub interface.  Is that right?  
If so, read on...

The issue here isn't a race, or locking, or a matter of a port's state.  
The real problem is that userspace can use usbfs to send a 
Set-Port-Feature request to the hub without claiming the hub interface.  
If usbfs had to claim the interface then the problem you encountered 
could not occur, right?

It looks like check_ctrlrecip() needs to be more careful.  A whole bunch 
of requesttype/request combinations -- basically, anything that isn't a 
GET-* -- should be forced to call checkintf(ps, 0) if the target device 
is a hub.  After all, we don't want userspace interfering with the 
operation of the hub driver.  This special hub-class handling should 
come directly before the code for the printer class.

Can you write a patch to do this?

> What is xhci-specific is that xhci_hub_control() is the only one of these
> paths that walks per-device state: xhci_stop_device() looks up
> xhci->devs[slot_id] and drops xhci->lock while sending the stop endpoint
> commands.  ehci/ohci/uhci only write port registers there, so the same
> interleaving does not give them a use-after-free.
> 
> So I would like to keep the xhci hunk as well, as memory-safety hardening
> for the case where the core does not catch it.  If you would rather see
> the core change first, I can send that separately and rebase this on top
> of it.

That's fine; I'm not concerned about the xhci-hcd portion.

Alan Stern

  reply	other threads:[~2026-11-05  4:28 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-26 12:36 [PATCH v2] " YuanZhe Liu
2026-10-30  6:01 ` YuanZhe Liu
2026-11-03 14:56 ` Mathias Nyman
2026-11-03 16:01   ` [PATCH v3] " YuanZhe Liu
2026-11-03 23:00     ` Michal Pecio
2026-11-04  1:32       ` [PATCH v4] " YuanZhe Liu
2026-11-04  3:56       ` [PATCH v5] " YuanZhe Liu
2026-11-04 15:02         ` Alan Stern
2026-11-04 16:59           ` Michal Pecio
2026-11-05  4:54             ` Alan Stern
2026-11-05  7:52               ` Michal Pecio
2026-11-05 15:39                 ` Alan Stern
2026-11-04 15:15         ` YuanZhe Liu
2026-11-05  4:28           ` Alan Stern [this message]
2026-11-05  5:30             ` [PATCH] usb: usbfs: Require claiming a hub interface for hub class requests YuanZhe Liu
2026-11-05  5:43             ` [PATCH v2] " YuanZhe Liu

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=82a746b7-4e87-4d46-88c3-bb881f11b8de@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=25031212351@stu.xidian.edu.cn \
    --cc=byu@xidian.edu.cn \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=michal.pecio@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=wencheng@xidian.edu.cn \
    /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®