From: sashiko-bot@kernel.org
To: "Chen-Yu Tsai" <wenst@chromium.org>
Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH 2/4] usb: of: Use raw port numbers for root hub OF lookups
Date: Fri, 04 Dec 2026 03:10:43 +0000 [thread overview]
Message-ID: <sashiko-outbox-249023@kernel.org> (raw)
In-Reply-To: <20261204025243.807657-3-wenst@chromium.org>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: of: UAF/NULL deref race via ledtrig-usbport and
xhci_mem_cleanup()
--
commit c57789cc567b11752bfc353db0a9b7f2d4d5b418
Author: Chen-Yu Tsai <wenst@chromium.org>
usb: of: Use raw port numbers for root hub OF lookups
This commit adds a usb_of_find_raw_port() helper to remap root hub port
numbers via usb_hcd_find_raw_port_number() and uses it in
usb_of_get_device_node() and usb_of_get_connect_type(), removing the
open-coded remapping from usb_alloc_dev().
> diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c
> index a040fae5710be..47e5428fc8d4c 100644
> --- a/drivers/usb/core/of.c
> +++ b/drivers/usb/core/of.c
> @@ -9,15 +9,25 @@
>
> #include <linux/of.h>
> #include <linux/of_graph.h>
> +#include <linux/usb.h>
> +#include <linux/usb/hcd.h>
> #include <linux/usb/of.h>
>
> +static int usb_of_find_raw_port(struct usb_device *hub, int port1)
> +{
> + if (!hub->parent)
> + return usb_hcd_find_raw_port_number(bus_to_hcd(hub->bus), port1);
> +
> + return port1;
> +}
> +
> /**
> * usb_of_get_device_node() - get a USB device node
> * @hub: hub to which device is connected
> - * @port1: one-based index of port
> + * @port1: one-based index of hub port
> *
> * Look up the node of a USB device given its parent hub device and one-based
> - * port number.
> + * hub port number.
> *
> * Return: A pointer to the node with incremented refcount if found, or
> * %NULL otherwise.
> @@ -25,13 +35,19 @@
> struct device_node *usb_of_get_device_node(struct usb_device *hub, int port1)
> {
> struct device_node *node;
> + int raw_port;
> u32 reg;
>
> + if (!hub->dev.of_node)
> + return NULL;
> +
> + raw_port = usb_of_find_raw_port(hub, port1);
[Severity: Medium]
Can usb_of_find_raw_port() trigger a use-after-free or NULL pointer
dereference on xhci->usb{2,3}_rhub.ports when usb_of_get_device_node()
races with usb_remove_hcd()?
Previously usb_of_get_device_node() only read hub->dev.of_node, which
stays valid until the last struct device reference is dropped. Calling
usb_hcd_find_raw_port_number() reaches into xHCI driver state that
xhci_mem_cleanup() frees and clears during HCD teardown while the root
hub device can still be pinned by a bus_for_each_dev() walk:
CPU0 CPU1
usbport_trig_activate()
usb_for_each_dev()
bus_for_each_dev()
usbport_trig_add_port()
kzalloc_obj(...)
usb_remove_hcd()
usb_disconnect(&rhdev)
...
klist_del(&dev->p->knode_bus)
usb_stop_hcd(hcd)
xhci_stop()
xhci_mem_cleanup()
kfree(xhci->usb2_rhub.ports)
kfree(xhci->hw_ports)
usbport_trig_port_observed()
usb_of_get_device_node()
usb_of_find_raw_port()
xhci_find_raw_port_number()
rhub->ports[port1 - 1]->hw_portnum
<-- use-after-free
bus_for_each_dev() holds only a struct device reference without
device_lock() or xhci->mutex, and bus_remove_device() uses non-waiting
klist_del(), so usb_remove_hcd() can proceed to xhci_mem_cleanup()
before usbport_trig_port_observed() runs. Since
xhci_find_raw_port_number() dereferences rhub->ports[port1 - 1] without
locking or a NULL check, this causes a use-after-free read or a NULL
pointer dereference once xhci_mem_cleanup() clears the pointers.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204025243.807657-1-wenst@chromium.org?part=2
next prev parent reply other threads:[~2026-12-04 3:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 2:52 [PATCH 0/4] usb: of: Fix root-hub raw port lookups and graph handling Chen-Yu Tsai
2026-12-04 2:52 ` [PATCH 1/4] usb: of: Ignore 0-based or unnumbered OF graphs in usb_of_get_connect_type() Chen-Yu Tsai
2026-12-04 2:52 ` [PATCH 2/4] usb: of: Use raw port numbers for root hub OF lookups Chen-Yu Tsai
2026-12-04 3:10 ` sashiko-bot [this message]
2026-12-04 2:52 ` [PATCH 3/4] usb: misc: onboard_usb_dev: Create pdevs for secondary root hubs Chen-Yu Tsai
2026-12-04 2:52 ` [PATCH 4/4] usb: of: Check compatible string of device node Chen-Yu Tsai
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=sashiko-outbox-249023@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=wenst@chromium.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