Skip to content

Commit 4a8737f

Browse files
can: gs_usb: fix use of uninitialized variable, detach device on reception of invalid USB data
The received data contains the channel the received data is associated with. If the channel number is bigger than the actual number of channels assume broken or malicious USB device and shut it down. This fixes the error found by clang: | drivers/net/can/usb/gs_usb.c:386:6: error: variable 'dev' is used | uninitialized whenever 'if' condition is true | if (hf->channel >= GS_MAX_INTF) | ^~~~~~~~~~~~~~~~~~~~~~~~~~ | drivers/net/can/usb/gs_usb.c:474:10: note: uninitialized use occurs here | hf, dev->gs_hf_size, gs_usb_receive_bulk_callback, | ^~~ Link: https://lore.kernel.org/all/[email protected] Fixes: d08e973 ("can: gs_usb: Added support for the GS_USB CAN devices") Cc: [email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 1d5a474 commit 4a8737f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/net/can/usb/gs_usb.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
321321

322322
/* device reports out of range channel id */
323323
if (hf->channel >= GS_MAX_INTF)
324-
goto resubmit_urb;
324+
goto device_detach;
325325

326326
dev = usbcan->canch[hf->channel];
327327

@@ -406,6 +406,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
406406

407407
/* USB failure take down all interfaces */
408408
if (rc == -ENODEV) {
409+
device_detach:
409410
for (rc = 0; rc < GS_MAX_INTF; rc++) {
410411
if (usbcan->canch[rc])
411412
netif_device_detach(usbcan->canch[rc]->netdev);

0 commit comments

Comments
 (0)