Linux USB
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Niklas Neronin" <niklas.neronin@linux.intel.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH 1/7] usb: xhci: simplify xhci_get_input_control_ctx()
Date: Tue, 01 Dec 2026 19:47:55 +0000	[thread overview]
Message-ID: <sashiko-outbox-244116@kernel.org> (raw)
In-Reply-To: <20261201194134.265480-2-niklas.neronin@linux.intel.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] usb: xhci: race condition in xhci_free_tt_info() [1]
--

commit e4be7ecc7f7cb6e246c200a24855015365ab6a17
Author: Niklas Neronin <niklas.neronin@linux.intel.com>

usb: xhci: simplify xhci_get_input_control_ctx()

This commit replaces the NULL return in xhci_get_input_control_ctx() with a
WARN_ON_ONCE() check and removes the corresponding NULL checks from all
callers.

> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
> index 7f0d34c465f8d..de04a7b705f84 100644
> --- a/drivers/usb/host/xhci.c
> +++ b/drivers/usb/host/xhci.c

[ ... ]

> @@ -5267,12 +5198,6 @@ int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev,
>  		return -ENOMEM;
>  
>  	ctrl_ctx = xhci_get_input_control_ctx(config_cmd->in_ctx);
> -	if (!ctrl_ctx) {
> -		xhci_warn(xhci, "%s: Could not get input context, bad type.\n",
> -				__func__);
> -		xhci_free_command(xhci, config_cmd);
> -		return -ENOMEM;
> -	}
>  
>  	spin_lock_irqsave(&xhci->lock, flags);
>  	if (hdev->speed == USB_SPEED_HIGH &&

[Severity: Critical]
This problem wasn't introduced by this patch, but can xhci_alloc_tt_info()
and xhci_free_tt_info() race and corrupt the root hub port's tts list
[1]?

xhci_update_hub_device() holds xhci->lock while xhci_alloc_tt_info() adds
entries to xhci->rh_bw[...].tts.  If another device on the same root hub
port concurrently fails setup or resets (for example via
xhci_disable_and_free_slot()), xhci_free_virt_device() calls
xhci_free_tt_info() without holding xhci->lock:

CPU0                                CPU1
xhci_update_hub_device()            xhci_disable_and_free_slot()
  spin_lock_irqsave(&xhci->lock)      xhci_free_virt_device()
  xhci_alloc_tt_info()                  xhci_free_tt_info()
    list_add(..., &rh_bw->tts)            list_del(&tt_info->tt_list)
                                            <-- list corruption
  spin_unlock_irqrestore(&xhci->lock)

The concurrent unlocked list_del() can corrupt the tts list pointers,
leading to a crash, infinite loop, or use-after-free during subsequent TT
bandwidth checks.

[1] https://sashiko.dev/#/bug/linux-3e30f7e2-c6ce-4541-8c1c-3eafceec7003

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201194134.265480-1-niklas.neronin@linux.intel.com?part=1

  reply	other threads:[~2026-12-01 19:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 19:41 [PATCH 0/7] usb: xhci: command queueing cleanups Niklas Neronin
2026-12-01 19:41 ` [PATCH 1/7] usb: xhci: simplify xhci_get_input_control_ctx() Niklas Neronin
2026-12-01 19:47   ` sashiko-bot [this message]
2026-12-01 19:41 ` [PATCH 2/7] usb: xhci: add xhci_queue_set_deq() helper Niklas Neronin
2026-12-01 19:41 ` [PATCH 3/7] usb: xhci: simplify prepare_ring() Niklas Neronin
2026-12-01 19:41 ` [PATCH 4/7] usb: xhci: split Configure Endpoint and Evaluate Context handling Niklas Neronin
2026-12-01 19:41 ` [PATCH 5/7] usb: xhci: clear EP_GETTING_NO_STREAMS when freeing streams fails Niklas Neronin
2026-12-01 19:41 ` [PATCH 6/7] usb: xhci: remove pre-allocated free streams command Niklas Neronin
2026-12-01 19:41 ` [PATCH 7/7] usb: xhci: remove command ring TRB reservation Niklas Neronin

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-244116@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=niklas.neronin@linux.intel.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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