From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Oliver Hartkopp via B4 Relay <devnull+socketcan.hartkopp.net@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>,
Urs Thuermann <urs.thuermann@volkswagen.de>,
Vincent Mailhol <mailhol@kernel.org>,
linux-can@vger.kernel.org, linux-kernel@vger.kernel.org,
Oliver Hartkopp <socketcan@hartkopp.net>,
syzbot+75e5e4ae00c3b4bb544e@syzkaller.appspotmail.com
Subject: Re: [PATCH v3 2/3] can: bcm: add locking when updating filter and timer values
Date: Mon, 2 Mar 2026 11:21:38 +0100 [thread overview]
Message-ID: <20260302-gregarious-poetic-wasp-e73cee-mkl@pengutronix.de> (raw)
In-Reply-To: <20260219-bcm_spin_lock_init-v3-2-c61026740d7b@hartkopp.net>
[-- Attachment #1: Type: text/plain, Size: 2928 bytes --]
The nipa/ai-review bot found these problems:
| https://netdev-ai.bots.linux.dev/ai-review.html?id=873e6dfb-7d8e-4f4d-98ef-a89fcedb701a
commit 6ea1c1c7064ff2b5c2a0434ec61d62fd3463fc12
Author: Oliver Hartkopp <socketcan@hartkopp.net>
can: bcm: add locking when updating filter and timer values
This commit addresses a KCSAN-detected data race in the CAN BCM protocol
by adding locking to protect simultaneous access to timer and filter values
during updates in bcm_rx_setup(). The race was benign functionally but is
resolved by introducing spin_lock_bh() protection.
Closes: https://lore.kernel.org/linux-can/6975d5cf.a00a0220.33ccc7.0022.GAE@google.com/
> diff --git a/net/can/bcm.c b/net/can/bcm.c
> index fd9fa072881e..0a3dc5500e14 100644
> --- a/net/can/bcm.c
> +++ b/net/can/bcm.c
> @@ -125,6 +125,7 @@ struct bcm_op {
> struct sock *sk;
> struct net_device *rx_reg_dev;
> spinlock_t bcm_tx_lock; /* protect currframe/count in runtime updates */
> + spinlock_t bcm_rx_update_lock; /* protect update of filter data */
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The comment says this lock protects "update of filter data" but the lock
is also used to protect timer data updates (ival1, ival2, kt_ival1,
kt_ival2, kt_lastmsg) in the SETTIMER block later in bcm_rx_setup().
Should the comment be more accurate and say "protect update of filter and
timer data"?
Additionally, this lock differs from bcm_tx_lock in that it's only taken on
the writer side (bcm_rx_setup) while the reader-side softirq handlers
(bcm_rx_handler, bcm_rx_timeout_handler, bcm_rx_thr_handler) never acquire
this lock. The protection is asymmetric -- it provides KCSAN suppression
and local-CPU softirq exclusion through spin_lock_bh(), but doesn't
synchronize against readers on other CPUs.
Is this asymmetric locking strategy intentional, or should the comment
clarify the actual protection model?
> };
>
> struct bcm_sock {
[ ... ]
> @@ -1263,10 +1286,13 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
> if (op->flags & SETTIMER) {
>
> /* set timer value */
> + spin_lock_bh(&op->bcm_rx_update_lock);
> op->ival1 = msg_head->ival1;
> op->ival2 = msg_head->ival2;
> op->kt_ival1 = bcm_timeval_to_ktime(msg_head->ival1);
> op->kt_ival2 = bcm_timeval_to_ktime(msg_head->ival2);
> + op->kt_lastmsg = 0;
> + spin_unlock_bh(&op->bcm_rx_update_lock);
This is where the lock also protects timer data, which confirms the comment
at the struct field declaration should mention timer data protection as well.
[ ... ]
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung Nürnberg | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-03-02 10:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-19 16:51 [PATCH v3 0/3] can: bcm: add/fix locking for config updates at runtime Oliver Hartkopp via B4 Relay
2026-02-19 16:51 ` [PATCH v3 1/3] can: bcm: fix locking for bcm_op runtime updates Oliver Hartkopp via B4 Relay
2026-02-19 16:51 ` [PATCH v3 2/3] can: bcm: add locking when updating filter and timer values Oliver Hartkopp via B4 Relay
2026-03-02 10:21 ` Marc Kleine-Budde [this message]
2026-03-23 9:42 ` Marc Kleine-Budde
2026-03-23 9:46 ` Oliver Hartkopp
2026-02-19 16:51 ` [PATCH v3 3/3] can: statistics: add missing atomic access in hot path Oliver Hartkopp via B4 Relay
2026-03-02 10:22 ` 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=20260302-gregarious-poetic-wasp-e73cee-mkl@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=davem@davemloft.net \
--cc=devnull+socketcan.hartkopp.net@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=socketcan@hartkopp.net \
--cc=syzbot+75e5e4ae00c3b4bb544e@syzkaller.appspotmail.com \
--cc=urs.thuermann@volkswagen.de \
/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®