From: sashiko-bot@kernel.org
To: "Oliver Hartkopp" <socketcan@hartkopp.net>
Cc: "Oleksij Rempel" <o.rempel@pengutronix.de>,
"Marc Kleine-Budde" <mkl@pengutronix.de>,
"Vincent Mailhol" <mailhol@kernel.org>,
linux-can@vger.kernel.org,
"Oliver Hartkopp" <socketcan@hartkopp.net>
Subject: Re: [PATCH v4 2/7] can: bcm: fix lockless bound/ifindex race and silent RX_SETUP failure
Date: Tue, 07 Jul 2026 14:53:14 +0000 [thread overview]
Message-ID: <20260707145314.CC49F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707-bcm_fixes-v4-2-aa87b8b9d33f@hartkopp.net>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Unprotected modification of RX operation buffers from process context races with softirq receive handlers.
--
--- Patch [2]: [PATCH v4 2/7] can: bcm: fix lockless bound/ifindex race and silent RX_SETUP failure ---
commit 9ced6bfc5d2fbc4191944246b0050dabfa00318e
Author: Oliver Hartkopp <socketcan@hartkopp.net>
can: bcm: fix lockless bound/ifindex race and silent RX_SETUP failure
This commit fixes a race condition between bcm_sendmsg() and socket state
modifications by moving the ifindex read inside the socket lock. It also
fixes a silent failure when a target device disappears concurrently during
RX_SETUP.
Link: https://lore.kernel.org/linux-can/CAGp+u1aBK8QVjsvAxM2Ldzep4rEbsP9x_pV3At4g=h1kVEtyhA@mail.gmail.com/
> diff --git a/net/can/bcm.c b/net/can/bcm.c
> index bdf53241bd7b3..b612135b017d1 100644
> --- a/net/can/bcm.c
> +++ b/net/can/bcm.c
> @@ -1323,6 +1323,11 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
>
> op->rx_reg_dev = dev;
> dev_put(dev);
> + } else {
> + /* the requested device is gone - do not
> + * silently succeed without registering
> + */
> + err = -ENODEV;
> }
[Severity: High]
This isn't a bug introduced by this patch, but since we are modifying
bcm_rx_setup(), I noticed a potential race condition. Does the process
context modification of RX buffers race with the softirq receive handlers?
When a user application repeatedly updates a BCM RX_SETUP filter via
sendmsg(), it modifies op->frames and resets op->last_frames directly in
process context:
net/can/bcm.c:bcm_rx_setup() {
...
err = memcpy_from_msg(op->frames, msg,
msg_head->nframes * op->cfsiz);
if (err < 0)
return err;
/* clear last_frames to indicate 'nothing received' */
memset(op->last_frames, 0, msg_head->nframes * op->cfsiz);
...
}
Concurrently, if a matching CAN frame arrives, will bcm_rx_handler() in
softirq context locklessly read op->frames and update op->last_frames?
net/can/bcm.c:bcm_rx_handler() {
...
for (i = 1; i < op->nframes; i++) {
if ((get_u64(op->frames, 0) & get_u64(rxframe, 0)) ==
(get_u64(op->frames, 0) &
get_u64(op->frames + op->cfsiz * i, 0))) {
bcm_rx_cmp_to_index(op, i, rxframe,
traffic_flags);
break;
...
}
Could this lead to torn reads or writes if the filter logic misfires while
these buffers are observed in an inconsistent state, potentially delivering
corrupted or duplicate CAN frames to userspace?
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260707-bcm_fixes-v4-0-aa87b8b9d33f@hartkopp.net?part=2
next prev parent reply other threads:[~2026-07-07 14:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 14:32 [PATCH v4 0/7] can: bcm: collected fixes Oliver Hartkopp via B4 Relay
2026-07-07 14:32 ` [PATCH v4 1/7] can: bcm: defer rx_op deallocation to workqueue to fix thrtimer UAF Oliver Hartkopp via B4 Relay
2026-07-07 14:47 ` sashiko-bot
2026-07-07 14:32 ` [PATCH v4 2/7] can: bcm: fix lockless bound/ifindex race and silent RX_SETUP failure Oliver Hartkopp via B4 Relay
2026-07-07 14:53 ` sashiko-bot [this message]
2026-07-07 14:32 ` [PATCH v4 3/7] can: bcm: add locking when updating filter and timer values Oliver Hartkopp via B4 Relay
2026-07-07 14:48 ` sashiko-bot
2026-07-07 14:32 ` [PATCH v4 4/7] can: bcm: fix CAN frame rx/tx statistics Oliver Hartkopp via B4 Relay
2026-07-07 14:54 ` sashiko-bot
2026-07-07 14:32 ` [PATCH v4 5/7] can: bcm: add missing rcu list annotations and operations Oliver Hartkopp via B4 Relay
2026-07-07 14:49 ` sashiko-bot
2026-07-07 14:32 ` [PATCH v4 6/7] can: bcm: extend bcm_tx_lock usage for data and timer updates Oliver Hartkopp via B4 Relay
2026-07-07 14:38 ` Marc Kleine-Budde
2026-07-07 14:48 ` Oliver Hartkopp
2026-07-07 14:32 ` [PATCH v4 7/7] can: bcm: validate frame length in bcm_rx_setup() for RTR replies Oliver Hartkopp via B4 Relay
2026-07-07 14:51 ` 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=20260707145314.CC49F1F000E9@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