Linux CAN drivers development
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: mkl@pengutronix.de
Cc: mailhol@kernel.org, pfink@christ-es.de, eric@evenchick.com,
	max@schneidersoft.net, wg@grandegger.com, kernel@pengutronix.de,
	linux-can@vger.kernel.org, stable@vger.kernel.org,
	kuba@kernel.org
Subject: Re: [PATCH can-next v10 12/14] can: gs_usb: gs_can_start_xmit(): mask invalid parts of CAN ID before sending
Date: Tue, 24 Nov 2026 09:31:03 +0000	[thread overview]
Message-ID: <179551266332.3131.13201472550336097370@kernel.org> (raw)
In-Reply-To: <20261122-gs_usb-fixes-v10-12-7c165c35d04a@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] 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

  reply	other threads:[~2026-11-24  9:31 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 18:48 [PATCH can-next v10 00/14] gs_usb: fixes Marc Kleine-Budde
2026-11-22 18:48 ` [PATCH can-next v10 01/14] can: gs_usb: gs_usb_probe(): init netdev completely before register_candev() Marc Kleine-Budde
2026-11-22 18:48 ` [PATCH can-next v10 02/14] can: gs_usb: gs_usb_receive_bulk_callback(): check for overflow flag if SKB allocation fails Marc Kleine-Budde
2026-11-24  9:30   ` netdev-bot+sashiko
2026-11-22 18:48 ` [PATCH can-next v10 03/14] can: gs_usb: gs_usb_receive_bulk_callback(): add missing call to can_rx_offload_irq_finish Marc Kleine-Budde
2026-11-22 18:48 ` [PATCH can-next v10 04/14] can: gs_usb: use spin_lock_irqsave() instead of spin_lock_bh() to protect struct gs_usb::tc Marc Kleine-Budde
2026-11-24  9:30   ` netdev-bot+sashiko
2026-11-22 18:48 ` [PATCH can-next v10 05/14] can: gs_usb: fix hardware timestamp state for mixed channels Marc Kleine-Budde
2026-11-24  9:30   ` netdev-bot+sashiko
2026-11-22 18:48 ` [PATCH can-next v10 06/14] can: gs_usb: add support for context analysis Marc Kleine-Budde
2026-11-22 18:48 ` [PATCH can-next v10 07/14] can: gs_usb: gs_make_candev(): check can_rx_offload_add_manual() return value Marc Kleine-Budde
2026-11-22 18:48 ` [PATCH can-next v10 08/14] can: gs_usb: gs_usb_receive_bulk_callback(): use dev_info() to print re-submit info messages Marc Kleine-Budde
2026-11-24  9:30   ` netdev-bot+sashiko
2026-11-22 18:48 ` [PATCH can-next v10 09/14] can: gs_usb: gs_usb_get_gs_can(): introduce new function to consolidate validation of struct gs_can Marc Kleine-Budde
2026-11-24  9:30   ` netdev-bot+sashiko
2026-11-22 18:48 ` [PATCH can-next v10 10/14] can: gs_usb: gs_usb_get_gs_can(): report channel number out of range error Marc Kleine-Budde
2026-11-22 18:48 ` [PATCH can-next v10 11/14] can: gs_usb: gs_usb_get_rx_data_length(): new function to consolidate validation of host frame Marc Kleine-Budde
2026-11-24  9:31   ` netdev-bot+sashiko
2026-11-22 18:48 ` [PATCH can-next v10 12/14] can: gs_usb: gs_can_start_xmit(): mask invalid parts of CAN ID before sending Marc Kleine-Budde
2026-11-24  9:31   ` netdev-bot+sashiko [this message]
2026-11-22 18:48 ` [PATCH can-next v10 13/14] can: gs_usb: gs_usb_host_frame_header_valid(): drop invalid CAN error frames Marc Kleine-Budde
2026-11-24  9:31   ` netdev-bot+sashiko
2026-11-22 18:48 ` [PATCH can-next v10 14/14] can: gs_usb: gs_usb_host_frame_header_valid(): drop CAN frames with invalid DLC Marc Kleine-Budde
2026-11-24  9:31   ` 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=179551266332.3131.13201472550336097370@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=eric@evenchick.com \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=max@schneidersoft.net \
    --cc=mkl@pengutronix.de \
    --cc=pfink@christ-es.de \
    --cc=stable@vger.kernel.org \
    --cc=wg@grandegger.com \
    /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