From: "Neronin, Niklas" <niklas.neronin@linux.intel.com>
To: Anfernee Cao <anferneemelokc5@gmail.com>,
Mathias Nyman <mathias.nyman@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] usb: xhci: fix EP0 context leak on virt device allocation failure
Date: Mon, 19 Oct 2026 15:47:31 +0300 [thread overview]
Message-ID: <e952e037-5be8-49c0-b0fe-bcf1bda77bdc@linux.intel.com> (raw)
In-Reply-To: <20261017111114.1135-1-anferneemelokc5@gmail.com>
On 17/10/2026 14.11, Anfernee Cao wrote:
> When XHCI_EP_LIMIT_QUIRK is set, xhci_alloc_dev() reserves an endpoint
> context for the default control endpoint before allocating the virt
> device:
>
> ret = xhci_reserve_host_control_ep_resources(xhci);
> ...
> if (!xhci_alloc_virt_device(xhci, slot_id, udev, GFP_NOIO))
> goto disable_slot;
>
> The reservation is normally released by xhci_handle_cmd_disable_slot(),
> which calls xhci_free_device_endpoint_resources() for the virt device
> found at xhci->devs[slot_id]. xhci_alloc_virt_device() does not install
> the virt device when it fails, so the Disable Slot completion handler
> finds an empty slot, returns early, and the reserved context is never
> released.
>
> Each failure leaks one endpoint context. Once num_active_eps reaches
> limit_active_eps, every new device is rejected with "Not enough host
> resources" and cannot be enumerated.
>
> Fix this by releasing the reservation when xhci_alloc_virt_device()
> fails.
>
> Fixes: 2cf95c18d506 ("Intel xhci: Limit number of active endpoints to 64.")
> Cc: stable@vger.kernel.org
> Signed-off-by: Anfernee Cao <anferneemelokc5@gmail.com>
> ---
> drivers/usb/host/xhci.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
> index 7f7babe9d681..8b9a6f88cca5 100644
> --- a/drivers/usb/host/xhci.c
> +++ b/drivers/usb/host/xhci.c
> @@ -4278,6 +4278,15 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev)
> */
> if (!xhci_alloc_virt_device(xhci, slot_id, udev, GFP_NOIO)) {
> xhci_warn(xhci, "Could not allocate xHCI USB device data structures\n");
> + /*
> + * The virt device was not installed, so the Disable Slot
> + * completion handler cannot drop the EP0 context reservation.
> + */
> + if (xhci->quirks & XHCI_EP_LIMIT_QUIRK) {
> + spin_lock_irqsave(&xhci->lock, flags);
> + xhci->num_active_eps--;
> + spin_unlock_irqrestore(&xhci->lock, flags);
> + }
> goto disable_slot;
> }
> vdev = xhci->devs[slot_id];
Hi,
Thanks for working on this. I believe this is the same issue addressed in this patch:
https://lore.kernel.org/linux-usb/20261006152427.3735383-3-niklas.neronin@linux.intel.com/
Thanks,
Niklas
prev parent reply other threads:[~2026-10-19 12:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-17 11:11 Anfernee Cao
[not found] ` <sashiko-outbox-175494@kernel.org>
2026-10-17 11:36 ` Anfernee Cao
2026-10-19 12:47 ` Neronin, Niklas [this message]
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=e952e037-5be8-49c0-b0fe-bcf1bda77bdc@linux.intel.com \
--to=niklas.neronin@linux.intel.com \
--cc=anferneemelokc5@gmail.com \
--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 \
/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®