]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
can: ucan: Fix infinite loop from zero-length messages
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 23 Feb 2026 16:30:20 +0000 (17:30 +0100)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Mon, 2 Mar 2026 10:03:42 +0000 (11:03 +0100)
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
0c73772cd2b8 ("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: 9f2d3eae88d2 ("can: ucan: add driver for Theobroma Systems UCAN devices")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/usb/ucan.c

index c79508b1c43e9720c08c219cf549dec7e40fc2c1..0ea0ac75e42f9a9b8e13a01b5b23d9fa051fdcc5 100644 (file)
@@ -748,7 +748,7 @@ static void ucan_read_bulk_callback(struct urb *urb)
                len = le16_to_cpu(m->len);
 
                /* check sanity (length of content) */
-               if (urb->actual_length - pos < len) {
+               if ((len == 0) || (urb->actual_length - pos < len)) {
                        netdev_warn(up->netdev,
                                    "invalid message (short; no data; l:%d)\n",
                                    urb->actual_length);