* Re: [PATCH can-next v10 12/14] can: gs_usb: gs_can_start_xmit(): mask invalid parts of CAN ID before sending
[not found] <20261122-gs_usb-fixes-v10-12-7c165c35d04a@pengutronix.de>
@ 2026-11-24 9:31 ` netdev-bot+sashiko
0 siblings, 0 replies; only message in thread
From: netdev-bot+sashiko @ 2026-11-24 9:31 UTC (permalink / raw)
To: mkl; +Cc: mailhol, pfink, eric, max, wg, kernel, linux-can, stable, kuba
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] The commit message names the wrong macro.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
gs_can_start_xmit() sends uninitialized kernel heap memory to the USB…
--
can: gs_usb: gs_can_start_xmit(): mask invalid parts of CAN ID before sending
This commit masks the CAN ID in gs_can_start_xmit() before the frame is
sent to the device. Flags that are not valid in the TX path are removed,
and the ID is limited to 11 or 29 bits depending on CAN_EFF_FLAG.
CAN_RTR_FLAG is kept only for CAN-CC frames.
> - CAN_ERR_MASK is used exclusively in the receive path between the
> driver and user space to signal problems with the CAN controller.
[Severity: Low]
Should this bullet say CAN_ERR_FLAG instead of CAN_ERR_MASK?
include/uapi/linux/can.h has:
#define CAN_ERR_FLAG 0x20000000U /* error message frame */
#define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */
CAN_ERR_MASK has the same value as CAN_EFF_MASK. In gs_can_start_xmit(),
the new EFF masks keep every CAN_ERR_MASK bit and drop only CAN_ERR_FLAG:
can_id &= CAN_EFF_MASK | CAN_EFF_FLAG;
...
can_id &= CAN_EFF_MASK | CAN_RTR_FLAG | CAN_EFF_FLAG;
> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> index 4aa674c743f67..b345ab34a200a 100644
> --- a/drivers/net/can/usb/gs_usb.c
> +++ b/drivers/net/can/usb/gs_usb.c
[ ... ]
> @@ -1006,8 +1012,14 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb,
> memcpy(hf->canfd->data, cfd->data, cfd->len);
> } else {
> cf = (struct can_frame *)skb->data;
> + canid_t can_id = cf->can_id;
> +
> + if (can_id & CAN_EFF_FLAG)
> + can_id &= CAN_EFF_MASK | CAN_RTR_FLAG | CAN_EFF_FLAG;
> + else
> + can_id &= CAN_SFF_MASK | CAN_RTR_FLAG;
>
> - hf->can_id = cpu_to_le32(cf->can_id);
> + hf->can_id = cpu_to_le32(can_id);
> hf->can_dlc = can_get_cc_dlc(cf, dev->can.ctrlmode);
>
> memcpy(hf->classic_can->data, cf->data, cf->len);
[Severity: High]
This isn't a bug introduced by this patch, but does gs_can_start_xmit()
send uninitialized kernel heap memory to the USB device?
The TX buffer is not zeroed when it is allocated:
hf = kmalloc(dev->hf_size_tx, GFP_ATOMIC);
The function writes only the header fields plus cf->len (0..8) or
cfd->len (0..64) payload bytes. It then submits the whole buffer:
usb_fill_bulk_urb(urb, dev->udev,
dev->parent->pipe_out,
hf, dev->hf_size_tx,
gs_usb_xmit_callback, txc);
When CAN_CTRLMODE_FD is enabled, gs_can_open() sizes the buffer for a
64 byte payload, even when the frame is classic CAN:
dev->hf_size_tx = struct_size(hf, canfd, 1);
In FD mode, a classic frame leaves at least 56 data bytes unwritten. A
short or zero-length FD frame leaves up to 64. The quirk byte in
classic_can_quirk and canfd_quirk (LPC546XX devices) is never written
either.
That would expose leftover slab contents with every transmitted frame,
to the device or to anyone sniffing the bus. Would kzalloc(), or a
memset() of the area after the copied payload, fix this?
Later patches in this series do not seem to address it.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122-gs_usb-fixes-v10-0-7c165c35d04a%40pengutronix.de
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-24 9:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261122-gs_usb-fixes-v10-12-7c165c35d04a@pengutronix.de>
2026-11-24 9:31 ` [PATCH can-next v10 12/14] can: gs_usb: gs_can_start_xmit(): mask invalid parts of CAN ID before sending netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox