From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796353844; b=a546QzRzCGMPS+ZcY0utPn4Fj3mDIIVz1TEIzfMsoljZAkNPA7dt6TrqV2TszphFrKy6 53cOJVvPTa1DnGG1/uCVGfveSdmT/gkgiWR6oxWCIf+ak/QisU4yLWRo/Q+sU5YoU2g01 fiqVGkqdlymoG3gJdHxh6uVaRagdsWKQdn8BEKmXGlKHDJKBUcN8p5d5umSCBumFqDUAT /Frf0uxWaVuKUXTXjfCyfMS4l4iBjlh/I3pj5wPh7BvipdKT5Hw48/o0aDeRoE/2I0Cem rEUd2CIH96wKF6z4nYVKSKGJazTt6aZlxWmTQSZ5SD2bEgRxSMiBSv5ZNDIU7aOQj7Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796353844; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=0MklKzH3CWdYn5nYEHclb2c86rzZH/lnmGSO7bq1NB0=; b=Zb+grnYTppgoDdCtizht3mD1JyrAL1UE2Co66XKMqYaXm7n5KMjrC84tUQJY8oLLyKwS 5kurL/Xd5VG8n2+lnBwvjtt9DBKf43HzEcGQU/hIf8D3kIe7dKl71rIeHXzwnxnX2MgS7 5tZhex8FLnwiNzy7UQvt9oZfg133JsZn6XlFvK7Gm5XqJl64fofq/Lxw1WC/9e3WKTN1N rpfCXNbpsJvfE4mh5+d7ShyjP/88SbdI6ya5sqkz+so17mj+XdH/KiqCL6uBvNaLDaosO PTtWBGm19GKErp/gDo3cHW2/WnFB8p5A/pyq5oasSZucLdT/GOCmJw5TzUvkrEw1GuQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Xi9+HG79; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BACA4606A322; Fri, 4 Dec 2026 03:10:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Xi9+HG79 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62B531F000CE; Fri, 4 Dec 2026 03:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796353844; bh=0MklKzH3CWdYn5nYEHclb2c86rzZH/lnmGSO7bq1NB0=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Xi9+HG79Ab5XdnvIA8NlhD5QH+Yojit+jn/6T5uv6ILtJEQqMIyx0aNd1i474HBoo UDESO2LjTAGSHm2N29c/qTZUrmoJ1kFnCGqLEnbyLhhm3+hG+ii79K1BcDBb9NbCE4 mOUclKZZ0A2+cHd5u6lP1AEzUP3pu0SnDSFARTHdG9NkNeUCsfylZcCt+WD9ctrEOm I59SOML8O+uTUunDDIo3EUCxyk8p+42O3JUFwmKYPG7djXqoYPwE0pdQ48KOm0Kx9x n+u7PRjW1SS4whSwX9A+1eGESvkFAuQa3dh7O88HlNE2dSskhEX28KJJRIvjSVAHQ/ Yrt1SXM3JdROA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 2/4] usb: of: Use raw port numbers for root hub OF lookups Reply-To: sashiko-reviews@lists.linux.dev To: "Chen-Yu Tsai" Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261204025243.807657-3-wenst@chromium.org> References: <20261204025243.807657-1-wenst@chromium.org> <20261204025243.807657-3-wenst@chromium.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 03:10:43 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 @@ > =20 > #include > #include > +#include > +#include > #include > =20 > +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 p= ort1) > { > struct device_node *node; > + int raw_port; > u32 reg; > =20 > + if (!hub->dev.of_node) > + return NULL; > + > + raw_port =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204025243.8076= 57-1-wenst@chromium.org?part=3D2