From: netdev-bot+sashiko@kernel.org
To: mkl@pengutronix.de
Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org,
linux-can@vger.kernel.org, kernel@pengutronix.de,
s.grosjean@peak-system.fr, stable@vger.kernel.org
Subject: Re: [PATCH net-next 20/23] can: peak_usb: don't return an uninitialized PCAN-USB CAN channel ID
Date: Thu, 03 Dec 2026 23:12:19 +0000 [thread overview]
Message-ID: <179633953988.3146.5292238485083319887@kernel.org> (raw)
In-Reply-To: <20261202230853.2665144-21-mkl@pengutronix.de>
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] With args[] zero-initialized, pcan_usb_get_can_channel_id()
(drivers/net/can/usb/peak_usb/pcan_usb.c) returns success with…
Pre-existing issues:
- [Medium] PCAN-USB Pro has the same disconnect-window leak, in
pcan_usb_pro_get_can_channel_id()…
- [Medium] At this commit, pcan_usb_set_can_channel_id() and
pcan_usb_set_bittiming() (drivers/net/can/usb/peak_usb/pcan_usb.c)…
--
can: peak_usb: don't return an uninitialized PCAN-USB CAN channel ID
This patch zero-initializes the args[] array in
pcan_usb_get_can_channel_id(). When pcan_usb_wait_rsp() returns success
without talking to a disconnected device, a null channel ID is now
returned instead of an uninitialized stack byte.
Link: https://patch.msgid.link/20261126-canfd_check_channel_idx-v9-11-abe0099b4585@peak-system.fr
> diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
> index ff19217790656..83cf6fe7d258b 100644
> --- a/drivers/net/can/usb/peak_usb/pcan_usb.c
> +++ b/drivers/net/can/usb/peak_usb/pcan_usb.c
> @@ -386,7 +386,7 @@ static int pcan_usb_get_serial(struct peak_usb_device *dev, u32 *serial_number)
> */
> static int pcan_usb_get_can_channel_id(struct peak_usb_device *dev, u32 *can_ch_id)
> {
> - u8 args[PCAN_USB_CMD_ARGS_LEN];
> + u8 args[PCAN_USB_CMD_ARGS_LEN] = {};
[Severity: Low]
With args[] zeroed, pcan_usb_get_can_channel_id() now reports success with
*can_ch_id = 0 whenever pcan_usb_wait_rsp() skips the USB exchange:
pcan_usb_wait_rsp() {
/* usb device unregistered? */
if (!test_bit(PCAN_USB_STATE_CONNECTED, &dev->state))
return 0;
...
}
peak_usb_stop_rx() clears PCAN_USB_STATE_CONNECTED before
peak_usb_disconnect() calls unregister_candev(). In that window,
peak_usb_get_eeprom() would return 0 to userspace and write 0 over
dev->can_channel_id.
In the same window, peak_usb_set_eeprom() would merge the user bytes into
this made-up 0 and cache the result. Meanwhile pcan_usb_send_cmd() skips
the flash write without reporting it.
The commit message says the null ID is intentional. Returning 0 for an
unplugged device is also a long-standing convention in this driver, and
the cached value is freed with the device shortly afterwards.
Would returning -ENODEV for a disconnected device be cleaner here than
reporting a successful read of ID 0?
> int err;
>
> err = pcan_usb_wait_rsp(dev, PCAN_USB_CMD_DEVID, PCAN_USB_GET, args);
[Severity: Medium]
This is a pre-existing issue and was not introduced by this patch. Does
PCAN-USB Pro have the same disconnect-window leak in
pcan_usb_pro_get_can_channel_id() in pcan_usb_pro.c?
The request is built without the u32 dev_num argument:
pcan_usb_pro_get_can_channel_id() {
...
pcan_msg_add_rec(&um, PCAN_USBPRO_GETDEVID, dev->ctrl_idx);
...
}
However, the GETDEVID case in pcan_msg_add_rec() still reads that
argument:
case PCAN_USBPRO_GETDEVID:
case PCAN_USBPRO_SETDEVID:
*pc++ = va_arg(ap, int);
pc += 2;
*(__le32 *)pc = cpu_to_le32(va_arg(ap, u32));
Once PCAN_USB_STATE_CONNECTED is cleared, pcan_usb_pro_send_cmd() and
pcan_usb_pro_wait_rsp() both return 0 without any transfer. pdn->dev_num
still holds the indeterminate value written into the request in
dev->cmd_buf, and it is returned as the channel ID.
peak_usb_get_eeprom() then copies that value to userspace and caches it
in dev->can_channel_id.
Reaching this needs CAP_NET_ADMIN for ETHTOOL_GEEPROM, and the window is
narrow. A later commit in the series fixes it: "can: peak_usb: pass the
dev_num argument of PCAN-USB Pro GETDEVID" changes the call to pass 0 as
dev_num.
[Severity: Medium]
This isn't a bug introduced by this patch, but pcan_usb_set_can_channel_id()
and pcan_usb_set_bittiming() in the same file still declare args[] without
an initializer:
pcan_usb_set_can_channel_id() {
u8 args[PCAN_USB_CMD_ARGS_LEN];
...
args[0] = can_ch_id;
return pcan_usb_send_cmd(dev, PCAN_USB_CMD_DEVID, PCAN_USB_SET, args);
}
pcan_usb_set_bittiming() {
u8 args[PCAN_USB_CMD_ARGS_LEN];
...
args[0] = btr1;
args[1] = btr0;
...
}
pcan_usb_send_cmd() copies all PCAN_USB_CMD_ARGS_LEN bytes into
dev->cmd_buf before usb_bulk_msg(). Doesn't that send 12 or 13
uninitialized kernel stack bytes to the device?
A later commit in the series fixes this: "can: peak_usb: don't send
uninitialized stack bytes to PCAN-USB devices" changes both declarations
to = {}.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202230853.2665144-2-mkl%40pengutronix.de
next prev parent reply other threads:[~2026-12-03 23:12 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 23:04 [PATCH net-next 0/23] pull-request: can-next 2026-12-03 Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 01/23] selftests: can: install net/lib.sh with the CAN tests Marc Kleine-Budde
2026-12-02 23:15 ` netdev-bot+sinfo
2026-12-02 23:04 ` [PATCH net-next 02/23] selftests: can: add J1939 test helper header and library Marc Kleine-Budde
2026-12-02 23:26 ` sashiko-bot
2026-12-02 23:29 ` Marc Kleine-Budde
2026-12-03 23:12 ` netdev-bot+sashiko
2026-12-02 23:04 ` [PATCH net-next 03/23] selftests: can: add J1939 base functional tests Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 04/23] selftests: can: add J1939 socket option and metadata tests Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 05/23] selftests: can: add J1939 addressing and concurrency tests Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 06/23] selftests: can: add J1939 wire-format tests against CAN_RAW Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 07/23] selftests: can: add J1939 TP/ETP multi-frame " Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 08/23] selftests: can: cover J1939 transport abort and timeout paths Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 09/23] selftests: can: check SO_J1939_PROMISC receive effect Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 10/23] can: peak_usb: fix missing CAN_ERR_FLAG when reporting error counters Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 11/23] can: peak_usb: harden PCAN-USB message validation Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 12/23] can: peak_usb: replace open-coded bitmask operations with bitops Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 13/23] can: peak_usb: harden channel handling in PCAN-USB FD Marc Kleine-Budde
2026-12-03 23:12 ` netdev-bot+sashiko
2026-12-02 23:04 ` [PATCH net-next 14/23] can: peak_usb: fix RX cursor desync for self-received RTR frames with SRR Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 15/23] can: peak_usb: reject records for unset channels in PCAN-USB Pro Marc Kleine-Budde
2026-12-03 23:12 ` netdev-bot+sashiko
2026-12-02 23:04 ` [PATCH net-next 16/23] can: peak_usb: register the netdevs only once all channels are set up Marc Kleine-Budde
2026-12-03 23:12 ` netdev-bot+sashiko
2026-12-02 23:04 ` [PATCH net-next 17/23] can: peak_usb: validate the data length of PCAN-USB Pro CAN records Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 18/23] can: peak_usb: don't read past the message in PCAN-USB Pro decoders Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 19/23] can: peak_usb: dump undecodable URBs once and rate limit decode errors Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 20/23] can: peak_usb: don't return an uninitialized PCAN-USB CAN channel ID Marc Kleine-Budde
2026-12-03 23:12 ` netdev-bot+sashiko [this message]
2026-12-02 23:04 ` [PATCH net-next 21/23] can: peak_usb: pass the dev_num argument of PCAN-USB Pro GETDEVID Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 22/23] can: peak_usb: don't send uninitialized stack bytes to PCAN-USB devices Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 23/23] can: peak_usb: don't send uninitialized heap bytes in restart commands Marc Kleine-Budde
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=179633953988.3146.5292238485083319887@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=s.grosjean@peak-system.fr \
--cc=stable@vger.kernel.org \
/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