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 checked 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(). Keep priv->lock across the in-use check, buffer setup, and draining of the write FIFO, and only set write_urb_in_use when a transfer is going to be submitted. Data and line-control updates are queued under the same lock, so a concurrent cypress_send() either makes it into this transfer or sees the flag clear and submits the data itself; no wakeup is lost, and the URB can no longer be submitted twice. 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> --- v2: Keep priv->lock across the in-use check, buffer setup and FIFO drain, and only set write_urb_in_use when a transfer is going to be submitted. Setting the flag before draining could strand data or line-control updates queued by a concurrent cypress_send(). drivers/usb/serial/cypress_m8.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c index 78fb1389b34c..560f25866d28 100644 --- a/drivers/usb/serial/cypress_m8.c +++ b/drivers/usb/serial/cypress_m8.c @@ -703,13 +703,11 @@ static void cypress_send(struct usb_serial_port *port) spin_unlock_irqrestore(&priv->lock, flags); return; } - spin_unlock_irqrestore(&priv->lock, flags); /* clear buffer */ memset(port->interrupt_out_urb->transfer_buffer, 0, port->interrupt_out_size); - spin_lock_irqsave(&priv->lock, flags); switch (priv->pkt_fmt) { default: case packet_format_1: @@ -730,17 +728,18 @@ static void cypress_send(struct usb_serial_port *port) if (priv->cmd_ctrl) { priv->cmd_count++; dev_dbg(dev, "%s - line control command being issued\n", __func__); + priv->write_urb_in_use = 1; spin_unlock_irqrestore(&priv->lock, flags); goto send; - } else - spin_unlock_irqrestore(&priv->lock, flags); + } - count = kfifo_out_locked(&priv->write_fifo, - &port->interrupt_out_buffer[offset], - port->interrupt_out_size - offset, - &priv->lock); - if (count == 0) + count = kfifo_out(&priv->write_fifo, + &port->interrupt_out_buffer[offset], + port->interrupt_out_size - offset); + if (count == 0) { + spin_unlock_irqrestore(&priv->lock, flags); return; + } switch (priv->pkt_fmt) { default: @@ -751,13 +750,12 @@ static void cypress_send(struct usb_serial_port *port) port->interrupt_out_buffer[0] |= count; } - 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); + dev_dbg(dev, "%s - count is %d\n", __func__, count); + +send: if (priv->cmd_ctrl) actual_size = 1; else -- 2.34.1