Linux CAN drivers development
 help / color / mirror / Atom feed
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 12/13] can: gs_usb: gs_usb_host_frame_header_valid(): drop invalid CAN error frames
Date: Mon, 23 Nov 2026 12:00:31 +0000	[thread overview]
Message-ID: <179543523180.3131.8385656651883959137@kernel.org> (raw)
In-Reply-To: <20261121-gs_usb-fixes-v9-12-db121d488945@pengutronix.de>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · 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).

- [High] This patch adds an unprivileged local DoS that permanently
  wedges TX on the gs_usb CAN interface.
- [Low] The new netdev_err() format string in
  gs_usb_host_frame_header_valid() has a typo: "exptect_can_dlc" (should…

--

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

This commit adds two checks to gs_usb_host_frame_header_valid(). Frames
with CAN_ERR_FLAG set must have a DLC of CAN_ERR_DLC, and they must not
have CAN_RTR_FLAG set. If either check fails, the frame is dropped and
the URB is resubmitted.

> 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) {

[Severity: High]
This check only looks at CAN_ERR_FLAG and never at echo_id. Does it
also reject TX echo frames (echo_id < GS_MAX_TX_URBS) as well as real RX
frames?

On transmit, gs_can_start_xmit() copies the can_id and DLC from
userspace into the host frame unchanged:

    hf->can_id = cpu_to_le32(cf->can_id);
    hf->can_dlc = can_get_cc_dlc(cf, dev->can.ctrlmode);

The FD path does the same with can_fd_len2dlc(). The device sends this
header back as the echo.

A CAN_RAW socket needs no capability. Through one, a user can send a
frame with CAN_ERR_FLAG set and len != 8, or a frame with
CAN_ERR_FLAG | CAN_RTR_FLAG. Neither net/can nor can_dev_dropped_skb()
filters these on transmit.

When the echo arrives, gs_usb_receive_bulk_callback() does:

    data_length = gs_usb_get_rx_data_length(dev, hf, urb->actual_length);
    if (data_length < 0)
        goto resubmit_urb;

That jump skips the echo branch:

    gs_free_tx_context(txc);
    atomic_dec(&dev->active_tx_urbs);
    netif_wake_queue(netdev);

gs_usb_xmit_callback() returns early when urb->status == 0, so nothing
else releases the tx context or the echo skb.

After GS_MAX_TX_URBS such frames, every tx context is leaked, and
gs_can_start_xmit() has already stopped the queue:

    if (atomic_read(&dev->active_tx_urbs) >= GS_MAX_TX_URBS)
        netif_stop_queue(netdev);

Can anything wake the queue again before the interface is taken down and
brought back up? Until then no user can transmit, and the echo skbs stay
charged to the socket. Each rejected echo also bumps
rx_errors/rx_length_errors and logs an error. Before this patch, these
echoes completed normally.

The later patch in this series, "can: gs_usb:
gs_usb_host_frame_header_valid(): drop CAN frames with invalid DLC",
also leaves the CAN_ERR_FLAG block unconditional. The problem is
therefore still there at the end of the series.

Should these checks apply only when header->echo_id ==
GS_HOST_FRAME_ECHO_ID_RX, or should echo frames never be dropped by
payload validation?

> +			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",

[Severity: Low]
This isn't a bug, but there's a typo in the format string: "exptect_can_dlc"
should probably be "expected_can_dlc". It is still there at the end of the
series.

The commit message also says:

    ensure that the RTR flag is not sent.

Should that say "set"? The code checks that the RTR flag is not set in
the received header.

> +					   header->can_dlc, CAN_ERR_DLC);
> +
> +			valid = false;
> +		}
> +
> +		if (header->can_id & cpu_to_le32(CAN_RTR_FLAG)) {

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-gs_usb-fixes-v9-0-db121d488945%40pengutronix.de

  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 [this message]
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=179543523180.3131.8385656651883959137@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