All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Marc Kleine-Budde" <mkl@pengutronix.de>
Cc: linux-can@vger.kernel.org,
	"Oliver Hartkopp" <socketcan@hartkopp.net>,
	"Vincent Mailhol" <mailhol@kernel.org>,
	"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH can-next v9 12/13] can: gs_usb: gs_usb_host_frame_header_valid(): drop invalid CAN error frames
Date: Sat, 21 Nov 2026 22:53:55 +0000	[thread overview]
Message-ID: <sashiko-outbox-227474@kernel.org> (raw)
In-Reply-To: <20261121-gs_usb-fixes-v9-12-db121d488945@pengutronix.de>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] can: gs_usb: TX context and echo skb leak on echoed
  CAN_ERR_FLAG frames
--

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

can: gs_usb: gs_usb_host_frame_header_valid(): drop invalid CAN error frames

This commit validates incoming CAN error frame headers in
gs_usb_host_frame_header_valid(), rejecting frames with CAN_ERR_FLAG set
if can_dlc is not CAN_ERR_DLC or if CAN_RTR_FLAG is set.

> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> index e4e177aee48b0..a1192867e49b8 100644
> --- a/drivers/net/can/usb/gs_usb.c
> +++ b/drivers/net/can/usb/gs_usb.c
> @@ -639,6 +639,30 @@ static bool gs_usb_host_frame_header_valid(const struct gs_can *dev,
>  		valid = false;
>  	}
>  
> +	if (header->can_id & cpu_to_le32(CAN_ERR_FLAG)) {
> +		if (header->can_dlc != CAN_ERR_DLC) {
> +			stats->rx_errors++;
> +			stats->rx_length_errors++;
> +
> +			if (net_ratelimit())
> +				netdev_err(netdev,
> +					   "invalid DLC in CAN error frame (can_dlc=%u, exptect_can_dlc=%u)\n",
> +					   header->can_dlc, CAN_ERR_DLC);
> +
> +			valid = false;
> +		}
> +
> +		if (header->can_id & cpu_to_le32(CAN_RTR_FLAG)) {
> +			stats->rx_errors++;
> +
> +			if (net_ratelimit())
> +				netdev_err(netdev,
> +					   "invalid RTR flag in CAN error frame\n");
> +
> +			valid = false;
> +		}
> +	}
> +
>  	return valid;
>  }

[Severity: Medium]
Can this leak txc and dev->can.echo_skb[hf->echo_id] when a transmitted
frame with CAN_ERR_FLAG set is echoed back by the device?

The TX path and gs_can_start_xmit() do not mask out or reject
CAN_ERR_FLAG in cf->can_id before allocating a TX context and storing the
echo skb.  When the device echoes that TX frame back with
header->echo_id < GS_MAX_TX_URBS, gs_usb_receive_bulk_callback() calls
gs_usb_get_rx_data_length() -> gs_usb_host_frame_header_valid() before
branching on hf->echo_id == GS_HOST_FRAME_ECHO_ID_RX.  If can_dlc !=
CAN_ERR_DLC or CAN_RTR_FLAG is set, gs_usb_receive_bulk_callback() jumps
to resubmit_urb without calling gs_free_tx_context(), consuming the echo
skb, or decrementing dev->active_tx_urbs, which permanently exhausts all
GS_MAX_TX_URBS slots and stalls the TX queue after 10 such frames.

Should this check be gated on header->echo_id == GS_HOST_FRAME_ECHO_ID_RX
(or should gs_can_start_xmit() reject or strip CAN_ERR_FLAG on TX)?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261121-gs_usb-fixes-v9-0-db121d488945@pengutronix.de?part=12

  reply	other threads:[~2026-11-21 22:53 UTC|newest]

Thread overview: 32+ 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-23 16:59     ` Marc Kleine-Budde
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-24  9:45   ` Vincent Donnefort
2026-11-24  9:46     ` Vincent Donnefort
2026-11-24  9:59     ` Marc Kleine-Budde
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 [this message]
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

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=sashiko-outbox-227474@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.