Skip to content

Commit 1e446fd

Browse files
gregkhmarckleinebudde
authored andcommitted
can: ucan: Fix infinite loop from zero-length messages
If a broken ucan device gets a message with the message length field set to 0, then the driver will loop for forever in ucan_read_bulk_callback(), hanging the system. If the length is 0, just skip the message and go on to the next one. This has been fixed in the kvaser_usb driver in the past in commit 0c73772 ("can: kvaser_usb: leaf: Fix potential infinite loop in command parsers"), so there must be some broken devices out there like this somewhere. Cc: Marc Kleine-Budde <mkl@pengutronix.de> Cc: Vincent Mailhol <mailhol@kernel.org> Cc: stable@kernel.org Assisted-by: gkh_clanker_2000 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://patch.msgid.link/2026022319-huff-absurd-6a18@gregkh Fixes: 9f2d3ea ("can: ucan: add driver for Theobroma Systems UCAN devices") Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
1 parent 38a01c9 commit 1e446fd

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/net/can/usb/ucan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ static void ucan_read_bulk_callback(struct urb *urb)
748748
len = le16_to_cpu(m->len);
749749

750750
/* check sanity (length of content) */
751-
if (urb->actual_length - pos < len) {
751+
if ((len == 0) || (urb->actual_length - pos < len)) {
752752
netdev_warn(up->netdev,
753753
"invalid message (short; no data; l:%d)\n",
754754
urb->actual_length);

0 commit comments

Comments
 (0)