]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
USB: serial: kl5kusb105: fix bulk-out buffer overflow
authorHyeongJun An <sammiee5311@gmail.com>
Mon, 8 Jun 2026 09:09:26 +0000 (18:09 +0900)
committerJohan Hovold <johan@kernel.org>
Mon, 8 Jun 2026 11:43:10 +0000 (13:43 +0200)
klsi_105_prepare_write_buffer() is called by the generic write path
with the bulk-out buffer and its size (bulk_out_size, 64 bytes). It
stores a two-byte length header at the start of the buffer and copies
the payload from the write fifo starting at buf + KLSI_HDR_LEN, but
passes the full buffer size as the number of bytes to copy:

  count = kfifo_out_locked(&port->write_fifo, buf + KLSI_HDR_LEN,
                           size, &port->lock);

When the fifo holds at least size bytes, size bytes are copied starting
two bytes into the size-byte buffer, writing KLSI_HDR_LEN bytes past its
end. Copy at most size - KLSI_HDR_LEN bytes instead, leaving room for
the header as safe_serial already does.

Writing bulk_out_size or more bytes to the tty triggers a slab
out-of-bounds write, observed with KASAN by emulating the device with
dummy_hcd and raw-gadget:

  BUG: KASAN: slab-out-of-bounds in kfifo_copy_out+0x83/0xc0
  Write of size 64 at addr ffff888112c62202 by task python3
   kfifo_copy_out
   klsi_105_prepare_write_buffer [kl5kusb105]
   usb_serial_generic_write_start [usbserial]
  Allocated by task 139:
   usb_serial_probe [usbserial]
  The buggy address is located 2 bytes inside of allocated 64-byte region

The out-of-bounds write no longer occurs with this change applied.

Fixes: 60b3013cdaf3 ("USB: kl5usb105: reimplement using generic framework")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: HyeongJun An <sammiee5311@gmail.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
drivers/usb/serial/kl5kusb105.c

index ed8531a647684f337cd2e222fa7392a6818e2d46..e72a0b45a70780a28a79a6b17454e4cc4d5e03c6 100644 (file)
@@ -330,8 +330,8 @@ static int klsi_105_prepare_write_buffer(struct usb_serial_port *port,
        unsigned char *buf = dest;
        int count;
 
-       count = kfifo_out_locked(&port->write_fifo, buf + KLSI_HDR_LEN, size,
-                                                               &port->lock);
+       count = kfifo_out_locked(&port->write_fifo, buf + KLSI_HDR_LEN,
+                                size - KLSI_HDR_LEN, &port->lock);
        put_unaligned_le16(count, buf);
 
        return count + KLSI_HDR_LEN;