mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michal Pecio <michal.pecio@gmail.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: YuanZhe Liu <25031212351@stu.xidian.edu.cn>,
	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: Thu, 5 Nov 2026 08:52:38 +0100	[thread overview]
Message-ID: <20261105085238.337cb70c.michal.pecio@gmail.com> (raw)
In-Reply-To: <d7448504-a63e-4f3a-a828-7656b1084105@rowland.harvard.edu>

On Wed, 4 Nov 2026 23:54:39 -0500, Alan Stern wrote:
> > What I find more disturbing is the existing protection from this
> > race added by 88716a93766b - it looks like core was triggering this
> > too.  
> 
> I don't know anything about it.  That commit only touches xhci-hub.c, 
> not usbcore.

Well, it looked like core was calling hcd->bus_suspend() before
disconnection has completed.

But I just found that xhci-hcd had a bug where hcd->free_dev() would
return before disconnection has fully completed, which can obviously
trick core into doing the above. Now fixed by 7faac1953ed1.

> There should never be any outstanding URBs on suspended ports.  If
> you have any examples, they need to be fixed.

There was a report of some HID driver leaving a pending URB on ep0.
Core blocks and flushes other endpoints, but ep0 is still needed by
device driver's suspend() call IIRC, so it only gets flushed after
the port is put in suspend. I wrote a patch which reliably triggers
ep0 unlink on a suspended port in this manner.

Reporter's HC wasn't expecting this and failed to perform the unlink.

> The core relies on drivers to unlink outstanding URBs and not submit
> any new ones after they have been told that their devices are going
> into suspend.

That's a little weak. The reporter got an LLM to patch the offending
driver, the LLM claimed that other similar drivers have similar bugs,
business as usual. IDK if they have been fixed.

Also, core ignores suspend() routines returning errors during system
sleep transitions. I'm not sure if drivers are *allowed* to return
-EBUSY in those cases, like they do to prevent autosuspend, but it's
at least another opportunity for bugs in drivers to cause issues.

> I suppose we could check that there are no errant URBs still in
> progress just before putting the port into suspend, but is this
> really necessary?

It's already being done, looks like those drivers aren't *actually*
trusted very much. But there is the ep0 loophole.

Regards,
Michal

  reply	other threads:[~2026-11-05  7:52 UTC|newest]

Thread overview: 15+ 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 [this message]
2026-11-04 15:15         ` YuanZhe Liu
2026-11-05  4:28           ` Alan Stern
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=20261105085238.337cb70c.michal.pecio@gmail.com \
    --to=michal.pecio@gmail.com \
    --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=stable@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --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®