pcan_usb_pro_decode_buf() walks variable-sized records inside the bulk-in URB. Each iteration reads pr->data_type (the first byte of the record) and indexes pcan_usb_pro_sizeof_rec[] with it before checking that the announced record length fits within msg_end. When the URB length exactly equals PCAN_USBPRO_MSG_HEADER_LEN (4 bytes), pcan_msg_init() returns a rec_ptr that already equals msg_end while the on-wire rec_cnt field can still be non-zero. The first iteration then reads pr->data_type one byte past the URB buffer. A malicious USB device that pretends to be a PEAK-System PCAN-USB-Pro adapter (USB IDs 0c72:000c..0c72:0014 across the Pro and Pro-FD line) can keep returning short bulk-in URBs and trigger this read on every poll cycle, leaking one byte of adjacent slab content into the dispatch table lookup or producing a KASAN slab-out-of-bounds report. Apply the pattern from commit 6fe9f3279f7d ("can: gs_usb: gs_usb_receive_bulk_callback(): check actual_length before accessing header"): verify that at least one byte remains before dereferencing the record header. Identified by static analysis. No KASAN trip available without specific PEAK CAN-USB-Pro hardware. Fixes: d8a199355f8f ("can: usb: PEAK-System Technik PCAN-USB Pro specific part") Cc: stable@vger.kernel.org # 3.4+ Signed-off-by: Berkant Koc --- drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c index 4bfa8d0fbb32..f7b0304f7c37 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c @@ -715,8 +715,19 @@ static int pcan_usb_pro_decode_buf(struct peak_usb_device *dev, struct urb *urb) msg_end = urb->transfer_buffer + urb->actual_length; rec_cnt = le16_to_cpu(*usb_msg.u.rec_cnt_rd); for (; rec_cnt > 0; rec_cnt--) { - union pcan_usb_pro_rec *pr = (union pcan_usb_pro_rec *)rec_ptr; - u16 sizeof_rec = pcan_usb_pro_sizeof_rec[pr->data_type]; + union pcan_usb_pro_rec *pr; + u16 sizeof_rec; + + /* make sure data_type is readable before dereferencing it */ + if (rec_ptr >= msg_end) { + netdev_err(netdev, + "got frag rec: should inc usb rx buf size\n"); + err = -EBADMSG; + break; + } + + pr = (union pcan_usb_pro_rec *)rec_ptr; + sizeof_rec = pcan_usb_pro_sizeof_rec[pr->data_type]; if (!sizeof_rec) { netdev_err(netdev, -- 2.47.3