mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: s.grosjean@peak-system.fr
Cc: mkl@pengutronix.de, mailhol@kernel.org, wg@grandegger.com,
	error27@gmail.com, lukas.magel@posteo.net,
	linux-can@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, kuba@kernel.org
Subject: Re: [PATCH v6 11/13] can: peak_usb: don't read past the message in PCAN-USB Pro decoders
Date: Sat, 24 Oct 2026 03:58:55 +0000	[thread overview]
Message-ID: <179281433565.3130.14307625292135673040@kernel.org> (raw)
In-Reply-To: <20261022-canfd_check_channel_idx-v6-11-197704231551@peak-system.fr>

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 overstates what the old
  pcan_usb_pro_wait_rsp() bug could do.

--

can: peak_usb: don't read past the message in PCAN-USB Pro decoders

This commit adds bounds checks to pcan_usb_pro_decode_buf() and
pcan_usb_pro_wait_rsp(). With these checks, the record walk stops at the
end of the received message and no longer trusts the record count sent by
the device. pcan_usb_pro_wait_rsp() also now rejects a record that doesn't
fit in the received length.

> - pcan_usb_pro_wait_rsp() doesn't check the records against the
>   received length at all. Since the count is a 32-bit value, a bogus
>   response makes it walk the records past the command buffer.

[Severity: Low]
With the current callers, is the last sentence accurate? The code change
looks correct. It is less clear that the old walk could ever leave the
command buffer allocation.

pcan_usb_pro_get_can_channel_id() in
drivers/net/can/usb/peak_usb/pcan_usb_pro.c is the only caller of
pcan_usb_pro_wait_rsp(). It builds a 4-byte header plus an 8-byte
GETDEVID record in dev->cmd_buf:

pcan_usb_pro_get_can_channel_id() {
	...
	pc = pcan_msg_init_empty(&um, dev->cmd_buf, PCAN_USB_MAX_CMD_LEN);
	pcan_msg_add_rec(&um, PCAN_USBPRO_GETDEVID, dev->ctrl_idx);
	...
}

That makes um.rec_buffer_len 12. pcan_usb_pro_wait_rsp() passes that
length to usb_bulk_msg(), so the device can write at most 12 bytes.

peak_usb_create_dev() allocates dev->cmd_buf with
kzalloc(PCAN_USB_MAX_CMD_LEN), and PCAN_USB_MAX_CMD_LEN is 32. None of the
PCAN-USB Pro command builders write more than 12 bytes into it, so bytes
12-31 stay zero.

No record type 0x00 is defined, so pcan_usb_pro_sizeof_rec[0] is 0. All
record sizes are multiples of 4, and the largest is RXMSG8 at 20 bytes.

The old loop therefore reads type bytes the device controls only at
offsets 4 and 8. From offset 8 it can advance to offset 28 at most. There
it reads a zero type and stops on the !rec_len check, whatever value
rec_cnt has.

What the old code could do is read past actual_length. For example, it
could accept a truncated response with actual_length == 8 and a GETDEVID
record at offset 4. In that case it would return the stale request bytes
8-11 as dev_num. The new "pc + rec_len > rsp_end" check fixes that case.

Could the commit message describe this case instead, so that the stated
impact matches what the old pcan_usb_pro_wait_rsp() code could actually
do?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261022-canfd_check_channel_idx-v6-0-197704231551%40peak-system.fr

  reply	other threads:[~2026-10-24  3:58 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-22 14:27 [PATCH v6 00/13] can: peak_usb: fixes, cleanup and input validation hardening Stéphane Grosjean via B4 Relay
2026-10-22 14:27 ` [PATCH v6 01/13] can: peak_usb: fix missing CAN_ERR_FLAG when reporting error counters Stéphane Grosjean via B4 Relay
2026-10-22 14:27 ` [PATCH v6 02/13] can: peak_usb: add missing includes Stéphane Grosjean via B4 Relay
2026-10-22 14:27 ` [PATCH v6 03/13] can: peak_usb: sort ctrlmode_supported flags Stéphane Grosjean via B4 Relay
2026-10-24  3:58   ` netdev-bot+sashiko
2026-10-22 14:27 ` [PATCH v6 04/13] can: peak_usb: harden PCAN-USB message validation Stéphane Grosjean via B4 Relay
2026-10-22 14:27 ` [PATCH v6 05/13] can: peak_usb: replace open-coded bitmask operations with bitops Stéphane Grosjean via B4 Relay
2026-10-22 14:27 ` [PATCH v6 06/13] can: peak_usb: harden channel handling in PCAN-USB FD Stéphane Grosjean via B4 Relay
2026-10-24  3:58   ` netdev-bot+sashiko
2026-10-22 14:27 ` [PATCH v6 07/13] can: peak_usb: fix RX cursor desync for self-received RTR frames with SRR Stéphane Grosjean via B4 Relay
2026-10-22 14:27 ` [PATCH v6 08/13] can: peak_usb: reject records for unset channels in PCAN-USB Pro Stéphane Grosjean via B4 Relay
2026-10-24  3:58   ` netdev-bot+sashiko
2026-10-22 14:27 ` [PATCH v6 09/13] can: peak_usb: register the netdevs only once all channels are set up Stéphane Grosjean via B4 Relay
2026-10-24  3:58   ` netdev-bot+sashiko
2026-10-22 14:27 ` [PATCH v6 10/13] can: peak_usb: validate the data length of PCAN-USB Pro CAN records Stéphane Grosjean via B4 Relay
2026-10-22 14:27 ` [PATCH v6 11/13] can: peak_usb: don't read past the message in PCAN-USB Pro decoders Stéphane Grosjean via B4 Relay
2026-10-24  3:58   ` netdev-bot+sashiko [this message]
2026-10-22 14:27 ` [PATCH v6 12/13] can: peak_usb: dump undecodable URBs once and rate limit decode errors Stéphane Grosjean via B4 Relay
2026-10-22 14:27 ` [PATCH v6 13/13] can: peak_usb: don't return an uninitialized PCAN-USB CAN channel ID Stéphane Grosjean via B4 Relay

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=179281433565.3130.14307625292135673040@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=error27@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.magel@posteo.net \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=s.grosjean@peak-system.fr \
    --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

all inboxes | Powered by JetHome®