From: sashiko-bot@kernel.org
To: "Hongyu Xie" <xiehongyu1@kylinos.cn>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v3] usbip: vhci_hcd: time out unanswered unlink requests
Date: Fri, 27 Nov 2026 14:59:34 +0000 [thread overview]
Message-ID: <sashiko-outbox-237654@kernel.org> (raw)
In-Reply-To: <179579060266.47199.14552707473292683159@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] usbip: vhci_hcd: use-after-free of priv in vhci_urb_dequeue()
- [High] usbip: vhci_rx: premature unlink watchdog disarm in
vhci_recv_ret_submit()
--
commit 4a96b2f220c57ad22b859e73a1c3d66273ce70e1
Author: Hongyu Xie <xiehongyu1@kylinos.cn>
usbip: vhci_hcd: time out unanswered unlink requests
This commit adds per-request deadlines and a per-device watchdog timer for
queued CMD_UNLINK requests in vhci_hcd so unanswered unlinks tear down the
connection instead of hanging callers in usb_kill_urb().
Link: https://lore.kernel.org/all/1d6db53d-07ab-46ad-adc4-d09c95b2c83f@mail.kernel.org/
> diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
> index 39e8faf4c18cd..18a0d42ba3904 100644
> --- a/drivers/usb/usbip/vhci_hcd.c
> +++ b/drivers/usb/usbip/vhci_hcd.c
[ ... ]
> @@ -949,6 +1057,15 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
> struct vhci_unlink *unlink;
>
> spin_lock(&vdev->priv_lock);
> + if (!urb->hcpriv) {
> + /*
> + * URB was just picked up by vhci_rx and will be
> + * given back shortly; no CMD_UNLINK needed.
> + */
> + spin_unlock(&vdev->priv_lock);
> + spin_unlock_irqrestore(&vhci->lock, flags);
> + return 0;
> + }
[Severity: High]
Can vhci_urb_dequeue() already have dereferenced a freed priv before
reaching this !urb->hcpriv check?
pickup_urb_and_free_priv() runs under vdev->priv_lock without holding
vhci->lock, whereas vhci_urb_dequeue() reads urb->hcpriv and dereferences
priv->vdev under vhci->lock before taking vdev->priv_lock:
CPU0 CPU1 (vhci_rx)
vhci_urb_dequeue()
spin_lock_irqsave(&vhci->lock, ...)
priv = urb->hcpriv;
vhci_recv_ret_submit()
spin_lock_irqsave(&vdev->priv_lock, ...)
pickup_urb_and_free_priv()
list_del(&priv->list);
kfree(priv);
urb->hcpriv = NULL;
spin_unlock_irqrestore(&vdev->priv_lock, ...)
vdev = priv->vdev; <-- use-after-free
if (!vdev->ud.tcp_socket)
...
spin_lock(&vdev->priv_lock);
if (!urb->hcpriv)
In the !vdev->ud.tcp_socket branch above this block, urb->hcpriv is not
rechecked under vdev->priv_lock at all, so the same race also performs a
second list_del(&priv->list) and kfree(priv). Deriving vdev from
urb->dev->portnum (as vhci_urb_enqueue() does) and holding vdev->priv_lock
before reading urb->hcpriv would avoid touching a freed priv.
[ ... ]
> diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
> index a678e7c898375..c71645499a7b5 100644
> --- a/drivers/usb/usbip/vhci_rx.c
> +++ b/drivers/usb/usbip/vhci_rx.c
> @@ -63,6 +63,8 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
>
> spin_lock_irqsave(&vdev->priv_lock, flags);
> urb = pickup_urb_and_free_priv(vdev, pdu->base.seqnum);
> + if (urb)
> + vhci_complete_unlink_locked(vdev, pdu->base.seqnum);
> spin_unlock_irqrestore(&vdev->priv_lock, flags);
>
> if (!urb) {
[Severity: High]
Does calling vhci_complete_unlink_locked() here disarm vdev->unlink_timer
before the RET_SUBMIT payload has actually been received from the socket?
After releasing vdev->priv_lock, vhci_recv_ret_submit() still calls
usbip_recv_xbuff() and usbip_recv_iso(), which perform blocking
MSG_WAITALL reads on ud->tcp_socket before usb_hcd_giveback_urb() runs:
drivers/usb/usbip/vhci_rx.c:vhci_recv_ret_submit() {
...
/* recv transfer buffer */
if (usbip_recv_xbuff(ud, urb) < 0) {
urb->status = -EPROTO;
goto error;
}
/* recv iso_packet_descriptor */
if (usbip_recv_iso(ud, urb) < 0) {
urb->status = -EPROTO;
goto error;
}
...
}
If the peer stalls after sending the 48-byte RET_SUBMIT header without
sending the transfer buffer or ISO descriptors, vhci_rx blocks forever in
sock_recvmsg(). Because pickup_urb_and_free_priv() has already cleared
urb->hcpriv and vhci_complete_unlink_locked() has already cancelled the
watchdog for any earlier unlink, both pre-existing unlinks and any later
vhci_urb_dequeue() call from usb_kill_urb() are left with no active
watchdog timer, and usb_kill_urb() still hangs indefinitely.
--
Sashiko AI review · https://sashiko.dev/#/patchset/179579060266.47199.14552707473292683159@kylinos.cn?part=1
prev parent reply other threads:[~2026-11-27 14:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 14:43 [PATCH v3] usbip: vhci_hcd: time out unanswered unlink requests Hongyu Xie
2026-11-27 14:59 ` sashiko-bot [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=sashiko-outbox-237654@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=xiehongyu1@kylinos.cn \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox