From: sashiko-bot@kernel.org
To: "Igor Skalkin" <igor.skalkin@oss.qualcomm.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
virtualization@lists.linux.dev,
"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH 1/8] virtio-usb: add protocol header and skeleton dual-role driver
Date: Thu, 24 Sep 2026 16:23:39 +0000 [thread overview]
Message-ID: <20260924162339.7888C1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260924160907.145405-2-igor.skalkin@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] usb: virtio_usb Kconfig allows built-in driver with modular gadget subsystem
- [Medium] virtio-usb: 16-bit port ID in device UAPI structures truncates 32-bit index
- [Medium] virtio-usb: missing bounds check on untrusted nports causes huge allocation
- [Low] virtio-usb: redundant USB prefix in UAPI SuperSpeed enum constant
- [Low] virtio-usb: missing error check after virtio_find_vqs() copies stale pointer
--
commit 326b99edf62be9a25cd868d49b2b33423f8607c9
Author: Aiswarya Cyriac <aiswarya.cyriac@oss.qualcomm.com>
virtio-usb: add protocol header and skeleton dual-role driver
Add the virtio_usb device and virtqueue-wrapper skeleton, the protocol header
shared with the vhost gadget driver and userspace backend, and probe()/remove()
plumbing with no role support yet.
> diff --git a/drivers/usb/virtio_usb/Kconfig b/drivers/usb/virtio_usb/Kconfig
> new file mode 100644
> index 0000000000000..bd377b9cbb43a
> --- /dev/null
> +++ b/drivers/usb/virtio_usb/Kconfig
> @@ -0,0 +1,21 @@
> +config USB_VIRTIO
> + tristate "Virtio USB device support"
> + depends on USB_SUPPORT && VIRTIO
> + depends on USB || USB_GADGET
> + depends on USB if !USB_GADGET
> + depends on USB_GADGET if !USB
[Severity: High]
Does this logic allow CONFIG_USB_VIRTIO to be built-in while the gadget
subsystem is modular?
If CONFIG_USB=y and CONFIG_USB_GADGET=m, it looks like 'depends on USB if
!USB_GADGET' evaluates to ignored, permitting CONFIG_USB_VIRTIO=y. Because
device.o is unconditionally compiled into the driver, could this cause
undefined references to modular gadget APIs from built-in code, breaking
the vmlinux link?
[ ... ]
> diff --git a/drivers/usb/virtio_usb/controller.c b/drivers/usb/virtio_usb/controller.c
> new file mode 100644
> index 0000000000000..2fc6f502b48f3
> --- /dev/null
> +++ b/drivers/usb/virtio_usb/controller.c
[ ... ]
> +static int virtio_usb_find_vqs(struct virtio_usb *vusb)
> +{
> + unsigned int nvqs = vusb->nvqs, i;
> + struct virtqueue **vqs = NULL;
> + int rc = -ENOMEM;
> +
> + vqs = kcalloc(nvqs, sizeof(void *), GFP_KERNEL);
> + if (!vqs)
> + return -ENOMEM;
> +
> + struct virtqueue_info *vqs_info =
> + kcalloc(nvqs, sizeof(*vqs_info), GFP_KERNEL);
> + if (!vqs_info) {
> + rc = -ENOMEM;
> + goto on_exit;
> + }
> + for (i = 0; i < nvqs; i++) {
> + vqs_info[i].name = vusb->vqueues[i].name;
> + vqs_info[i].callback = vusb->vqueues[i].callback;
> + }
> + rc = virtio_find_vqs(vusb->vdev, nvqs, vqs, vqs_info, NULL);
> +
> + kfree(vqs_info);
> +
> + for (i = 0; i < nvqs; i++) {
> + vusb->vqueues[i].vqueue = vqs[i];
> + spin_lock_init(&vusb->vqueues[i].lock);
> + }
[Severity: Low]
Is there a missing error check for 'rc' here?
If virtio_find_vqs() fails and returns an error code, the code seems to fall
through to the loop and blindly assign vusb->vqueues[i].vqueue = vqs[i]
using uninitialized or dangling pointers from the vqs array before exiting
via 'on_exit'.
Should there be an 'if (rc) goto on_exit;' before the loop?
> +on_exit:
> + kfree(vqs);
> + return rc;
> +}
[ ... ]
> +static int virtio_usb_probe(struct virtio_device *vdev)
> +{
> + struct virtio_usb *vusb;
> + unsigned int nvqs = 0;
> + int rc = 0;
> +
> + vusb = devm_kzalloc(&vdev->dev, sizeof(*vusb), GFP_KERNEL);
> + if (!vusb)
> + return -ENOMEM;
> +
> + vusb->vdev = vdev;
> + vdev->priv = vusb;
> +
> + virtio_cread_le(vdev, struct virtio_usb_config, ports, &vusb->nports);
> +
> + vusb->vports = devm_kcalloc(&vdev->dev, vusb->nports,
> + sizeof(*vusb->vports), GFP_KERNEL);
[Severity: Medium]
Does this allocation need a bounds check?
The untrusted value 'vusb->nports' is read directly from the device config
space and passed to devm_kcalloc() with GFP_KERNEL.
Since there is no architectural cap checked, could a malicious host or
hypervisor supply a massive value (e.g., 100M) and trigger OOM killer
activity or large allocation warnings?
[ ... ]
> diff --git a/include/uapi/linux/virtio_usb.h b/include/uapi/linux/virtio_usb.h
> new file mode 100644
> index 0000000000000..b9dc448e38ef6
> --- /dev/null
> +++ b/include/uapi/linux/virtio_usb.h
[ ... ]
> +enum {
> + VIRTIO_USB_SPEED_UNKNOWN = 0,
> + VIRTIO_USB_SPEED_LOW,
> + VIRTIO_USB_SPEED_FULL, /* usb 1.1 */
> + VIRTIO_USB_SPEED_HIGH, /* usb 2.0 */
> + VIRTIO_USB_SPEED_WIRELESS, /* wireless (usb 2.5) */
> + VIRTIO_USB_USB_SPEED_SUPER, /* usb 3.0 */
[Severity: Low]
Is the "USB" prefix redundant here?
This defines VIRTIO_USB_USB_SPEED_SUPER instead of VIRTIO_USB_SPEED_SUPER,
breaking naming consistency and forcing userspace to use the flawed macro
name.
> + VIRTIO_USB_SPEED_SUPER_PLUS, /* usb 3.1 */
> +};
[ ... ]
> +struct virtio_usb_dev_cmd_hdr {
> + __le32 code; /* VIRTIO_USB_CMD_DEV_XXX */
> + __le16 port; /* Port ID */
> + __le16 endpoint; /* Endpoint ID */
> +};
[Severity: Medium]
Will this 16-bit port ID correctly route commands for all virtual ports?
Since 'virtio_usb_config.ports' and host UAPI structures define the port
count and IDs as 32-bit (__le32), a 16-bit port field here silently
truncates the index for any port >= 65536.
[ ... ]
> +struct virtio_usb_request {
> + __le64 tag;
> + __le16 port; /* Port ID */
> + __le16 endpoint; /* Endpoint ID */
> + __le16 transfer_type; /* VIRTIO_USB_EP_XXX */
> + __le16 transfer_flags; /* VIRTIO_USB_FLAG_XXX */
[Severity: Medium]
Similar to 'virtio_usb_dev_cmd_hdr' above, does this 16-bit port ID truncate
the 32-bit port index?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260924160907.145405-1-igor.skalkin@oss.qualcomm.com?part=1
next prev parent reply other threads:[~2026-09-24 16:23 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 16:08 [PATCH 0/8] virtio-usb: add dual-role virtio USB driver Igor Skalkin
2026-09-24 16:09 ` [PATCH 1/8] virtio-usb: add protocol header and skeleton dual-role driver Igor Skalkin
2026-09-24 16:23 ` sashiko-bot [this message]
2026-09-25 5:14 ` Greg Kroah-Hartman
2026-09-28 14:19 ` Igor Skalkin
2026-09-25 5:21 ` Greg Kroah-Hartman
2026-09-28 14:14 ` Igor Skalkin
2026-09-24 16:09 ` [PATCH 2/8] virtio-usb: add host role (USB Host Controller) support Igor Skalkin
2026-09-24 16:25 ` sashiko-bot
2026-09-25 5:18 ` Greg Kroah-Hartman
2026-09-28 14:01 ` Igor Skalkin
2026-09-24 16:09 ` [PATCH 3/8] virtio-usb: add device role (USB Device " Igor Skalkin
2026-09-24 16:28 ` sashiko-bot
2026-09-24 16:09 ` [PATCH 4/8] virtio-usb: add OTG role query support Igor Skalkin
2026-09-24 16:19 ` sashiko-bot
2026-09-24 16:09 ` [PATCH 5/8] virtio-usb: add USB On-The-Go role-switching support Igor Skalkin
2026-09-24 16:24 ` sashiko-bot
2026-09-24 16:09 ` [PATCH 6/8] virtio-usb: rework endpoint lifecycle to an async split-phase state machine Igor Skalkin
2026-09-24 16:30 ` sashiko-bot
2026-09-24 16:09 ` [PATCH 7/8] virtio-usb: add SuperSpeed device-role support Igor Skalkin
2026-09-24 16:35 ` sashiko-bot
2026-09-24 16:09 ` [PATCH 8/8] virtio-usb: support a guest UDC name prefix from the bind event Igor Skalkin
2026-09-24 16:35 ` sashiko-bot
2026-09-25 5:17 ` [PATCH 0/8] virtio-usb: add dual-role virtio USB driver Greg Kroah-Hartman
2026-09-28 13:55 ` Igor Skalkin
2026-09-28 14:44 ` Greg Kroah-Hartman
2026-09-28 15:56 ` Igor Skalkin
2026-09-28 16:10 ` Greg Kroah-Hartman
2026-09-29 9:47 ` Michael S. Tsirkin
2026-09-29 16:01 ` Greg Kroah-Hartman
2026-09-29 19:02 ` Vasilii Ianikeev
2026-09-29 19:58 ` Vasilii Ianikeev
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=20260924162339.7888C1F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=eperezma@redhat.com \
--cc=igor.skalkin@oss.qualcomm.com \
--cc=mst@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=virtualization@lists.linux.dev \
/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.