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 --- 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