From: netdev-bot+sashiko@kernel.org
To: mkl@pengutronix.de
Cc: mailhol@kernel.org, pfink@christ-es.de, eric@evenchick.com,
max@schneidersoft.net, wg@grandegger.com, kernel@pengutronix.de,
linux-can@vger.kernel.org, shuangpeng.kernel@gmail.com,
stable@vger.kernel.org, vadim.fedorenko@linux.dev,
kuba@kernel.org
Subject: Re: [PATCH can-next v9 13/13] can: gs_usb: gs_usb_host_frame_header_valid(): drop CAN frames with invalid DLC
Date: Mon, 23 Nov 2026 12:00:33 +0000 [thread overview]
Message-ID: <179543523333.3131.16865758831688588605@kernel.org> (raw)
In-Reply-To: <20261121-gs_usb-fixes-v9-13-db121d488945@pengutronix.de>
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The new DLC check in gs_usb_host_frame_header_valid()
(drivers/net/can/usb/gs_usb.c:666-678) ignores echo_id.
- [Low] The commit fixes a real contract violation that userspace can
see, but it has no Fixes: tag and the message does not state the…
- [Low] In gs_usb_host_frame_header_valid()
(drivers/net/can/usb/gs_usb.c), the new out-of-range DLC check (lines…
--
can: gs_usb: gs_usb_host_frame_header_valid(): drop CAN frames with invalid DLC
This patch adds a check to gs_usb_host_frame_header_valid() that rejects
any host frame with a DLC above 0xf. A rejected frame increments
rx_errors and rx_length_errors, logs a rate limited error and causes the
URB to be resubmitted.
Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261004-gs_usb-cleanups-and-fixes-v1-0-7b4b06244a77@pengutronix.de
> According to the respective CAN standards, the maximum DLC length for
> CAN-CC and CAN-FD frames is 0xf. The code in driver assumes that this limit
> has been verified.
[Severity: Low]
Should this have a Fixes: tag, and could the message state what goes
wrong without the check?
Before this patch, gs_usb_receive_bulk_callback() passed the
device-supplied hf->can_dlc directly to can_frame_set_cc_len(). That
call came in with commit 26949ac935e3 ("can: gs_usb: add CAN-FD
support"):
can_frame_set_cc_len(cf, hf->can_dlc, dev->can.ctrlmode);
The helper expects the caller to have checked the value already:
include/linux/can/length.h:can_frame_set_cc_len() {
/* the caller already ensured that dlc is a value from 0 .. 15 */
if (ctrlmode & CAN_CTRLMODE_CC_LEN8_DLC && dlc > CAN_MAX_DLEN)
cf->len8_dlc = dlc;
}
With CAN_CTRLMODE_CC_LEN8_DLC enabled, a len8_dlc above 15 could
therefore reach raw CAN socket users.
On the FD path, can_fd_dlc2len() does dlc2len[dlc & 0x0F]. A DLC such as
0x1f was silently turned into a valid 64 byte frame instead of being
rejected.
Other fixes in this series carry Fixes: and Cc: stable tags, for example
"can: gs_usb: gs_usb_receive_bulk_callback(): check for overflow flag if
SKB allocation fails". Would the same tags make sense here, so stable
backporters have something to go on?
> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> index a1192867e49b8..2da2f8843e5d5 100644
> --- a/drivers/net/can/usb/gs_usb.c
> +++ b/drivers/net/can/usb/gs_usb.c
> @@ -663,6 +663,20 @@ static bool gs_usb_host_frame_header_valid(const struct gs_can *dev,
> }
> }
>
> + /* we can check for max CAN-CC and CAN-FD DLC at the same time, they are both 0xf */
> + BUILD_BUG_ON(CAN_MAX_RAW_DLC != CANFD_MAX_DLC);
> + if (header->can_dlc > CAN_MAX_RAW_DLC) {
[Severity: Medium]
This check runs whatever header->echo_id is, so TX echo frames
(echo_id < GS_MAX_TX_URBS) with can_dlc > 15 are now rejected as well.
What happens to the pending TX context in that case?
gs_usb_get_rx_data_length() returns -EINVAL, and
gs_usb_receive_bulk_callback() then skips the echo completion branch:
gs_usb_receive_bulk_callback() {
...
data_length = gs_usb_get_rx_data_length(dev, hf, urb->actual_length);
if (data_length < 0)
goto resubmit_urb;
...
} else { /* echo_id == hf->echo_id */
txc = gs_get_tx_context(dev, hf->echo_id);
...
gs_free_tx_context(txc);
atomic_dec(&dev->active_tx_urbs);
netif_wake_queue(netdev);
}
...
}
The TX context slot and the echo skb that gs_can_start_xmit() stored
with can_put_echo_skb() then stay held until gs_can_close(). The
active_tx_urbs count is never decremented either. The driver has no
ndo_tx_timeout or other recovery path.
After GS_MAX_TX_URBS such echoes, gs_alloc_tx_context() fails and
gs_can_start_xmit() returns NETDEV_TX_BUSY. Once the leaked
active_tx_urbs count reaches GS_MAX_TX_URBS, gs_can_start_xmit() stops
the queue and nothing wakes it. TX then stalls until the interface is
taken down and brought back up.
Echo frames never use can_dlc. gs_usb_get_minimum_rx_length() only
converts the DLC to a length for echo_id == GS_HOST_FRAME_ECHO_ID_RX,
and the echo path takes its data from dev->can.echo_skb[]. Before this
patch, an echo with a bogus can_dlc completed normally.
Could the DLC check be limited to echo_id == GS_HOST_FRAME_ECHO_ID_RX?
> + stats->rx_errors++;
> + stats->rx_length_errors++;
[Severity: Low]
Can error frames be counted twice here? Take a frame with CAN_ERR_FLAG
set and can_dlc > 15, for example 0x20. The existing check earlier in
gs_usb_host_frame_header_valid() already fires for it:
if (header->can_id & cpu_to_le32(CAN_ERR_FLAG)) {
if (header->can_dlc != CAN_ERR_DLC) {
stats->rx_errors++;
stats->rx_length_errors++;
Nothing skips the new check once valid is false, so both counters are
incremented again. That one dropped frame adds 2 to rx_length_errors
and at least 2 to rx_errors.
struct rtnl_link_stats64 in include/uapi/linux/if_link.h documents both
counters as counting packets, not individual validation failures.
> +
> + if (net_ratelimit())
> + netdev_err(netdev,
> + "out of range DLC (can_dlc=%u, max_can_dlc=%u)\n",
> + header->can_dlc, CAN_MAX_RAW_DLC);
> +
> + valid = false;
> + }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-gs_usb-fixes-v9-0-db121d488945%40pengutronix.de
prev parent reply other threads:[~2026-11-23 12:00 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 22:35 [PATCH can-next v9 00/13] gs_usb: fixes Marc Kleine-Budde
2026-11-21 22:35 ` [PATCH can-next v9 01/13] can: gs_usb: gs_usb_probe(): init netdev completely before register_candev() Marc Kleine-Budde
2026-11-21 22:36 ` [PATCH can-next v9 02/13] can: gs_usb: gs_usb_receive_bulk_callback(): check for overflow flag if SKB allocation fails Marc Kleine-Budde
2026-11-21 22:36 ` [PATCH can-next v9 03/13] can: gs_usb: gs_usb_receive_bulk_callback(): add missing call to can_rx_offload_irq_finish Marc Kleine-Budde
2026-11-21 22:36 ` [PATCH can-next v9 04/13] can: gs_usb: use spin_lock_irqsave() instead of spin_lock_bh() to protect struct gs_usb::tc Marc Kleine-Budde
2026-11-21 22:36 ` [PATCH can-next v9 05/13] can: gs_usb: fix hardware timestamp state for mixed channels Marc Kleine-Budde
2026-11-21 22:43 ` sashiko-bot
2026-11-23 12:00 ` netdev-bot+sashiko
2026-11-21 22:36 ` [PATCH can-next v9 06/13] can: gs_usb: add support for context analysis Marc Kleine-Budde
2026-11-21 22:42 ` sashiko-bot
2026-11-23 12:00 ` netdev-bot+sashiko
2026-11-21 22:36 ` [PATCH can-next v9 07/13] can: gs_usb: gs_make_candev(): check can_rx_offload_add_manual() return value Marc Kleine-Budde
2026-11-21 22:36 ` [PATCH can-next v9 08/13] can: gs_usb: gs_usb_receive_bulk_callback(): use dev_info() to print re-submit info messages Marc Kleine-Budde
2026-11-21 22:42 ` sashiko-bot
2026-11-23 12:00 ` netdev-bot+sashiko
2026-11-21 22:36 ` [PATCH can-next v9 09/13] can: gs_usb: gs_usb_get_gs_can(): introduce new function to consolidate validation of struct gs_can Marc Kleine-Budde
2026-11-23 12:00 ` netdev-bot+sashiko
2026-11-21 22:36 ` [PATCH can-next v9 10/13] can: gs_usb: gs_usb_get_gs_can(): report channel number out of range error Marc Kleine-Budde
2026-11-23 12:00 ` netdev-bot+sashiko
2026-11-21 22:36 ` [PATCH can-next v9 11/13] can: gs_usb: gs_usb_get_rx_data_length(): introduce new function to consolidate validation of host frame Marc Kleine-Budde
2026-11-23 12:00 ` netdev-bot+sashiko
2026-11-21 22:36 ` [PATCH can-next v9 12/13] can: gs_usb: gs_usb_host_frame_header_valid(): drop invalid CAN error frames Marc Kleine-Budde
2026-11-21 22:53 ` sashiko-bot
2026-11-21 23:02 ` Marc Kleine-Budde
2026-11-23 7:41 ` Marc Kleine-Budde
2026-11-23 12:00 ` netdev-bot+sashiko
2026-11-21 22:36 ` [PATCH can-next v9 13/13] can: gs_usb: gs_usb_host_frame_header_valid(): drop CAN frames with invalid DLC Marc Kleine-Budde
2026-11-23 12:00 ` netdev-bot+sashiko [this message]
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=179543523333.3131.16865758831688588605@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=eric@evenchick.com \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=max@schneidersoft.net \
--cc=mkl@pengutronix.de \
--cc=pfink@christ-es.de \
--cc=shuangpeng.kernel@gmail.com \
--cc=stable@vger.kernel.org \
--cc=vadim.fedorenko@linux.dev \
--cc=wg@grandegger.com \
/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