* [PATCH] USB: serial: cypress_m8: fix write URB double-submission race
@ 2026-12-05 17:00 YuanZhe Liu
2026-12-05 17:16 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: YuanZhe Liu @ 2026-12-05 17:00 UTC (permalink / raw)
To: Johan Hovold
Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, stable, Bin Yu,
Cheng Wen
cypress_send() is called from both the tty write path and the
interrupt-out URB completion handler. It uses priv->write_urb_in_use to
ensure that only one write URB is in flight, but the flag is tested in
one critical section and set again in another, after the shared
transfer buffer has been prepared.
Two concurrent callers can therefore both observe the flag as clear and
submit the same URB twice. The host controller then tracks two
transfer descriptors for one URB and the second urb_priv overwrites
urb->hcpriv. When the first transfer descriptor completes, the
giveback frees the second urb_priv while its transfer descriptor is
still queued on the endpoint ring. The next submission then writes
through the stale ring entry:
BUG: KASAN: slab-use-after-free in prepare_transfer
Write of size 8 at addr ffff888012dd1908
...
prepare_transfer
xhci_queue_bulk_tx
xhci_urb_enqueue
usb_hcd_submit_urb
cypress_send
cypress_write_int_callback
The stale transfer descriptor later causes a general protection fault
in xhci_td_cleanup().
Set write_urb_in_use while testing it, so that setting up the transfer
buffer and submitting the URB are covered by the same guard, and clear
it again when there is nothing to send.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
---
drivers/usb/serial/cypress_m8.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 78fb1389b34c..340863affc65 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -703,6 +703,7 @@ static void cypress_send(struct usb_serial_port *port)
spin_unlock_irqrestore(&priv->lock, flags);
return;
}
+ priv->write_urb_in_use = 1;
spin_unlock_irqrestore(&priv->lock, flags);
/* clear buffer */
@@ -739,8 +740,12 @@ static void cypress_send(struct usb_serial_port *port)
&port->interrupt_out_buffer[offset],
port->interrupt_out_size - offset,
&priv->lock);
- if (count == 0)
+ if (count == 0) {
+ spin_lock_irqsave(&priv->lock, flags);
+ priv->write_urb_in_use = 0;
+ spin_unlock_irqrestore(&priv->lock, flags);
return;
+ }
switch (priv->pkt_fmt) {
default:
@@ -754,10 +759,6 @@ static void cypress_send(struct usb_serial_port *port)
dev_dbg(dev, "%s - count is %d\n", __func__, count);
send:
- spin_lock_irqsave(&priv->lock, flags);
- priv->write_urb_in_use = 1;
- spin_unlock_irqrestore(&priv->lock, flags);
-
if (priv->cmd_ctrl)
actual_size = 1;
else
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] USB: serial: cypress_m8: fix write URB double-submission race
2026-12-05 17:00 [PATCH] USB: serial: cypress_m8: fix write URB double-submission race YuanZhe Liu
@ 2026-12-05 17:16 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-05 17:16 UTC (permalink / raw)
To: YuanZhe Liu; +Cc: linux-usb
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] usb: serial: cypress_m8: TX stall and lost cmd_ctrl race in
cypress_send()
--
commit 5eed4564631ae20c868d4673e55c2a40c9705ee0
Author: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
USB: serial: cypress_m8: fix write URB double-submission race
This commit sets priv->write_urb_in_use while checking it in
cypress_send() instead of waiting until the send label, and clears it
again if kfifo_out_locked() finds no data to transmit.
> diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
> index bd9b68b691de6..7b6cb9a04e41e 100644
> --- a/drivers/usb/serial/cypress_m8.c
> +++ b/drivers/usb/serial/cypress_m8.c
> @@ -703,6 +703,7 @@ static void cypress_send(struct usb_serial_port *port)
> spin_unlock_irqrestore(&priv->lock, flags);
> return;
> }
> + priv->write_urb_in_use = 1;
> spin_unlock_irqrestore(&priv->lock, flags);
>
> /* clear buffer */
> @@ -739,8 +740,12 @@ static void cypress_send(struct usb_serial_port *port)
> &port->interrupt_out_buffer[offset],
> port->interrupt_out_size - offset,
> &priv->lock);
> - if (count == 0)
> + if (count == 0) {
> + spin_lock_irqsave(&priv->lock, flags);
> + priv->write_urb_in_use = 0;
> + spin_unlock_irqrestore(&priv->lock, flags);
> return;
> + }
>
> switch (priv->pkt_fmt) {
> default:
[Severity: High]
Does this introduce a lost-wakeup race that leaves TX data stranded in
priv->write_fifo?
CPU0 CPU1
cypress_write_int_callback()
cypress_send()
lock(&priv->lock)
priv->write_urb_in_use = 1
unlock(&priv->lock)
...
kfifo_out_locked(...) == 0
cypress_write()
kfifo_in_locked(...)
cypress_send()
lock(&priv->lock)
write_urb_in_use != 0 <-- returns
unlock(&priv->lock)
lock(&priv->lock)
priv->write_urb_in_use = 0
unlock(&priv->lock)
return <-- TX data stranded
Because priv->lock is dropped before clearing priv->write_urb_in_use, CPU1
assumes an in-flight URB callback will drain the FIFO and returns early.
CPU0 then returns without submitting an URB, leaving the queued bytes
stranded indefinitely and hanging tcdrain() or port close.
The same window between checking priv->cmd_ctrl and clearing
priv->write_urb_in_use can also strand a concurrent line-control update
(such as from cypress_tiocmset()) with priv->cmd_ctrl left at 1 and no
URB in flight.
Holding priv->lock continuously across checking priv->write_urb_in_use,
checking priv->cmd_ctrl, and draining priv->write_fifo with kfifo_out(),
setting priv->write_urb_in_use = 1 only when there is work to submit,
would avoid both double submission and this stall.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205170022.4906-1-25031212351@stu.xidian.edu.cn?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 17:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 17:00 [PATCH] USB: serial: cypress_m8: fix write URB double-submission race YuanZhe Liu
2026-12-05 17:16 ` sashiko-bot
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.