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 Signed-off-by: Bin Yu Co-developed-by: Cheng Wen Signed-off-by: Cheng Wen 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