Commit 69aedf407d for qemu.org
commit 69aedf407d94012a7580155bd760e0aa24b6f76b
Author: Tommaso Califano <tcalifano@redhat.com>
Date: Thu Nov 12 18:49:00 2026 +0100
hw/usb/dev-mtp: Check length of class control request
usb_mtp_handle_control() reads a 16-bit event code from the request
data without checking that the host actually sent it. A request with
wLength < 2 makes the device act on stale bytes left in the control
buffer.
STALL requests that are too short to hold the event code.
Cc: qemu-stable@nongnu.org
Fixes: 47bff13cea8d ("dev-mtp: add support for canceling transaction")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4529
Suggested-by: Hui Peng <https://gitlab.com/benquike>
Signed-off-by: Tommaso Califano <tcalifano@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20261112174907.158825-4-tcalifano@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index bc5a6f0891..92dc9a9e21 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -1516,6 +1516,10 @@ static void usb_mtp_handle_control(USBDevice *dev, USBPacket *p,
switch (request) {
case ClassInterfaceOutRequest | 0x64:
+ if (length < sizeof(*event)) {
+ p->status = USB_RET_STALL;
+ break;
+ }
if (*event == EVT_CANCEL_TRANSACTION) {
g_free(s->result);
s->result = NULL;