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] Backport hazard. Pre-existing issues: - [High] Peer inconsistency in PCAN-USB Pro. - [High] Use-after-free on the probe error paths at this commit. - [Medium] peak_usb_stop_rx() clears PCAN_USB_STATE_CONNECTED on all channels before any unregister_candev(). -- can: peak_usb: harden channel handling in PCAN-USB FD This commit checks the channel number in PCAN-USB FD records against the adapter's controller count and rejects records for empty channel slots. It also clears the slot in pcan_usb_fd_free(). It adds peak_usb_stop_rx(), which clears CONNECTED under RTNL and poisons the RX anchors of all channels before the probe error path and peak_usb_disconnect() free them. Link: https://patch.msgid.link/2026…@peak-system.fr
> diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c > index a1b17e1e6fea6..f5c39b43b0fa1 100644 > --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c > +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
[ ... ]
> @@ -574,6 +575,9 @@ static int peak_usb_ndo_open(struct net_device *netdev) > struct peak_usb_device *dev = netdev_priv(netdev); > int err; > > + if (!test_bit(PCAN_USB_STATE_CONNECTED, &dev->state)) > + return -ENODEV; > +
[Severity: Low] This isn't a bug, but this test_bit() and the clear_bit() calls in peak_usb_stop_rx() only build on top of the preceding commit, "can: peak_usb: replace open-coded bitmask operations with bitops". That commit is what turned dev->state into an unsigned long holding bit numbers. This commit has a Fixes: tag. The bitops commit has neither a Fixes: tag nor Cc: stable. If a stable backport picks up only this commit, would it fail to build? The bitops commit message does state the dependency ("The next patch relies on this to clear CONNECTED while a channel may be opened"). The other series patches that depend on it also leave out Cc: stable, so this may be intentional. [ ... ]
> @@ -904,6 +908,29 @@ int pcan_get_ts_info(struct net_device *dev, struct kernel_ethtool_ts_info *info
[ ... ]
> +static void peak_usb_stop_rx(struct peak_usb_device *dev) > +{ > + struct peak_usb_device *d; > + > + rtnl_lock(); > + for (d = dev; d; d = d->prev_siblings) > + clear_bit(PCAN_USB_STATE_CONNECTED, &d->state); > + rtnl_unlock();
[Severity: Medium] This is a pre-existing issue, but clearing CONNECTED on every channel before any unregister_candev() makes the shutdown commands sent from ndo_stop silent no-ops: pcan_usb_fd_send_cmd() if (!test_bit(PCAN_USB_STATE_CONNECTED, &dev->state)) return 0; On an IFF_UP netdev, unregister_candev() runs peak_usb_ndo_stop(). That calls dev_stop() (pcan_usb_fd_stop() turns the calibration messages off) and then dev_set_bus(dev, 0). Both commands are dropped but reported as successful. pcan_usb.c and pcan_usb_pro.c have the same pattern. After a probe error the adapter is still attached. Can its CAN controller stay bus-on, with calibration and error messages enabled, and no driver bound? The disconnect path behaves as before. The old peak_usb_disconnect() already cleared CONNECTED on each device right before calling unregister_candev() on it. The only path that changes is adap_dev_free in peak_usb_create_dev(). The later series commit "can: peak_usb: register the netdevs only once all channels are set up" removes the peak_usb_stop_rx() call there, and with it the window in which the netdev can be open.
> + > + for (d = dev; d; d = d->prev_siblings) > + usb_poison_anchored_urbs(&d->rx_submitted); > +}
[ ... ]
> @@ -1014,6 +1041,13 @@ static int peak_usb_create_dev(const struct peak_usb_adapter *peak_usb_adapter, > return 0; > > adap_dev_free: > + /* the whole interface is released when probing a channel fails: > + * stop RX on this channel, which may already be open, and on the > + * channels already created, since their RX URBs may carry records > + * for this one. > + */ > + peak_usb_stop_rx(dev); > + > if (dev->adapter->dev_free) > dev->adapter->dev_free(dev); >
[Severity: High] This isn't a bug introduced by this patch, but is there a use-after-free on this error path? peak_usb_create_dev() calls register_candev() before dev_init() and dev_set_bus(dev, 0). Userspace can therefore configure and open can0 while probe is still running. If dev_set_bus() then fails, for a channel with no siblings: peak_usb_create_dev() peak_usb_stop_rx(dev); dev->adapter->dev_free(dev); pcan_usb_fd_free() kfree(pdev->cmd_buffer_addr); kfree(pdev->usb_if); unregister_candev(netdev); /* lbl_unregister_candev */ peak_usb_ndo_stop() pcan_usb_fd_stop() pdev->usb_if->dev_opened_count--; pcan_usb_fd_set_bus(dev, 0) u8 *pc = pcan_usb_fd_cmd_buffer(dev); pcan_usb_fd_stop() reads and decrements dev_opened_count in the freed usb_if. pcan_usb_fd_set_bus() then writes the RESET_MODE command into the freed command buffer before pcan_usb_fd_send_cmd() checks CONNECTED. When pcan_usb_fd_init() fails on channel 0 (err_out_2 / err_out_1), the shared objects are freed and the code jumps to lbl_unregister_candev with no RX stop at all. Can in-flight RX completions then dereference the freed usb_if? The later series commit "can: peak_usb: register the netdevs only once all channels are set up" fixes this. peak_usb_create_dev() no longer registers the netdev. Registration moves to peak_usb_probe() after all channels are set up, and peak_usb_disconnect() unregisters (and so runs ndo_stop) before dev_free(). [ ... ]
> 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 729d294f71e55..43c16e743c155 100644 > --- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c > +++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
[ ... ]
> @@ -536,10 +537,16 @@ 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 */ > + if (pucan_msg_get_channel(rm) >= usb_if->adapter->ctrl_count) > + return -EINVAL; > + > + dev = READ_ONCE(usb_if->dev[pucan_msg_get_channel(rm)]); > + > + /* reject records for a channel that is not (or no longer) set up */ > + if (!dev) > + return -EINVAL; > > - dev = usb_if->dev[pucan_msg_get_channel(rm)]; > netdev = dev->netdev;
[Severity: High] This isn't a bug introduced by this patch, but the PCAN-USB Pro decoders still have the pattern removed here. pcan_usb_pro_handle_canmsg() and pcan_usb_pro_handle_error() in pcan_usb_pro.c do: if (ctrl_idx >= ARRAY_SIZE(usb_if->dev)) return -EINVAL; dev = usb_if->dev[ctrl_idx]; netdev = dev->netdev; On a 2-channel PCAN-USB Pro, only pcan_usb_pro_init() fills dev[1], when channel 1 is initialized. pcan_usb_pro_free() never clears the slot. Channel 0's RX URBs can already be running before that point. Can a device record for channel 1 then cause a NULL pointer dereference in URB completion context? The next commit in the series, "can: peak_usb: reject records for unset channels in PCAN-USB Pro", closes this gap. It adds the READ_ONCE() and NULL check to both Pro decoders, and pcan_usb_pro_free() clears the slot with WRITE_ONCE(). [ ... ]
-- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…%40pengutronix.de