From: Yiran Qiu <eritque-arcus@ikuyo.dev>
To: Frank Jungclaus <frank.jungclaus@esd.eu>,
socketcan@esd.eu, Marc Kleine-Budde <mkl@pengutronix.de>,
Vincent Mailhol <mailhol@kernel.org>
Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org,
Yiran Qiu <eritque-arcus@ikuyo.dev>,
stable@vger.kernel.org
Subject: [PATCH 2/2] can: kvaser_usb_hydra: reject too-short commands in the receive path
Date: Sat, 15 Aug 2026 02:05:47 +0800 [thread overview]
Message-ID: <20260815-can-esd-hydra-fixes-v1-2-de644cbeaec2@ikuyo.dev> (raw)
In-Reply-To: <20260815-can-esd-hydra-fixes-v1-0-de644cbeaec2@ikuyo.dev>
kvaser_usb_hydra_read_bulk_callback() walks commands out of the RX URB
buffer, using kvaser_usb_hydra_cmd_size() to determine each command's
length. For an extended command (CMD_EXTENDED) that size is taken
directly from the device-supplied 16-bit length field with no lower
bound. A CMD_EXTENDED command whose length is zero makes cmd_size 0, so
"pos += cmd_len" never advances and this URB-completion softirq spins
forever.
Reject a command whose reported size is smaller than the command header
before it is dispatched, mirroring the minimum-length check added in
commit 0293dd153f9d ("can: kvaser_usb_leaf: kvaser_usb_leaf_wait_cmd():
validate received command extents"); that fix did not touch hydra's
asynchronous read_bulk_callback().
Reproduced with USB_RAW_GADGET + dummy_hcd on a KASAN build: after the
normal probe/START_CHIP handshake, a 6-byte CMD_EXTENDED frame with the
length field set to 0 makes the callback loop print
kvaser_usb 1-1:1.0: Unhandled extended command (255)
without bound (306000 times in ~75 s), until
rcu: INFO: rcu_sched detected stalls on CPUs/tasks:
and the machine had to be killed externally.
Fixes: aec5fb2268b5 ("can: kvaser_usb: Add support for Kvaser USB hydra family")
Cc: stable@vger.kernel.org
Signed-off-by: Yiran Qiu <eritque-arcus@ikuyo.dev>
---
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
index efbb7bed34c9d..d44f9875fbe2f 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
@@ -2156,6 +2156,15 @@ static void kvaser_usb_hydra_read_bulk_callback(struct kvaser_usb *dev,
cmd_len = kvaser_usb_hydra_cmd_size(cmd);
+ /* An extended command carries a device-supplied length; a
+ * command shorter than the command header would never advance
+ * @pos and would spin this URB-completion softirq forever.
+ */
+ if (cmd_len < sizeof(struct kvaser_cmd_header)) {
+ dev_err(&dev->intf->dev, "Format error\n");
+ break;
+ }
+
if (pos + cmd_len > len) {
/* We got first part of a command */
int leftover_bytes;
--
2.55.0
next prev parent reply other threads:[~2026-08-14 18:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-14 18:05 [PATCH 0/2] can: fix two missed siblings of the kvaser_usb_leaf receive-walk fix Yiran Qiu
2026-08-14 18:05 ` [PATCH 1/2] can: esd_usb: validate received message length before use Yiran Qiu
2026-08-14 18:05 ` Yiran Qiu [this message]
2026-09-16 18:18 ` [PATCH 2/2] can: kvaser_usb_hydra: reject too-short commands in the receive path eritque-arcus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260815-can-esd-hydra-fixes-v1-2-de644cbeaec2@ikuyo.dev \
--to=eritque-arcus@ikuyo.dev \
--cc=frank.jungclaus@esd.eu \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=socketcan@esd.eu \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®