Linux USB
 help / color / mirror / Atom feed
* [PATCH] usbip: vudc: check ep0->req_queue before list_last_entry() in get_gadget_descs()
@ 2026-12-04  3:14 Ziheng Wei
  2026-12-04  3:26 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Ziheng Wei @ 2026-12-04  3:14 UTC (permalink / raw)
  To: Valentina Manea, Shuah Khan, Hongren Zheng, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, stable

get_gadget_descs() drops udc->lock to invoke udc->driver->setup(),
reacquires the lock, and unconditionally calls list_last_entry() on
&ep0->req_queue. If setup() did not queue a request or the queue was
emptied while the lock was released, list_last_entry() computes an
invalid struct vrequest pointer from the list head, leading to memory
corruption in list_del() and usb_gadget_giveback_request().

Check list_empty(&ep0->req_queue) after reacquiring udc->lock and return
-EPROTO if no request is queued.

Found by LLM-assisted static analysis. Compile-tested on x86_64.

Fixes: ea6873a45a22 ("usbip: vudc: Add SysFS infrastructure for VUDC")
Cc: stable@vger.kernel.org
Signed-off-by: Ziheng Wei <zihengw03@163.com>
---
 drivers/usb/usbip/vudc_sysfs.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/usbip/vudc_sysfs.c b/drivers/usb/usbip/vudc_sysfs.c
index 47f3a7d51..531b16958 100644
--- a/drivers/usb/usbip/vudc_sysfs.c
+++ b/drivers/usb/usbip/vudc_sysfs.c
@@ -44,6 +44,10 @@ int get_gadget_descs(struct vudc *udc)
 		goto out;
 
 	/* assuming request queue is empty; request is now on top */
+	if (list_empty(&ep0->req_queue)) {
+		ret = -EPROTO;
+		goto out;
+	}
 	usb_req = list_last_entry(&ep0->req_queue, struct vrequest, req_entry);
 	list_del(&usb_req->req_entry);
 

base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-04  3:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  3:14 [PATCH] usbip: vudc: check ep0->req_queue before list_last_entry() in get_gadget_descs() Ziheng Wei
2026-12-04  3:26 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox