* [PATCH] usb: gadget: bcm63xx_udc: fix dequeue of unqueued request
@ 2026-10-23 8:08 liuc63
0 siblings, 0 replies; only message in thread
From: liuc63 @ 2026-10-23 8:08 UTC (permalink / raw)
To: gregkh
Cc: cernekee, sebastian, balbi, liuwb, linux-usb, linux-kernel,
Liu Chao, stable
From: Liu Chao <liuc63@xiaopeng.com>
bcm63xx_udc_dequeue() only checks whether bep->queue is empty; it never
verifies that the passed request is actually linked on that queue. If
the request was already completed by the data ISR (which list_del's it)
or belongs to another endpoint, list_del() corrupts an unrelated list
node. Worse, the out: path unconditionally sets req->status and calls
req->complete() even when rc == -EINVAL, so a request that was never
queued (or was already completed and possibly freed by the gadget
driver) gets completed a second time, leading to a double completion
and use-after-free.
Walk bep->queue to confirm the request is queued before touching it,
and only invoke the completion callback when the request was actually
removed from the queue. The -EINVAL path now returns without
completing.
Fixes: 613065e53cb1 ("usb: gadget: bcm63xx UDC driver")
Cc: stable@vger.kernel.org
Reviewed-by: Weibin Liu <liuwb@xiaopeng.com>
Signed-off-by: Liu Chao <liuc63@xiaopeng.com>
---
drivers/usb/gadget/udc/bcm63xx_udc.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/gadget/udc/bcm63xx_udc.c b/drivers/usb/gadget/udc/bcm63xx_udc.c
index 502612a56..a27dc7df7 100644
--- a/drivers/usb/gadget/udc/bcm63xx_udc.c
+++ b/drivers/usb/gadget/udc/bcm63xx_udc.c
@@ -1209,15 +1209,20 @@ static int bcm63xx_udc_dequeue(struct usb_ep *ep, struct usb_request *req)
int rc = 0;
spin_lock_irqsave(&udc->lock, flags);
- if (list_empty(&bep->queue)) {
+
+ /* Make sure the request is actually queued on this endpoint */
+ list_for_each_entry(cur, &bep->queue, queue) {
+ if (cur == breq)
+ break;
+ }
+ if (&cur->queue == &bep->queue) {
rc = -EINVAL;
goto out;
}
- cur = list_first_entry(&bep->queue, struct bcm63xx_req, queue);
usb_gadget_unmap_request(&udc->gadget, &breq->req, bep->iudma->is_tx);
- if (breq == cur) {
+ if (breq == list_first_entry(&bep->queue, struct bcm63xx_req, queue)) {
iudma_reset_channel(udc, bep->iudma);
list_del(&breq->queue);
@@ -1235,8 +1240,11 @@ static int bcm63xx_udc_dequeue(struct usb_ep *ep, struct usb_request *req)
out:
spin_unlock_irqrestore(&udc->lock, flags);
- req->status = -ESHUTDOWN;
- req->complete(ep, req);
+ /* Only complete the request if it was actually removed */
+ if (rc == 0) {
+ req->status = -ESHUTDOWN;
+ req->complete(ep, req);
+ }
return rc;
}
--
2.50.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-23 8:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-23 8:08 [PATCH] usb: gadget: bcm63xx_udc: fix dequeue of unqueued request liuc63
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®