From: netdev-bot+sashiko@kernel.org
To: stephane.grosjean@free.fr
Cc: mkl@pengutronix.de, mailhol@kernel.org, error27@gmail.com,
wg@grandegger.com, s.grosjean@peak-system.fr,
linux-can@vger.kernel.org, linux-kernel@vger.kernel.org,
kuba@kernel.org
Subject: Re: [PATCH v4 07/10] can: peak_usb: fix RX cursor desync for self-received RTR frames with SRR
Date: Thu, 22 Oct 2026 00:29:25 +0000 [thread overview]
Message-ID: <179262896579.3131.4160814028534799667@kernel.org> (raw)
In-Reply-To: <20261020-canfd_check_channel_idx-v4-7-bfbde81f8bab@peak-system.fr>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
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] This patch adds an error-path stats regression in
pcan_usb_decode_data() (drivers/net/can/usb/peak_usb/pcan_usb.c).
--
can: peak_usb: fix RX cursor desync for self-received RTR frames with SRR
This commit moves the SRR private id byte skip in pcan_usb_decode_data()
out of the non-RTR branch. The byte is now consumed whenever
PCAN_USB_TX_SRR is set, which matches the layout used by
pcan_usb_encode_msg() and stops the RX cursor desync for self-received
RTR frames.
> diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
> index 93da0fd4f10e7..4c8cfed31634a 100644
> --- a/drivers/net/can/usb/peak_usb/pcan_usb.c
> +++ b/drivers/net/can/usb/peak_usb/pcan_usb.c
> @@ -697,16 +697,19 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len)
> memcpy(cf->data, mc->ptr, cf->len);
> mc->ptr += rec_len;
>
> - /* Ignore next byte (client private id) if SRR bit is set */
> - if (can_id_flags & PCAN_USB_TX_SRR) {
> - if ((mc->ptr + 1) > mc->end)
> - goto decode_failed;
> - mc->ptr++;
> - }
> -
> /* update statistics */
> mc->netdev->stats.rx_bytes += cf->len;
> }
> +
> + /* Ignore next byte (client private id) if SRR bit is set.
> + * Note: this test must be done even when the frame is an RTR frame.
> + */
> + if (can_id_flags & PCAN_USB_TX_SRR) {
> + if ((mc->ptr + 1) > mc->end)
> + goto decode_failed;
> + mc->ptr++;
> + }
> +
> mc->netdev->stats.rx_packets++;
[Severity: Medium]
Can this leave rx_bytes counting a frame that gets dropped?
Before this patch, the SRR bounds check ran inside the non-RTR branch,
ahead of the rx_bytes update. Now rx_bytes is updated first, and the
check comes after it.
Take a non-RTR record that has PCAN_USB_TX_SRR set and a non-zero
payload ending exactly at mc->end, so the private id byte is missing.
In pcan_usb_decode_data():
mc->ptr += rec_len;
...
mc->netdev->stats.rx_bytes += cf->len;
}
...
if (can_id_flags & PCAN_USB_TX_SRR) {
if ((mc->ptr + 1) > mc->end)
goto decode_failed;
decode_failed frees the skb and returns -EINVAL. No frame is delivered
and rx_packets is not incremented, but the rx_bytes increment of up to
8 bytes is kept.
The device firmware controls this data, so a faulty or malicious USB
device could trigger it through:
peak_usb_read_bulk_callback()->pcan_usb_decode_buf()->
pcan_usb_decode_msg()->pcan_usb_decode_data()
Would it work to do the non-RTR rx_bytes update after the shared SRR
check succeeds? For example, next to rx_packets++ and guarded by
!(status_len & PCAN_USB_STATUSLEN_RTR).
>
> /* convert timestamp into kernel time */
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261020-canfd_check_channel_idx-v4-0-bfbde81f8bab%40peak-system.fr
next prev parent reply other threads:[~2026-10-22 0:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 10:40 [PATCH v4 00/10] can: peak_usb: fixes, cleanup and input validation hardening Stéphane Grosjean
2026-10-20 10:40 ` [PATCH v4 01/10] can: peak_usb: fix missing CAN_ERR_FLAG when reporting error counters Stéphane Grosjean
2026-10-20 10:40 ` [PATCH v4 02/10] can: peak_usb: add missing includes Stéphane Grosjean
2026-10-20 10:40 ` [PATCH v4 03/10] can: peak_usb: sort ctrlmode_supported flags Stéphane Grosjean
2026-10-20 10:40 ` [PATCH v4 04/10] can: peak_usb: harden PCAN-USB message validation Stéphane Grosjean
2026-10-20 10:40 ` [PATCH v4 05/10] can: peak_usb: replace open-coded bitmask operations with bitops Stéphane Grosjean
2026-10-20 10:40 ` [PATCH v4 06/10] can: peak_usb: harden channel handling in PCAN-USB FD Stéphane Grosjean
2026-10-22 0:29 ` netdev-bot+sashiko
2026-10-20 10:40 ` [PATCH v4 07/10] can: peak_usb: fix RX cursor desync for self-received RTR frames with SRR Stéphane Grosjean
2026-10-22 0:29 ` netdev-bot+sashiko [this message]
2026-10-20 10:40 ` [PATCH v4 08/10] can: peak_usb: reject records for unset channels in PCAN-USB Pro Stéphane Grosjean
2026-10-22 0:29 ` netdev-bot+sashiko
2026-10-20 10:40 ` [PATCH v4 09/10] can: peak_usb: register the netdev only once the channel is set up Stéphane Grosjean
2026-10-22 0:29 ` netdev-bot+sashiko
2026-10-20 10:40 ` [PATCH v4 10/10] can: peak_usb: only dump received bytes on decode error Stéphane Grosjean
2026-10-22 0:29 ` 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=179262896579.3131.4160814028534799667@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=error27@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=s.grosjean@peak-system.fr \
--cc=stephane.grosjean@free.fr \
--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
all inboxes | Powered by JetHome®