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, stable@vger.kernel.org,
kuba@kernel.org
Subject: Re: [PATCH can-next v10 14/14] can: gs_usb: gs_usb_host_frame_header_valid(): drop CAN frames with invalid DLC
Date: Tue, 24 Nov 2026 09:31:06 +0000 [thread overview]
Message-ID: <179551266677.3131.6488994858051921423@kernel.org> (raw)
In-Reply-To: <20261122-gs_usb-fixes-v10-14-7c165c35d04a@pengutronix.de>
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
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] In gs_usb_host_frame_header_valid()
(drivers/net/can/usb/gs_usb.c), an RX CAN error frame (CAN_ERR_FLAG…
- [Low] The commit "can: gs_usb: gs_usb_host_frame_header_valid(): drop
CAN frames with invalid DLC" fixes a user-visible bug that comes from…
--
can: gs_usb: gs_usb_host_frame_header_valid(): drop CAN frames with invalid DLC
This commit adds a check to gs_usb_host_frame_header_valid() that drops
received CAN frames with a DLC above 0xf. It updates the rx error
counters, logs a rate-limited error and resubmits the URB.
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.
>
> Drop CAN frames with DLC > 0xf, print a error message and resubmit the URB.
[Severity: Low]
Should this patch have a Fixes: tag and Cc: stable? The commit message
also doesn't say what goes wrong without the check.
Before this patch, gs_usb_receive_bulk_callback() passed the raw device
DLC to the helper unchecked:
can_frame_set_cc_len(cf, hf->can_dlc, dev->can.ctrlmode);
The helper in include/linux/can/length.h assumes the range has already
been checked:
/* 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 USB device sending can_dlc
0x10..0xff gives userspace a struct can_frame with len8_dlc above
CAN_MAX_RAW_DLC. For CAN-FD, can_fd_dlc2len() masks the DLC with 0x0F, so
a DLC of 0x1X is accepted with a different payload length.
gs_make_candev() has advertised CAN_CTRLMODE_CC_LEN8_DLC since commit
4c01fc87675e ("can: drivers: add len8_dlc support for various CAN
adapters"). That commit looks like a reasonable Fixes: target.
Other gs_usb fixes in the same series carry Fixes: and Cc: stable, for
example "can: gs_usb: gs_usb_receive_bulk_callback(): add missing call to
can_rx_offload_irq_finish". Could this one get the same tags, plus a
sentence on the user-visible effect?
> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> index 7229d002b938a..5e8ea308fabf5 100644
> --- a/drivers/net/can/usb/gs_usb.c
> +++ b/drivers/net/can/usb/gs_usb.c
> @@ -668,6 +668,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) {
> + stats->rx_errors++;
> + stats->rx_length_errors++;
[Severity: Medium]
Can a single error frame be counted twice here?
Take an RX frame with CAN_ERR_FLAG set in can_id and can_dlc in 16..255.
The existing error-frame block earlier in
gs_usb_host_frame_header_valid() already counts it and keeps going
instead of returning:
if (header->can_id & cpu_to_le32(CAN_ERR_FLAG)) {
if (header->can_dlc != CAN_ERR_DLC) {
stats->rx_errors++;
stats->rx_length_errors++;
...
valid = false;
}
This new check then runs for the same frame and increments rx_errors and
rx_length_errors again. It also logs a second error message.
gs_usb_get_rx_data_length() drops exactly one frame here, but both
counters go up by 2. If CAN_RTR_FLAG is also set, rx_errors goes up
by 3.
include/uapi/linux/if_link.h defines rx_length_errors as "Number of
packets dropped due to invalid length", so this would over-count.
Would it work to make the new range check an else branch of the
error-frame DLC check? Another option is to update the counters once at
the end of the function when valid is false.
> +
> + 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;
> + }
> +
> return valid;
> }
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122-gs_usb-fixes-v10-0-7c165c35d04a%40pengutronix.de
parent reply other threads:[~2026-11-24 9:31 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20261122-gs_usb-fixes-v10-14-7c165c35d04a@pengutronix.de>]
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=179551266677.3131.6488994858051921423@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=stable@vger.kernel.org \
--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