From: sashiko-bot@kernel.org
To: "Marc Kleine-Budde" <mkl@pengutronix.de>
Cc: linux-can@vger.kernel.org,
"Oliver Hartkopp" <socketcan@hartkopp.net>,
"Vincent Mailhol" <mailhol@kernel.org>,
"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH can-next v11 2/9] can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails
Date: Mon, 30 Nov 2026 07:45:43 +0000 [thread overview]
Message-ID: <sashiko-outbox-240617@kernel.org> (raw)
In-Reply-To: <20261130-gs_usb-fixes-v11-2-3f052bb620d4@pengutronix.de>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] can: gs_usb: unvalidated data[1] read in gs_update_state() on
short frames
--
commit 30fc2459f9b225604427254c1421d65c0b0fa7b1
Author: Marc Kleine-Budde <mkl@pengutronix.de>
can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails
This commit moves gs_update_state() before alloc_can_skb() in
gs_usb_receive_bulk_callback() and changes it to read directly from struct
gs_host_frame so CAN state updates are not lost if skb allocation fails.
> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> index 965151ab50a1e..0c65db9bbd30f 100644
> --- a/drivers/net/can/usb/gs_usb.c
> +++ b/drivers/net/can/usb/gs_usb.c
> @@ -495,23 +495,23 @@ static void gs_usb_timestamp_stop(struct gs_usb *parent)
> cancel_delayed_work_sync(&parent->timestamp);
> }
>
> -static void gs_update_state(struct gs_can *dev, struct can_frame *cf)
> +static void gs_update_state(struct gs_can *dev, const struct gs_host_frame *hf)
> {
> struct can_device_stats *can_stats = &dev->can.can_stats;
>
> - if (cf->can_id & CAN_ERR_RESTARTED) {
> + if (hf->can_id & cpu_to_le32(CAN_ERR_RESTARTED)) {
> dev->can.state = CAN_STATE_ERROR_ACTIVE;
> can_stats->restarts++;
> - } else if (cf->can_id & CAN_ERR_BUSOFF) {
> + } else if (hf->can_id & cpu_to_le32(CAN_ERR_BUSOFF)) {
> dev->can.state = CAN_STATE_BUS_OFF;
> can_stats->bus_off++;
> - } else if (cf->can_id & CAN_ERR_CRTL) {
> - if ((cf->data[1] & CAN_ERR_CRTL_TX_WARNING) ||
> - (cf->data[1] & CAN_ERR_CRTL_RX_WARNING)) {
> + } else if (hf->can_id & cpu_to_le32(CAN_ERR_CRTL)) {
> + if ((hf->classic_can->data[1] & CAN_ERR_CRTL_TX_WARNING) ||
> + (hf->classic_can->data[1] & CAN_ERR_CRTL_RX_WARNING)) {
> dev->can.state = CAN_STATE_ERROR_WARNING;
> can_stats->error_warning++;
> - } else if ((cf->data[1] & CAN_ERR_CRTL_TX_PASSIVE) ||
> - (cf->data[1] & CAN_ERR_CRTL_RX_PASSIVE)) {
> + } else if ((hf->classic_can->data[1] & CAN_ERR_CRTL_TX_PASSIVE) ||
> + (hf->classic_can->data[1] & CAN_ERR_CRTL_RX_PASSIVE)) {
> dev->can.state = CAN_STATE_ERROR_PASSIVE;
> can_stats->error_passive++;
> } else {
> @@ -685,6 +685,10 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
>
> memcpy(cfd->data, hf->canfd->data, data_length);
> } else {
> + /* ERROR frames tell us information about the controller */
> + if (hf->can_id & cpu_to_le32(CAN_ERR_FLAG))
> + gs_update_state(dev, hf);
[Severity: Medium]
Can gs_update_state() read uninitialized or stale memory from
hf->classic_can->data[1] when a short error frame is received?
Previously, alloc_can_skb() zeroed cf via skb_put_zero() and only
data_length validated bytes were copied into cf->data. Because
gs_usb_get_minimum_rx_length() allows classic CAN frames with
data_length < 2 (when hf->can_dlc < 2 or CAN_RTR_FLAG is set), and RX URB
buffers are allocated with kmalloc() in gs_can_open() and reused across
transfers, reading hf->classic_can->data[1] directly without checking
data_length >= 2 can inspect uninitialized or leftover payload bytes and
misupdate dev->can.state and can_stats.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-gs_usb-fixes-v11-0-3f052bb620d4@pengutronix.de?part=2
next prev parent reply other threads:[~2026-11-30 7:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 7:37 [PATCH can-next v11 0/9] gs_usb: fixes - part 1 Marc Kleine-Budde
2026-11-30 7:37 ` [PATCH can-next v11 1/9] can: gs_usb: gs_usb_probe(): init netdev completely before register_candev() Marc Kleine-Budde
2026-11-30 7:37 ` [PATCH can-next v11 2/9] can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails Marc Kleine-Budde
2026-11-30 7:45 ` sashiko-bot [this message]
2026-11-30 8:04 ` Marc Kleine-Budde
2026-11-30 7:37 ` [PATCH can-next v11 3/9] can: gs_usb: gs_usb_receive_bulk_callback(): check for overflow flag if SKB allocation fails Marc Kleine-Budde
2026-11-30 7:37 ` [PATCH can-next v11 4/9] can: gs_usb: gs_usb_receive_bulk_callback(): add missing call to can_rx_offload_irq_finish Marc Kleine-Budde
2026-11-30 7:37 ` [PATCH can-next v11 5/9] can: gs_usb: fix hardware timestamp state for mixed channels Marc Kleine-Budde
2026-11-30 7:37 ` [PATCH can-next v11 6/9] can: gs_usb: add support for context analysis Marc Kleine-Budde
2026-11-30 7:44 ` sashiko-bot
2026-11-30 7:37 ` [PATCH can-next v11 7/9] can: gs_usb: gs_make_candev(): check can_rx_offload_add_manual() return value Marc Kleine-Budde
2026-11-30 7:37 ` [PATCH can-next v11 8/9] can: gs_usb: gs_usb_receive_bulk_callback(): use dev_info_ratelimited() to print re-submit info messages Marc Kleine-Budde
2026-11-30 7:37 ` [PATCH can-next v11 9/9] can: gs_usb: gs_usb_receive_bulk_callback(): emit error message on invalid channel instead of disconnecting interfaces 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=sashiko-outbox-240617@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=o.rempel@pengutronix.de \
--cc=sashiko-reviews@lists.linux.dev \
--cc=socketcan@hartkopp.net \
/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