From: sashiko-bot@kernel.org
To: "Stéphane Grosjean" <stephane.grosjean@free.fr>
Cc: "Marc Kleine-Budde" <mkl@pengutronix.de>,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
linux-can@vger.kernel.org, "Vincent Mailhol" <mailhol@kernel.org>,
"Oliver Hartkopp" <socketcan@hartkopp.net>
Subject: Re: [PATCH 4/5] can: peak_usb: validate channel numbers in PCAN-USB FD
Date: Thu, 08 Oct 2026 09:36:52 +0000 [thread overview]
Message-ID: <sashiko-outbox-163954@kernel.org> (raw)
In-Reply-To: <20261008-canfd_check_channel_idx-v1-4-0a3bb82f4e09@peak-system.fr>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] can: peak_usb: missing NULL check on sibling channels leads to UAF and NULL deref
--
commit bb6a3841806ddddd6a5d411fd8594a762ea452bd
Author: Stéphane Grosjean <s.grosjean@peak-system.fr>
can: peak_usb: validate channel numbers in PCAN-USB FD
This patch adds validation for CAN channel numbers encoded in messages
received from PCAN-USB FD devices. The channel number is checked against
the number of controllers supported by the adapter to prevent out-of-bounds
array accesses.
> diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
> index 82502594a4092..ddbb2be1de0dd 100644
> --- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
> +++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
[ ... ]
> @@ -536,8 +537,12 @@ static int pcan_usb_fd_decode_canmsg(struct pcan_usb_fd_if *usb_if,
> struct sk_buff *skb;
> const u16 rx_msg_flags = le16_to_cpu(rm->flags);
>
> - if (pucan_msg_get_channel(rm) >= ARRAY_SIZE(usb_if->dev))
> - return -ENOMEM;
> + /* Reject invalid channel numbers reported by the firmware.
> + * Any channel below ctrl_count is guaranteed to have a valid
> + * entry in usb_if->dev[].
> + */
> + if (pucan_msg_get_channel(rm) >= usb_if->adapter->ctrl_count)
> + return -EINVAL;
>
> dev = usb_if->dev[pucan_msg_get_channel(rm)];
> netdev = dev->netdev;
[Severity: High]
Does this actually guarantee that the usb_if->dev[] entry is valid?
Since sibling channels are initialized sequentially during device probe, can
this lead to a NULL pointer dereference? For example, if can0 is brought up
and receives a message from the shared USB endpoint with a channel number
for can1 before can1 completes its initialization, usb_if->dev[channel]
might still be NULL, causing a crash when accessing dev->netdev.
Additionally, what happens during device disconnect? If peak_usb_disconnect()
frees sibling channels in reverse order (e.g., can1 then can0), the freed
channel's pointer seems to remain in the shared usb_if->dev[] array. If can0
is still active and receives a message for the freed channel, could this
result in a use-after-free?
This same pattern appears to be repeated in pcan_usb_fd_decode_status(),
pcan_usb_fd_decode_error(), and pcan_usb_fd_decode_overrun() modified
further down in this patch.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261008-canfd_check_channel_idx-v1-0-0a3bb82f4e09@peak-system.fr?part=4
next prev parent reply other threads:[~2026-10-08 9:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 9:14 [PATCH 0/5] can: peak_usb: fixes, cleanup and input validation hardening Stéphane Grosjean
2026-10-08 9:14 ` [PATCH 1/5] can: peak_usb: fix missing CAN_ERR_FLAG when reporting error counters Stéphane Grosjean
2026-10-08 9:14 ` [PATCH 2/5] can: peak_usb: add missing includes Stéphane Grosjean
2026-10-08 9:14 ` [PATCH 3/5] can: peak_usb: sort ctrlmode_supported flags Stéphane Grosjean
2026-10-08 9:14 ` [PATCH 4/5] can: peak_usb: validate channel numbers in PCAN-USB FD Stéphane Grosjean
2026-10-08 9:36 ` sashiko-bot [this message]
2026-10-10 6:48 ` netdev-bot+sashiko
2026-10-08 9:14 ` [PATCH 5/5] can: peak_usb: harden PCAN-USB message validation Stéphane Grosjean
2026-10-10 6:48 ` 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-163954@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 \
--cc=stephane.grosjean@free.fr \
/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