[PATCH 1/2] usbip: clear actual_length after a failed receive
From: Cheng Yongkang
Date: Thu Oct 29 2026 - 10:13:19 EST
vhci_recv_ret_submit() receives the transfer buffer for an IN URB. When
usbip_recv_xbuff() fails, it sets urb->status to -EPROTO and gives the URB
back, but leaves urb->actual_length at the value supplied by the usbip
peer. A malicious peer can set actual_length larger than
transfer_buffer_length; usbfs then copies that many bytes from the
kmalloc(transfer_buffer_length) buffer to userspace:
BUG: KASAN: slab-out-of-bounds in _copy_to_user+0x79/0xb0
Read of size 88 at addr ...
copy_urb_data_to_user+0x36f/0x480
Clear actual_length on the failure path so the failed URB never carries a
peer-controlled length. The URB is completed with -EPROTO and userspace
observes a zero-length, failed transfer.
Fixes: aabb5b833872 ("usbip: Fix error path of vhci_recv_ret_submit()")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: LLM
Signed-off-by: Cheng Yongkang <teel4res@xxxxxxxxx>
---
drivers/usb/usbip/vhci_rx.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
index a678e7c..741107a 100644
--- a/drivers/usb/usbip/vhci_rx.c
+++ b/drivers/usb/usbip/vhci_rx.c
@@ -79,6 +79,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
/* recv transfer buffer */
if (usbip_recv_xbuff(ud, urb) < 0) {
urb->status = -EPROTO;
+ urb->actual_length = 0;
goto error;
}
--
2.34.1