Linux CAN drivers development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Marc Kleine-Budde" <mkl@pengutronix.de>
Cc: "Oliver Hartkopp" <socketcan@hartkopp.net>,
	"Oleksij Rempel" <o.rempel@pengutronix.de>,
	linux-can@vger.kernel.org,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	"Vincent Mailhol" <mailhol@kernel.org>
Subject: Re: [PATCH can-next 10/10] can: gs_usb: gs_usb_get_minimum_rx_length(): enforce data_length of 8 bytes for CAN error frames
Date: Sat, 03 Oct 2026 23:05:25 +0000	[thread overview]
Message-ID: <20261003230525.B3E501F0089B@smtp.kernel.org> (raw)
In-Reply-To: <20261004-gs_usb-cleanups-and-fixes-v1-10-7b4b06244a77@pengutronix.de>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] can: gs_usb: valid CAN error frames dropped due to inflated minimum_length
- [Medium] can: gs_usb: missing cf->len update truncates CAN error frames
--

commit ee50d7ce750c8b15bfde5ea17af1803de6e6715b
Author: Marc Kleine-Budde <mkl@pengutronix.de>

can: gs_usb: gs_usb_get_minimum_rx_length(): enforce data_length of 8 bytes for CAN error frames

This commit updates the minimum RX length calculation for CAN error frames to
strictly expect 8 bytes of data. By definition, CAN error frames have a data
length of 8 bytes, so this aligns the data length calculation for error
frames with that specification.

> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> index 3c0464edb5d39..9ec6fed45b814 100644
> --- a/drivers/net/can/usb/gs_usb.c
> +++ b/drivers/net/can/usb/gs_usb.c
> @@ -576,8 +576,12 @@ gs_usb_get_minimum_rx_length(const struct gs_can *dev, const struct gs_host_fram
>  			minimum_length = sizeof(hf->header) + data_length;
>  	} else {
>  		if (hf->echo_id == GS_HOST_FRAME_ECHO_ID_RX &&
> -		    !(hf->can_id & cpu_to_le32(CAN_RTR_FLAG)))
> -			data_length = can_cc_dlc2len(hf->can_dlc);
> +		    !(hf->can_id & cpu_to_le32(CAN_RTR_FLAG))) {
> +			if (hf->can_id & cpu_to_le32(CAN_ERR_FLAG))
> +				data_length = CAN_ERR_DLC;
> +			else
> +				data_length = can_cc_dlc2len(hf->can_dlc);
> +		}

[Severity: High]
Does inflating data_length here cause valid, unpadded CAN error frames to
be discarded?

By forcing data_length to 8, the returned minimum_length will increase.
If a USB device sends a short, unpadded error frame where hf->can_dlc is
less than 8, the frame might be shorter than the newly inflated
minimum_length. The check in gs_usb_receive_bulk_callback() would then fail
and drop the frame:

gs_usb_receive_bulk_callback() {
    ...
    minimum_length = gs_usb_get_minimum_rx_length(dev, hf, &data_length);
    if (urb->actual_length < minimum_length) {
        stats->rx_errors++;
        stats->rx_length_errors++;
    ...
}

[Severity: Medium]
Could forcing data_length to 8 here also create a mismatch with cf->len
when the frame is constructed?

In gs_usb_receive_bulk_callback(), the frame length is initialized using the
unmodified hf->can_dlc, but the payload copying relies on data_length:

gs_usb_receive_bulk_callback() {
    ...
    can_frame_set_cc_len(cf, hf->can_dlc, dev->can.ctrlmode);
    ...
    memcpy(cf->data, hf->classic_can->data, data_length);
    ...
}

If the device sends an error frame with hf->can_dlc less than 8, data_length
is now forced to 8, meaning 8 bytes of payload are copied. However, cf->len
will be initialized to a value less than 8. This length mismatch would
truncate the error frame details exposed to the network stack and userspace
tools.

>  
>  		if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
>  			/* timestamp follows data field of max size */

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261004-gs_usb-cleanups-and-fixes-v1-0-7b4b06244a77@pengutronix.de?part=10

  reply	other threads:[~2026-10-03 23:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-03 22:53 [PATCH can-next 00/10] can: gs_usb: cleanups and fixes Marc Kleine-Budde
2026-10-03 22:53 ` [PATCH can-next 01/10] can: gs_usb: remove unused define GS_CAN_MODE_NORMAL Marc Kleine-Budde
2026-10-03 22:53 ` [PATCH can-next 02/10] can: gs_usb: replace all GS_CAN_MODE_* by GS_CAN_FEATURE_* Marc Kleine-Budde
2026-10-03 22:53 ` [PATCH can-next 03/10] can: gs_usb: gs_make_candev(): reduce scope of variable bt_const_extended Marc Kleine-Budde
2026-10-03 22:53 ` [PATCH can-next 04/10] can: gs_usb: gs_make_candev(): sort evaluation of device features Marc Kleine-Budde
2026-10-03 22:53 ` [PATCH can-next 05/10] can: gs_usb: gs_usb_receive_bulk_callback(): check for overflow flag if SKB allocation fails Marc Kleine-Budde
2026-10-05 12:13   ` netdev-bot+sashiko
2026-10-03 22:53 ` [PATCH can-next 06/10] can: gs_usb: gs_usb_receive_bulk_callback(): add missing call to can_rx_offload_irq_finish Marc Kleine-Budde
2026-10-05 12:13   ` netdev-bot+sashiko
2026-10-03 22:53 ` [PATCH can-next 07/10] can: gs_usb: gs_usb_receive_bulk_callback(): report channel number out of range error Marc Kleine-Budde
2026-10-05 12:13   ` netdev-bot+sashiko
2026-10-03 22:53 ` [PATCH can-next 08/10] can: gs_usb: gs_usb_receive_bulk_callback(): reduce scope of several variables Marc Kleine-Budde
2026-10-03 22:53 ` [PATCH can-next 09/10] can: gs_usb: gs_usb_receive_bulk_callback(): no need to assign CAN_ERR_DLC Marc Kleine-Budde
2026-10-03 22:53 ` [PATCH can-next 10/10] can: gs_usb: gs_usb_get_minimum_rx_length(): enforce data_length of 8 bytes for CAN error frames Marc Kleine-Budde
2026-10-03 23:05   ` sashiko-bot [this message]
2026-10-05 12:13   ` netdev-bot+sashiko

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=20261003230525.B3E501F0089B@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=o.rempel@pengutronix.de \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=socketcan@hartkopp.net \
    /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