From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Cc: Feifan Qian <bea1e@proton.me>, Peter Maydell <peter.maydell@linaro.org>
Subject: [PULL 5/5] hw/usb/hcd-xhci: Check return value of xhci_xfer_create_sgl() for errors
Date: Mon, 27 Jul 2026 14:52:07 +0200 [thread overview]
Message-ID: <20260727125207.646148-6-thuth@redhat.com> (raw)
In-Reply-To: <20260727125207.646148-1-thuth@redhat.com>
From: Thomas Huth <thuth@redhat.com>
xhci_xfer_create_sgl() can fail if a guest programmed the XHCI in
a weird way. The current code ignores this error, and this triggers
an assert() shortly afterwards:
hw/usb/core.c:612: usb_packet_copy:
Assertion `p->actual_length + bytes <= iov->size' failed.
Fix it by handling the error correctly (i.e. return with an error to
the caller).
While we're at it, change the DPRINTF statements in xhci_xfer_create_sgl()
into proper qemu_log_mask() statements, so we have a better way to detect
this situation.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3786
Reported-by: Feifan Qian <bea1e@proton.me>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-ID: <20260724110933.629791-1-thuth@redhat.com>
---
hw/usb/hcd-xhci.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 569386b8cf1..d342aa2739e 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -1464,7 +1464,8 @@ static int xhci_xfer_create_sgl(XHCITransfer *xfer, int in_xfer)
switch (TRB_TYPE(*trb)) {
case TR_DATA:
if ((!(trb->control & TRB_TR_DIR)) != (!in_xfer)) {
- DPRINTF("xhci: data direction mismatch for TR_DATA\n");
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "xhci: data direction mismatch for TR_DATA\n");
goto err;
}
/* fallthrough */
@@ -1474,7 +1475,8 @@ static int xhci_xfer_create_sgl(XHCITransfer *xfer, int in_xfer)
chunk = trb->status & 0x1ffff;
if (trb->control & TRB_TR_IDT) {
if (chunk > 8 || in_xfer) {
- DPRINTF("xhci: invalid immediate data TRB\n");
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "xhci: invalid immediate data TRB\n");
goto err;
}
qemu_sglist_add(&xfer->sgl, trb->addr, chunk);
@@ -1617,7 +1619,9 @@ static int xhci_setup_packet(XHCITransfer *xfer)
}
}
- xhci_xfer_create_sgl(xfer, dir == USB_TOKEN_IN); /* Also sets int_req */
+ if (xhci_xfer_create_sgl(xfer, dir == USB_TOKEN_IN) < 0) { /* Also sets int_req */
+ return -1;
+ }
usb_packet_setup(&xfer->packet, dir, ep, xfer->streamid,
xfer->trbs[0].addr, false, xfer->int_req);
if (usb_packet_map(&xfer->packet, &xfer->sgl)) {
--
2.55.0
prev parent reply other threads:[~2026-07-27 12:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 12:52 [PULL 0/5] Various fixes for 11.1-rc2 Thomas Huth
2026-07-27 12:52 ` [PULL 1/5] hw/cxl: Validate Set Feature payload bounds Thomas Huth
2026-07-27 12:52 ` [PULL 2/5] hw/usb/dev-uas: Fix guest-triggerable heap OOB access Thomas Huth
2026-07-27 12:52 ` [PULL 3/5] hw/ide/core: Fix possible crash via NULL pointer in ide_cancel_dma_sync() Thomas Huth
2026-07-27 12:52 ` [PULL 4/5] hw/usb/core: Avoid possible assert() in do_parameter() --> usb_packet_copy() Thomas Huth
2026-07-27 12:52 ` Thomas Huth [this message]
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=20260727125207.646148-6-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=bea1e@proton.me \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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.