Linux CAN drivers development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Oliver Hartkopp" <socketcan@hartkopp.net>
Cc: "Oliver Hartkopp" <socketcan@hartkopp.net>,
	"Vincent Mailhol" <mailhol@kernel.org>,
	"Oleksij Rempel" <o.rempel@pengutronix.de>,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	linux-can@vger.kernel.org
Subject: Re: [PATCH v7 10/10] can: bcm: fix data race on rx_stamp/rx_ifindex in bcm_rx_handler()
Date: Wed, 08 Jul 2026 15:48:22 +0000	[thread overview]
Message-ID: <20260708154822.9F8F51F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260708-bcm_fixes-v7-10-c78896b342e4@hartkopp.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Multiplexed or throttled CAN frames share a single global `rx_stamp` and `rx_ifindex`, which are overwritten by rejected or unrelated multiplex frames, causing metadata corruption when sending throttled frames to userspace.
--

--- Patch [10]: [PATCH v7 10/10] can: bcm: fix data race on rx_stamp/rx_ifindex in bcm_rx_handler() ---
commit 981b0672b1caa15044dae2fc2e2b6c5ccb8394f9
Author: Oliver Hartkopp <socketcan@hartkopp.net>

can: bcm: fix data race on rx_stamp/rx_ifindex in bcm_rx_handler()

This commit moves the updates to op->rx_stamp and op->rx_ifindex inside
the bcm_rx_update_lock section to prevent data races. It also notes that
metadata is bundled correctly when running concurrently on different CPUs
for wildcard interface subscriptions.

Link: https://lore.kernel.org/linux-can/20260707145135.5BC831F00A3A@smtp.kernel.org/

> diff --git a/net/can/bcm.c b/net/can/bcm.c
> --- a/net/can/bcm.c
> +++ b/net/can/bcm.c
[ ... ]
> @@ -805,6 +800,14 @@ static void bcm_rx_handler(struct sk_buff *skb, void *data)
>  
>  	spin_lock_bh(&op->bcm_rx_update_lock);
>  
> +	/* save rx timestamp and originator for recvfrom() under lock.
> +	 * For an op subscribed on all interfaces (ifindex == 0)
> +	 * bcm_rx_handler() can run concurrently on different CPUs so
> +	 * the CAN content and the meta data must be bundled correctly.
> +	 */
> +	op->rx_stamp = skb->tstamp;
> +	op->rx_ifindex = skb->dev->ifindex;
> +

[Severity: High]
This is a pre-existing issue, but by updating op->rx_stamp and
op->rx_ifindex unconditionally here before checking the multiplex mask,
are we risking metadata corruption for throttled frames?

If a valid multiplexed frame is received and throttled, its payload is
buffered. If another frame with the same CAN ID but a non-matching
multiplex ID (or on a different interface) arrives while the throttle
timer is running, we reach this code and overwrite the global op->rx_stamp
and op->rx_ifindex.

When the timer later expires, bcm_rx_thr_flush() flushes all pending
throttled MUX frames using the shared overwritten metadata:

net/can/bcm.c:bcm_rx_thr_flush() {
    ...
    for (i = 1; i < op->nframes; i++)
        updated += bcm_rx_do_flush(op, i);
    ...
}

Which propagates to bcm_rx_changed():

net/can/bcm.c:bcm_rx_changed() {
    ...
    bcm_send_to_user(op, &head, data, 1);
    ...
}

Could this cause applications to respond on the wrong CAN bus interface if
recvfrom() returns the incorrectly overwritten ifindex?

>  	if (op->flags & RX_FILTER_ID) {
>  		/* the easiest case */
>  		bcm_rx_update_and_send(op, op->last_frames, rxframe,

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260708-bcm_fixes-v7-0-c78896b342e4@hartkopp.net?part=10

      reply	other threads:[~2026-07-08 15:48 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08 15:21 [PATCH v7 00/10] can: bcm: collected fixes - final2 :-D Oliver Hartkopp via B4 Relay
2026-07-08 15:21 ` [PATCH v7 01/10] can: bcm: defer rx_op deallocation to workqueue to fix thrtimer UAF Oliver Hartkopp via B4 Relay
2026-07-08 15:36   ` sashiko-bot
2026-07-08 15:21 ` [PATCH v7 02/10] can: bcm: fix lockless bound/ifindex race and silent RX_SETUP failure Oliver Hartkopp via B4 Relay
2026-07-08 15:36   ` sashiko-bot
2026-07-08 15:21 ` [PATCH v7 03/10] can: bcm: add locking when updating filter and timer values Oliver Hartkopp via B4 Relay
2026-07-08 15:21 ` [PATCH v7 04/10] can: bcm: fix CAN frame rx/tx statistics Oliver Hartkopp via B4 Relay
2026-07-08 15:34   ` sashiko-bot
2026-07-08 15:21 ` [PATCH v7 05/10] can: bcm: add missing rcu list annotations and operations Oliver Hartkopp via B4 Relay
2026-07-08 15:35   ` sashiko-bot
2026-07-08 15:21 ` [PATCH v7 06/10] can: bcm: extend bcm_tx_lock usage for data and timer updates Oliver Hartkopp via B4 Relay
2026-07-08 15:34   ` sashiko-bot
2026-07-08 15:21 ` [PATCH v7 07/10] can: bcm: validate frame length in bcm_rx_setup() for RTR replies Oliver Hartkopp via B4 Relay
2026-07-08 15:21 ` [PATCH v7 08/10] can: bcm: add missing device refcount for CAN filter removal Oliver Hartkopp via B4 Relay
2026-07-08 15:21 ` [PATCH v7 09/10] can: bcm: fix stale rx/tx ops after device removal Oliver Hartkopp via B4 Relay
2026-07-08 15:40   ` sashiko-bot
2026-07-08 15:21 ` [PATCH v7 10/10] can: bcm: fix data race on rx_stamp/rx_ifindex in bcm_rx_handler() Oliver Hartkopp via B4 Relay
2026-07-08 15:48   ` sashiko-bot [this message]

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=20260708154822.9F8F51F000E9@smtp.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