Skip to content

Commit

Permalink
can: gs_usb: fix use of uninitialized variable, detach device on rece…
Browse files Browse the repository at this point in the history
…ption 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>
  • Loading branch information
marckleinebudde authored and gregkh committed Jan 16, 2022
1 parent 72bd750 commit 1026f71
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/net/can/usb/gs_usb.c
Expand Up @@ -321,7 +321,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)

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

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

Expand Down Expand Up @@ -406,6 +406,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)

/* USB failure take down all interfaces */
if (rc == -ENODEV) {
device_detach:
for (rc = 0; rc < GS_MAX_INTF; rc++) {
if (usbcan->canch[rc])
netif_device_detach(usbcan->canch[rc]->netdev);
Expand Down

0 comments on commit 1026f71

Please sign in to comment.