From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, Richard Henderson <richard.henderson@linaro.org>
Cc: Feifan Qian <bea1e@proton.me>
Subject: [PULL 4/6] hw/usb/dev-uas: Don't abort if guest provided an undersized buffer for status
Date: Fri, 14 Aug 2026 12:09:15 +0200 [thread overview]
Message-ID: <20260814100917.163448-5-thuth@redhat.com> (raw)
In-Reply-To: <20260814100917.163448-1-thuth@redhat.com>
QEMU currently aborts if the guest provides an undersized buffer
for the status packet (8 bytes):
hw/usb/core.c:623: usb_packet_copy:
Assertion `p->actual_length + bytes <= iov->size' failed.
If we hit this situation, log a guest error and continue by simply
only providing the bytes that the guest asked for.
(Note: This is e.g. similar to the UAS_PIPE_ID_COMMAND case that
also clamps the length with: length = MIN(sizeof(iu), p->iov.size))
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3900
Reported-by: Feifan Qian <bea1e@proton.me>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-ID: <20260730163901.1154791-1-thuth@redhat.com>
---
hw/usb/dev-uas.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/hw/usb/dev-uas.c b/hw/usb/dev-uas.c
index 963c0433b38..be8c3667e83 100644
--- a/hw/usb/dev-uas.c
+++ b/hw/usb/dev-uas.c
@@ -359,6 +359,7 @@ static void usb_uas_send_status_bh(void *opaque)
UASDevice *uas = opaque;
UASStatus *st;
USBPacket *p;
+ uint32_t length;
while ((st = QTAILQ_FIRST(&uas->results)) != NULL) {
if (uas_using_streams(uas)) {
@@ -373,7 +374,14 @@ static void usb_uas_send_status_bh(void *opaque)
break;
}
- usb_packet_copy(p, &st->status, st->length);
+ length = st->length;
+ if (length > p->iov.size) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "usb uas: packet (%zd) too small for status (%d)\n",
+ p->iov.size, length);
+ length = p->iov.size;
+ }
+ usb_packet_copy(p, &st->status, length);
QTAILQ_REMOVE(&uas->results, st, next);
g_free(st);
@@ -875,7 +883,14 @@ static void usb_uas_handle_data(USBDevice *dev, USBPacket *p)
break;
}
}
- usb_packet_copy(p, &st->status, st->length);
+ length = st->length;
+ if (length > p->iov.size) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "usb uas: packet (%zd) too small for status (%d)\n",
+ p->iov.size, length);
+ length = p->iov.size;
+ }
+ usb_packet_copy(p, &st->status, length);
QTAILQ_REMOVE(&uas->results, st, next);
g_free(st);
break;
--
2.55.0
next prev parent reply other threads:[~2026-08-14 10:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-14 10:09 [PULL 0/6] Functional test framework improvements & bug fixes Thomas Huth
2026-08-14 10:09 ` [PULL 1/6] tests/functional: add skipWithoutSudo() decorator Thomas Huth
2026-08-14 10:09 ` [PULL 2/6] tests/functional/qemu_test: drop *args argument from .get_vm() Thomas Huth
2026-08-14 10:09 ` [PULL 3/6] tests/testcase.py: passthrough monitor_address Thomas Huth
2026-08-14 10:09 ` Thomas Huth [this message]
2026-08-14 10:09 ` [PULL 5/6] hw/net/vmxnet3: Do not abort if guest provides bad interrupt numbers Thomas Huth
2026-08-14 10:09 ` [PULL 6/6] hw/i386/amd_iommu: Avoid undefined behavior in amdvi_setevent_bits() Thomas Huth
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=20260814100917.163448-5-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=bea1e@proton.me \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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.