All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hw/usb/canokey: validate endpoint number in canokey_handle_data
@ 2026-09-18  9:57 Bin Guo
  0 siblings, 0 replies; only message in thread
From: Bin Guo @ 2026-09-18  9:57 UTC (permalink / raw)
  To: qemu-devel

canokey_handle_data() takes the endpoint number from the USB packet
(p->ep->nr, guest-selectable 1..15) and uses it to index the fixed-size
ep_out[] / ep_out_size[] arrays of CanoKeyState, which hold only
CANOKEY_EP_NUM = 3 entries.  A forged bulk-OUT transfer on any endpoint
number >= 3 therefore reads a bogus length from past ep_out_size[] and
writes guest data through a wild pointer read from past ep_out[].

Validate p->ep->nr against CANOKEY_EP_NUM and return USB_RET_STALL for
invalid endpoints, before any array access.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4481
Signed-off-by: Bin Guo <guobin@linux.alibaba.com>
---
 hw/usb/canokey.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/usb/canokey.c b/hw/usb/canokey.c
index c3baedac2c..91dd886761 100644
--- a/hw/usb/canokey.c
+++ b/hw/usb/canokey.c
@@ -189,6 +189,11 @@ static void canokey_handle_data(USBDevice *dev, USBPacket *p)
 {
     CanoKeyState *key = CANOKEY(dev);
 
+    if (p->ep->nr >= CANOKEY_EP_NUM) {
+        p->status = USB_RET_STALL;
+        return;
+    }
+
     uint8_t ep_in = CANOKEY_EP_IN(p->ep->nr);
     uint8_t ep_out = p->ep->nr;
     uint32_t in_len;
-- 
2.50.1 (Apple Git-155)



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-18  9:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-18  9:57 [PATCH] hw/usb/canokey: validate endpoint number in canokey_handle_data Bin Guo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.