From: Junjie Cao <junjie.cao@linux.dev>
To: qemu-devel@nongnu.org
Cc: thuth@redhat.com, kraxel@redhat.com, philmd@oss.qualcomm.com,
junjie.cao@linux.dev, qemu-stable@nongnu.org
Subject: [PATCH 1/2] usb-host: validate interface number before indexing altsetting
Date: Sat, 3 Oct 2026 23:27:21 -0500 [thread overview]
Message-ID: <20261004042722.6937-2-junjie.cao@linux.dev> (raw)
In-Reply-To: <20261004042722.6937-1-junjie.cao@linux.dev>
From: Junjie Cao <junjie.cao@intel.com>
usb_host_ep_update() indexes USBDevice.altsetting with the interface
number supplied by the active configuration descriptor. A descriptor
with bInterfaceNumber >= USB_MAX_INTERFACES reads past that array while
the host device is opened. Skip such interfaces before the lookup.
Record the descriptor's interface number on its endpoints as well. The
loop index identifies the descriptor's position in the configuration,
which need not equal bInterfaceNumber.
Fixes: 0dbe4768b95 ("usb-host: use correct altsetting in usb_host_ep_update")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3975
Cc: qemu-stable@nongnu.org
Signed-off-by: Junjie Cao <junjie.cao@intel.com>
---
hw/usb/host-libusb.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index 629505c6d3..fd4a16ee8a 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -895,6 +895,11 @@ static void usb_host_ep_update(USBHostDevice *s)
* then correct the alternate setting value if necessary.
*/
intf = &conf->interface[i].altsetting[0];
+ if (intf->bInterfaceNumber >= USB_MAX_INTERFACES) {
+ trace_usb_host_parse_error(s->bus_num, s->addr,
+ "invalid interface number");
+ continue;
+ }
alt = udev->altsetting[intf->bInterfaceNumber];
if (alt != 0) {
@@ -930,7 +935,7 @@ static void usb_host_ep_update(USBHostDevice *s)
usb_ep_set_max_packet_size(udev, pid, ep,
endp->wMaxPacketSize);
usb_ep_set_type(udev, pid, ep, type);
- usb_ep_set_ifnum(udev, pid, ep, i);
+ usb_ep_set_ifnum(udev, pid, ep, intf->bInterfaceNumber);
usb_ep_set_halted(udev, pid, ep, 0);
#ifdef HAVE_STREAMS
if (type == LIBUSB_TRANSFER_TYPE_BULK &&
--
2.43.0
next prev parent reply other threads:[~2026-10-04 12:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-04 4:27 [PATCH 0/2] usb-host: validate and release configuration descriptors Junjie Cao
2026-10-04 4:27 ` Junjie Cao [this message]
2026-10-04 16:42 ` [PATCH 1/2] usb-host: validate interface number before indexing altsetting Marc-André Lureau
2026-10-04 4:27 ` [PATCH 2/2] usb-host: free configuration descriptors on error paths Junjie Cao
2026-10-04 16:34 ` Marc-André Lureau
2026-10-05 5:45 ` Junjie Cao
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=20261004042722.6937-2-junjie.cao@linux.dev \
--to=junjie.cao@linux.dev \
--cc=kraxel@redhat.com \
--cc=philmd@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=thuth@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.