Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: can: esd_usb2: check index of array before accessing

The esd_usb2_read_bulk_callback() function is parsing the data that comes from
the USB CAN adapter. One datum is used as an index to access the dev->nets[]
array. This patch adds the missing bounds checking.

Acked-by: Matthias Fuchs <matthias.fuchs@esd.eu>
Signed-off-by: Maximilian Schneider <max@schneidersoft.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Maximilian Schneider and committed by
Marc Kleine-Budde
233a26e8 ecb2cf1a

+10
+10
drivers/net/can/usb/esd_usb2.c
··· 412 412 413 413 switch (msg->msg.hdr.cmd) { 414 414 case CMD_CAN_RX: 415 + if (msg->msg.rx.net >= dev->net_count) { 416 + dev_err(dev->udev->dev.parent, "format error\n"); 417 + break; 418 + } 419 + 415 420 esd_usb2_rx_can_msg(dev->nets[msg->msg.rx.net], msg); 416 421 break; 417 422 418 423 case CMD_CAN_TX: 424 + if (msg->msg.txdone.net >= dev->net_count) { 425 + dev_err(dev->udev->dev.parent, "format error\n"); 426 + break; 427 + } 428 + 419 429 esd_usb2_tx_done_msg(dev->nets[msg->msg.txdone.net], 420 430 msg); 421 431 break;