@samitouri / QOSamiQemu / commits / 2c6fae7d7d

hw/usb/dev-wacom: Don't write off end of buffer

In usb_wacom_handle_data() we allocate a buffer with a size determined by the transfer size requested by the guest. We then fill it in by calling either usb_mouse_poll() or usb_wacom_poll(), both of which functions take a length and return an actual length, which we pass to usb_packet_copy(). However, usb_mouse_poll() doesn't check the buffer size as it fills in the buffer, so if the guest passes an overly short transfer size then it will write off the end of the allocated buffer. Check the length is at least big enough for the minimum 3 byte packet and return nothing if it is not, as usb_wacom_poll() does. Cc: qemu-stable@nongnu.org Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3672 Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Message-id: 20260706182034.1003176-1-peter.maydell@linaro.org

Peter Maydell committed Jul 13, 2026 at 12:34 UTC 2c6fae7d7da874615d8585f6d2b16ffb673c5c9a
1 file changed +4
hw/usb/dev-wacom.c
+4
@@ -285,6 +285,10 @@ static int usb_mouse_poll(USBWacomState *s, uint8_t *buf, int len)
285 b |= 0x04;
286 }
287
288 + if (len < 3) {
289 + return 0;
290 + }
291 +
292 buf[0] = b;
293 buf[1] = dx;
294 buf[2] = dy;