]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
USB: serial: cypress_m8: validate interrupt packet headers
authorZhang Cen <rollkingzzc@gmail.com>
Fri, 22 May 2026 14:54:42 +0000 (22:54 +0800)
committerJohan Hovold <johan@kernel.org>
Sat, 23 May 2026 07:35:26 +0000 (09:35 +0200)
cypress_read_int_callback() parses the interrupt-in buffer according to
the selected Cypress packet format. Format 1 has a two-byte status/count
header and format 2 has a one-byte combined status/count header. The
usb-serial core sizes the interrupt-in buffer from the endpoint
descriptor's wMaxPacketSize, and successful interrupt transfers can
complete short when URB_SHORT_NOT_OK is not set.

Check that the completed packet contains the selected header before
reading it. Malformed short reports are ignored and the interrupt URB is
resubmitted through the existing retry path, preventing out-of-bounds
header-byte reads.

KASAN report as below:
KASAN slab-out-of-bounds in cypress_read_int_callback+0x240/0x7f0
Read of size 1
Call trace:
  cypress_read_int_callback() (drivers/usb/serial/cypress_m8.c:1009)
  __usb_hcd_giveback_urb()
  dummy_timer()

Fixes: 3416eaa1f8f8 ("USB: cypress_m8: Packet format is separate from characteristic size")
Assisted-by: Codex:gpt-5.5
Signed-off-by: Zhang Cen <rollkingzzc@gmail.com>
Fixes: 3416eaa1f8f8 ("USB: cypress_m8: Packet format is separate from characteristic size")
Cc: stable@vger.kernel.org # 2.6.26
[ johan: use constants in header length sanity checks ]
Signed-off-by: Johan Hovold <johan@kernel.org>
drivers/usb/serial/cypress_m8.c

index 0b8a4e9d7bc5621e37ad0870bf6b22f3b6ce32b3..bcf302e88ca48f663cd9e6b9276f98c757071fa2 100644 (file)
@@ -1025,8 +1025,8 @@ static void cypress_read_int_callback(struct urb *urb)
        char tty_flag = TTY_NORMAL;
        int bytes = 0;
        int result;
-       int i = 0;
        int status = urb->status;
+       int i;
 
        switch (status) {
        case 0: /* success */
@@ -1064,22 +1064,32 @@ static void cypress_read_int_callback(struct urb *urb)
 
        spin_lock_irqsave(&priv->lock, flags);
        result = urb->actual_length;
+       i = 0;
        switch (priv->pkt_fmt) {
        default:
        case packet_format_1:
                /* This is for the CY7C64013... */
+               if (result < 2)
+                       break;
                priv->current_status = data[0] & 0xF8;
                bytes = data[1] + 2;
                i = 2;
                break;
        case packet_format_2:
                /* This is for the CY7C63743... */
+               if (result < 1)
+                       break;
                priv->current_status = data[0] & 0xF8;
                bytes = (data[0] & 0x07) + 1;
                i = 1;
                break;
        }
        spin_unlock_irqrestore(&priv->lock, flags);
+       if (i == 0) {
+               dev_dbg(dev, "%s - short packet received: %d bytes\n",
+                       __func__, result);
+               goto continue_read;
+       }
        if (result < bytes) {
                dev_dbg(dev,
                        "%s - wrong packet size - received %d bytes but packet said %d bytes\n",