Skip to content

Commit bd61ae8

Browse files
marckleinebuddegregkh
authored andcommitted
can: gs_usb: fix use of uninitialized variable, detach device on reception of invalid USB data
commit 4a8737f upstream. 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/20211210091158.408326-1-mkl@pengutronix.de Fixes: d08e973 ("can: gs_usb: Added support for the GS_USB CAN devices") Cc: stable@vger.kernel.org Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f68e600 commit bd61ae8

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎drivers/net/can/usb/gs_usb.c‎

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

321321
/* device reports out of range channel id */
322322
if (hf->channel >= GS_MAX_INTF)
323-
goto resubmit_urb;
323+
goto device_detach;
324324

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

@@ -405,6 +405,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
405405

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

0 commit comments

Comments
 (0)