Linux USB
 help / color / mirror / Atom feed
* [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

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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox