Linux USB
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>,
	Mathias Nyman <mathias.nyman@linux.intel.com>,
	Olli Salenius <opsalenius@gmail.com>,
	Michal Pecio <michal.pecio@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH 10/10] xhci: fix NULL pointer dereference of rhub_port in xhci_urb_enqueue()
Date: Fri, 27 Nov 2026 14:17:55 +0200	[thread overview]
Message-ID: <20261127121755.281420-11-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <20261127121755.281420-1-mathias.nyman@linux.intel.com>

xhci_urb_enqueue() checks vdev->rhub_port->link_inactive before queueing
a URB, but rhub_port is only set in xhci_setup_addressable_virt_dev()
when the device is enabled or addressed.

If the virt device is freed and reallocated for an existing usb device,
the new virt device has no rhub_port until usb core enables or addresses
the device again. This happens for example when the xHC is reset during
resume, and xhci_discover_or_reset_device() reallocates the virt device
during reset-resume.

usb core does not send URBs to the device in this window, but a driver
that keeps submitting I/O across system suspend does. This was reported
with hid-steelseries-arctis, whose status polling work sends a control
request during reset-resume after the xHC failed to restore its state:

 BUG: kernel NULL pointer dereference, address: 0000000000000020
 Workqueue: events steelseries_status_timer_work_handler [hid_steelseries_arctis]
 RIP: 0010:xhci_urb_enqueue+0x1c8/0x350
 Call Trace:
  usb_hcd_submit_urb+0x91/0x190
  usb_start_wait_urb+0x8f/0x1d0
  usb_control_msg+0xdd/0x150
  usbhid_raw_request+0x11e/0x140
  steelseries_arctis_9_request_status+0x63/0xb0 [hid_steelseries_arctis]

Refuse to queue URBs to a device that has no root hub port yet. This
also ensures no TDs are queued for a device without rhub_port, which the
transfer event and halted endpoint handling code dereference as well.

Reported-by: Olli Salenius <opsalenius@gmail.com>
Closes: https://lore.kernel.org/all/CACQx0bG4bvt4bHa+WG4u2UGmUc_YMUnhpWovz5+rzp76Jpb9ZA@mail.gmail.com/
Suggested-by: Michal Pecio <michal.pecio@gmail.com>
Fixes: e3d757dc9257 ("xhci: include all root port children in recovery prevention on link error")
Cc: stable@vger.kernel.org
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index fa6f8b879a18..7f0d34c465f8 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1631,6 +1631,7 @@ static int xhci_check_ep0_maxpacket(struct xhci_hcd *xhci, struct xhci_virt_devi
 static int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
 {
 	struct xhci_hcd *xhci = hcd_to_xhci(hcd);
+	struct xhci_virt_device *vdev;
 	unsigned long flags;
 	int ret = 0;
 	unsigned int slot_id, ep_index;
@@ -1683,9 +1684,11 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag
 		goto free_priv;
 	}
 
-	ep_state = &xhci->devs[slot_id]->eps[ep_index].ep_state;
+	vdev = xhci->devs[slot_id];
+	ep_state = &vdev->eps[ep_index].ep_state;
 
-	if (xhci->devs[slot_id]->rhub_port->link_inactive ||
+	/* rhub_port is only set once the device is enabled or addressed */
+	if (!vdev->rhub_port || vdev->rhub_port->link_inactive ||
 	    *ep_state & EP_DROP_PENDING) {
 		xhci_dbg(xhci, "Can't queue urb, port disconnect or link inactive\n");
 		ret = -ENODEV;
-- 
2.43.0


  parent reply	other threads:[~2026-11-27 12:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 12:17 [PATCH 00/10] xhci fixes for usb-linus Mathias Nyman
2026-11-27 12:17 ` [PATCH 01/10] usb: xhci: Fix ep0 maxpacket update on enabled slots Mathias Nyman
2026-11-27 12:17 ` [PATCH 02/10] xhci: check for halted host before accessing virt devices in xhci_check_args() Mathias Nyman
2026-11-27 12:17 ` [PATCH 03/10] xhci: Give back URB under lock in xhci_urb_dequeue() Mathias Nyman
2026-11-27 12:17 ` [PATCH 04/10] xhci: Fix reporting incorrect supported speeds in roothub BOS descriptor Mathias Nyman
2026-11-27 12:17 ` [PATCH 05/10] xhci: sideband: avoid use-after-free of stale virt device pointer Mathias Nyman
2026-11-27 12:17 ` [PATCH 06/10] xhci: sideband: check virt device under xhci lock when stopping endpoints Mathias Nyman
2026-11-27 12:17 ` [PATCH 07/10] usb: xhci: tegra: Fix missing semi-colon Mathias Nyman
2026-11-27 12:17 ` [PATCH 08/10] usb: xhci: Demote isoch buffer overrun message to debug level Mathias Nyman
2026-11-27 12:17 ` [PATCH 09/10] xhci: fix use-after-free for errors mid TD on empty halted rings Mathias Nyman
2026-11-27 12:17 ` Mathias Nyman [this message]
2026-11-27 12:28 ` [PATCH 00/10] xhci fixes for usb-linus sashiko-bot

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=20261127121755.281420-11-mathias.nyman@linux.intel.com \
    --to=mathias.nyman@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=michal.pecio@gmail.com \
    --cc=opsalenius@gmail.com \
    --cc=stable@vger.kernel.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