* [PATCH v5 00/10] can: peak_usb: fixes, cleanup and input validation hardening
@ 2026-10-20 13:30 Stéphane Grosjean via B4 Relay
2026-10-20 13:30 ` [PATCH v5 01/10] can: peak_usb: fix missing CAN_ERR_FLAG when reporting error counters Stéphane Grosjean via B4 Relay
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Stéphane Grosjean via B4 Relay @ 2026-10-20 13:30 UTC (permalink / raw)
To: Marc Kleine-Budde, Vincent Mailhol, Dan Carpenter,
Wolfgang Grandegger
Cc: Stéphane Grosjean, linux-can, linux-kernel,
Stefan Günther, stable
This series contains bug fixes, cleanups and input validation
improvements for the PEAK-System USB CAN drivers.
Patch 1 fixes CAN error frame generation, where CAN_ERR_CNT overwrote
previously set CAN error flags.
Patches 2, 3 and 5 are cleanups: make a public header self-contained,
sort the CAN_CTRLMODE_* flags in ctrlmode_supported, and replace
open-coded bitmask operations with bitops. Patch 5 also makes the
state flag updates atomic, which patch 6 relies on.
Patch 4 adds bounds checks to the PCAN-USB RX parser, so that
truncated or malformed records are rejected instead of being read
beyond the received data.
Patch 6 validates the channel numbers received from PCAN-USB FD
devices, rejects records for channels that are not set up, and stops
RX on all channels before they are released, on disconnect as well as
on probe failure.
Patch 7 fixes the RX parsing of self-received RTR frames with SRR set,
which left the RX cursor one byte behind.
Patches 8 to 10 fix related issues found while reviewing the above:
the same channel slot check in the PCAN-USB Pro driver, the netdevs
being registered before their channels are initialized, and the dump of
stale RX buffer bytes on decode errors.
---
Changes in v5:
- Register the netdevs only once all the channels of the interface are
initialized, since they share resources during the init of a sibling
(patch 9).
- Link to v4: https://lore.kernel.org/r/20261020-canfd_check_channel_idx-v4-0-bfbde81f8bab@peak-system.fr
Changes in v4:
- Register the netdev only once the channel is initialized, instead of
only reordering unregister_candev() and dev_free() on probe failure
(patch 9).
- Link to v3: https://lore.kernel.org/r/20261020-canfd_check_channel_idx-v3-0-74d17c5a599e@peak-system.fr
Changes in v3:
- Fix out-of-bounds read of the error counters in PCAN-USB bus events.
- Harden channel handling in PCAN-USB FD: publish/read channel slots
with smp_store_release()/READ_ONCE(), clear them on teardown, stop RX
on all channels on disconnect and on the siblings on probe failure,
and reject ndo_open() once disconnected.
- Fix RX cursor desync for self-received RTR frames with SRR.
- Replace open-coded bitmask operations with bitops.
- Add channel slot checks to PCAN-USB Pro.
- Unregister the netdev before dev_free() on probe failure.
- Only dump received bytes, rate limited, on decode error.
- Link to v2: https://patch.msgid.link/20261009-canfd_check_channel_idx-v2-0-f7b772929791@peak-system.fr
Changes in v2:
- Kill all pending RX URBs before unregistering sibling netdevs.
- Reject records targeting unavailable channels during device
initialization in rare corner cases involving malformed device
input.
- Link to v1: https://patch.msgid.link/20261008-canfd_check_channel_idx-v1-0-0a3bb82f4e09@peak-system.fr
To: Marc Kleine-Budde <mkl@pengutronix.de>
To: Vincent Mailhol <mailhol@kernel.org>
To: Dan Carpenter <error27@gmail.com>
To: Wolfgang Grandegger <wg@grandegger.com>
Cc: Stéphane Grosjean <s.grosjean@peak-system.fr>
Cc: linux-can@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
Marc Kleine-Budde (1):
can: peak_usb: add missing includes
Stefan Günther (1):
can: peak_usb: fix missing CAN_ERR_FLAG when reporting error counters
Stéphane Grosjean (8):
can: peak_usb: sort ctrlmode_supported flags
can: peak_usb: harden PCAN-USB message validation
can: peak_usb: replace open-coded bitmask operations with bitops
can: peak_usb: harden channel handling in PCAN-USB FD
can: peak_usb: fix RX cursor desync for self-received RTR frames with SRR
can: peak_usb: reject records for unset channels in PCAN-USB Pro
can: peak_usb: register the netdevs only once all channels are set up
can: peak_usb: only dump received bytes on decode error
drivers/net/can/usb/peak_usb/pcan_usb.c | 51 ++++++++++-----
drivers/net/can/usb/peak_usb/pcan_usb_core.c | 91 ++++++++++++++++++--------
drivers/net/can/usb/peak_usb/pcan_usb_core.h | 16 ++++-
drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 96 ++++++++++++++++++++--------
drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 29 +++++++--
5 files changed, 201 insertions(+), 82 deletions(-)
---
base-commit: a7bfaba4823e3c165bb2004c74eff7c096672bc7
change-id: 20261007-canfd_check_channel_idx-a4d7a1a1ee7d
Best regards,
--
Stéphane Grosjean <s.grosjean@peak-system.fr>
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v5 01/10] can: peak_usb: fix missing CAN_ERR_FLAG when reporting error counters
2026-10-20 13:30 [PATCH v5 00/10] can: peak_usb: fixes, cleanup and input validation hardening Stéphane Grosjean via B4 Relay
@ 2026-10-20 13:30 ` Stéphane Grosjean via B4 Relay
2026-10-20 13:30 ` [PATCH v5 07/10] can: peak_usb: fix RX cursor desync for self-received RTR frames with SRR Stéphane Grosjean via B4 Relay
2026-10-20 13:53 ` [PATCH v5 00/10] can: peak_usb: fixes, cleanup and input validation hardening Dan Carpenter
2 siblings, 0 replies; 5+ messages in thread
From: Stéphane Grosjean via B4 Relay @ 2026-10-20 13:30 UTC (permalink / raw)
To: Marc Kleine-Budde, Vincent Mailhol, Dan Carpenter,
Wolfgang Grandegger
Cc: Stéphane Grosjean, linux-can, linux-kernel,
Stefan Günther, stable
From: Stefan Günther <stefangun@pm.me>
When the device reports error counters, the driver incorrectly uses an
assignment (=) instead of a bitwise OR (|=) for CAN_ERR_CNT. This wipes
out the CAN_ERR_FLAG and CAN_ERR_CRTL flags, causing the error frame to
be sent to userspace as a regular CAN frame with ID 0x200.
Fix this by using a bitwise OR to preserve the flags.
Signed-off-by: Stefan Günther <stefangun@pm.me>
Cc: stable@vger.kernel.org
Fixes: 3e5c291c7942 ("can: add CAN_ERR_CNT flag to notify availability of error counter")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/peak_usb/pcan_usb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
index 8fd058c32856..785224e00c4e 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb.c
@@ -526,7 +526,7 @@ static int pcan_usb_decode_error(struct pcan_usb_msg_context *mc, u8 n,
/* Supply TX/RX error counters in case of
* controller error.
*/
- cf->can_id = CAN_ERR_CNT;
+ cf->can_id |= CAN_ERR_CNT;
cf->data[6] = mc->pdev->bec.txerr;
cf->data[7] = mc->pdev->bec.rxerr;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v5 07/10] can: peak_usb: fix RX cursor desync for self-received RTR frames with SRR
2026-10-20 13:30 [PATCH v5 00/10] can: peak_usb: fixes, cleanup and input validation hardening Stéphane Grosjean via B4 Relay
2026-10-20 13:30 ` [PATCH v5 01/10] can: peak_usb: fix missing CAN_ERR_FLAG when reporting error counters Stéphane Grosjean via B4 Relay
@ 2026-10-20 13:30 ` Stéphane Grosjean via B4 Relay
2026-10-20 13:53 ` [PATCH v5 00/10] can: peak_usb: fixes, cleanup and input validation hardening Dan Carpenter
2 siblings, 0 replies; 5+ messages in thread
From: Stéphane Grosjean via B4 Relay @ 2026-10-20 13:30 UTC (permalink / raw)
To: Marc Kleine-Budde, Vincent Mailhol, Dan Carpenter,
Wolfgang Grandegger
Cc: Stéphane Grosjean, linux-can, linux-kernel, stable
From: Stéphane Grosjean <s.grosjean@peak-system.fr>
pcan_usb_encode_msg() appends a one-byte "writer id" whenever
PCAN_USB_TX_SRR is set in can_id_flags, for both RTR and non-RTR
frames: the data block and the SRR writer id byte are two independent,
unconditional steps.
pcan_usb_decode_data() only consumed that extra byte in the non-RTR
branch, inside the same conditional block that reads the CAN data
payload. A self-received RTR frame with the SRR bit set (e.g. a
loopback echo with CAN_CTRLMODE_LOOPBACK) therefore left the RX cursor
one byte short, causing the private id byte to be misparsed as the
next record's status/len byte and the rest of the URB to be misparsed
or rejected.
Move the private id byte skip out of the RTR/non-RTR branch so it is
applied whenever SRR is set, matching the encoder's layout.
Fixes: 3a7939495ce8 ("can: peak_usb: PCAN-USB: add support of loopback and one-shot mode")
Cc: stable@vger.kernel.org
Signed-off-by: Stéphane Grosjean <s.grosjean@peak-system.fr>
---
drivers/net/can/usb/peak_usb/pcan_usb.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
index 93da0fd4f10e..4c8cfed31634 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++;
/* convert timestamp into kernel time */
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v5 00/10] can: peak_usb: fixes, cleanup and input validation hardening
2026-10-20 13:30 [PATCH v5 00/10] can: peak_usb: fixes, cleanup and input validation hardening Stéphane Grosjean via B4 Relay
2026-10-20 13:30 ` [PATCH v5 01/10] can: peak_usb: fix missing CAN_ERR_FLAG when reporting error counters Stéphane Grosjean via B4 Relay
2026-10-20 13:30 ` [PATCH v5 07/10] can: peak_usb: fix RX cursor desync for self-received RTR frames with SRR Stéphane Grosjean via B4 Relay
@ 2026-10-20 13:53 ` Dan Carpenter
2026-10-20 14:19 ` Stéphane Grosjean
2 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2026-10-20 13:53 UTC (permalink / raw)
To: s.grosjean
Cc: Marc Kleine-Budde, Vincent Mailhol, Wolfgang Grandegger,
linux-can, linux-kernel, Stefan Günther, stable
Could you please slow down. Only resend once per day. Otherwise it's
a bit like involuntary pair programming for people who are on the list.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v5 00/10] can: peak_usb: fixes, cleanup and input validation hardening
2026-10-20 13:53 ` [PATCH v5 00/10] can: peak_usb: fixes, cleanup and input validation hardening Dan Carpenter
@ 2026-10-20 14:19 ` Stéphane Grosjean
0 siblings, 0 replies; 5+ messages in thread
From: Stéphane Grosjean @ 2026-10-20 14:19 UTC (permalink / raw)
To: Dan Carpenter
Cc: Marc Kleine-Budde, Vincent Mailhol, Wolfgang Grandegger,
linux-can, linux-kernel, Stefan Günther, stable, s grosjean
Sorry about that, and thanks for the reminder. I'll wait at least
24 hours between postings from now on.
Regards,
Stéphane
----- Mail original -----
> Could you please slow down. Only resend once per day. Otherwise
> it's
> a bit like involuntary pair programming for people who are on the
> list.
>
> regards,
> dan carpenter
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-10-20 14:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-20 13:30 [PATCH v5 00/10] can: peak_usb: fixes, cleanup and input validation hardening Stéphane Grosjean via B4 Relay
2026-10-20 13:30 ` [PATCH v5 01/10] can: peak_usb: fix missing CAN_ERR_FLAG when reporting error counters Stéphane Grosjean via B4 Relay
2026-10-20 13:30 ` [PATCH v5 07/10] can: peak_usb: fix RX cursor desync for self-received RTR frames with SRR Stéphane Grosjean via B4 Relay
2026-10-20 13:53 ` [PATCH v5 00/10] can: peak_usb: fixes, cleanup and input validation hardening Dan Carpenter
2026-10-20 14:19 ` Stéphane Grosjean
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox