From: Bin Guo <guobin@linux.alibaba.com>
To: qemu-devel@nongnu.org
Subject: [PATCH] hw/usb/canokey: validate endpoint number in canokey_handle_data
Date: Fri, 18 Sep 2026 17:57:18 +0800 [thread overview]
Message-ID: <20260918095718.33745-1-guobin@linux.alibaba.com> (raw)
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)
reply other threads:[~2026-09-18 9:58 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260918095718.33745-1-guobin@linux.alibaba.com \
--to=guobin@linux.alibaba.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.