From: sashiko-bot@kernel.org
To: "Oliver Hartkopp" <socketcan@hartkopp.net>
Cc: "Marc Kleine-Budde" <mkl@pengutronix.de>,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
"Vincent Mailhol" <mailhol@kernel.org>,
"Oliver Hartkopp" <socketcan@hartkopp.net>,
linux-can@vger.kernel.org
Subject: Re: [PATCH v2 4/6] can: bcm: fix CAN frame rx/tx statistics
Date: Tue, 07 Jul 2026 08:37:13 +0000 [thread overview]
Message-ID: <20260707083713.8A8561F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707-bcm_fixes-v2-4-96620c534b75@hartkopp.net>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Concurrent execution of bcm_rx_handler() leads to unprotected data races and potential 64-bit torn writes on op->rx_stamp and op->rx_ifindex, causing metadata corruption.
--
--- Patch [4]: [PATCH v2 4/6] can: bcm: fix CAN frame rx/tx statistics ---
commit c40daefa12b560d84d208b978162b5b62f34aade
Author: Oliver Hartkopp <socketcan@hartkopp.net>
can: bcm: fix CAN frame rx/tx statistics
This commit fixes a KCSAN-detected data race in bcm_rx_handler() when multiple
CAN frames are processed concurrently. It transitions the statistics counters
to atomic long operations and consolidates overflow checking into a new
bcm_update_stats() function.
> diff --git a/net/can/bcm.c b/net/can/bcm.c
> --- a/net/can/bcm.c
> +++ b/net/can/bcm.c
[ ... ]
> @@ -742,7 +752,7 @@ static void bcm_rx_handler(struct sk_buff *skb, void *data)
> /* save originator for recvfrom() */
> op->rx_ifindex = skb->dev->ifindex;
[Severity: High]
This is a pre-existing issue, but can concurrent execution of bcm_rx_handler()
lead to unprotected data races on op->rx_stamp and op->rx_ifindex here?
If an application creates a BCM socket listening on all interfaces (ifindex=0),
and multiple CAN frames arrive concurrently from different interfaces matching
the same bcm_op, bcm_rx_handler() can be invoked concurrently on multiple CPUs.
CPU A and CPU B could both write op->rx_stamp and op->rx_ifindex outside of
any lock. If CPU A then acquires the lock and reads these values later in
bcm_send_to_user():
net/can/bcm.c:bcm_send_to_user() {
...
/* restore rx timestamp */
skb->tstamp = op->rx_stamp;
...
addr->can_ifindex = op->rx_ifindex;
...
}
Could CPU A pick up CPU B's ifindex or a torn timestamp? This might lead to
CAN frames being delivered to userspace with mismatched interface indices or
corrupted 64-bit timestamps on 32-bit systems, potentially breaking
time-sensitive control loops.
> /* update statistics */
> - op->frames_abs++;
> + bcm_update_stats(op);
>
> /* snapshot the flag under lock: op->flags/op->frames may be updated
> * concurrently by bcm_rx_setup(). Do not call bcm_can_tx() while
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260707-bcm_fixes-v2-0-96620c534b75@hartkopp.net?part=4
next prev parent reply other threads:[~2026-07-07 8:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 7:27 [PATCH v2 0/6] can: bcm: collected fixes Oliver Hartkopp via B4 Relay
2026-07-07 7:27 ` [PATCH v2 1/6] can: bcm: defer rx_op deallocation to workqueue to fix thrtimer UAF Oliver Hartkopp via B4 Relay
2026-07-07 7:59 ` sashiko-bot
2026-07-07 7:27 ` [PATCH v2 2/6] can: bcm: fix lockless bound/ifindex race and silent RX_SETUP failure Oliver Hartkopp via B4 Relay
2026-07-07 8:13 ` sashiko-bot
2026-07-07 7:27 ` [PATCH v2 3/6] can: bcm: add locking when updating filter and timer values Oliver Hartkopp via B4 Relay
2026-07-07 8:28 ` sashiko-bot
2026-07-07 7:27 ` [PATCH v2 4/6] can: bcm: fix CAN frame rx/tx statistics Oliver Hartkopp via B4 Relay
2026-07-07 8:37 ` sashiko-bot [this message]
2026-07-07 7:27 ` [PATCH v2 5/6] can: bcm: add missing rcu list annotations and operations Oliver Hartkopp via B4 Relay
2026-07-07 8:50 ` sashiko-bot
2026-07-07 7:27 ` [PATCH v2 6/6] can: bcm: extend bcm_tx_lock usage for data and timer updates Oliver Hartkopp via B4 Relay
2026-07-07 8:58 ` sashiko-bot
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=20260707083713.8A8561F000E9@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