* Re: [PATCH can-next v9 12/13] can: gs_usb: gs_usb_host_frame_header_valid(): drop invalid CAN error frames
[not found] <20261121-gs_usb-fixes-v9-12-db121d488945@pengutronix.de>
@ 2026-11-23 12:00 ` netdev-bot+sashiko
0 siblings, 0 replies; only message in thread
From: netdev-bot+sashiko @ 2026-11-23 12:00 UTC (permalink / raw)
To: mkl
Cc: mailhol, pfink, eric, max, wg, kernel, linux-can,
shuangpeng.kernel, stable, vadim.fedorenko, kuba
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
^ permalink raw reply [flat|nested] only message in thread