From: sashiko-bot@kernel.org
To: "Oliver Hartkopp" <socketcan@hartkopp.net>
Cc: "Vincent Mailhol" <mailhol@kernel.org>,
"Oliver Hartkopp" <socketcan@hartkopp.net>,
linux-can@vger.kernel.org,
"Marc Kleine-Budde" <mkl@pengutronix.de>,
"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH v9 02/10] can: bcm: fix lockless bound/ifindex race and silent RX_SETUP failure
Date: Thu, 09 Jul 2026 08:36:41 +0000 [thread overview]
Message-ID: <20260709083642.4F5B91F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260709-bcm_fixes-v9-2-6eebb78ccfb2@hartkopp.net>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Pre-existing issues:
- [High] Unsafe lockless list traversal and missing memory barriers for tx_ops and rx_ops lists.
- [High] Unbounded allocation of bcm_op structures allows local users to exhaust kernel memory.
- [Medium] bcm_rx_setup() silently fails to resume frame delivery for an updated RX operation if the target network device was previously unregistered.
- [Medium] Data race on bo->ifindex and bo->bound during NETDEV_DOWN handling risks torn reads and spurious errors.
--
--- Patch [2]: [PATCH v9 02/10] can: bcm: fix lockless bound/ifindex race and silent RX_SETUP failure ---
commit 48dc89358d05a6bfc0097f061749b853a77c5328
Author: Oliver Hartkopp <socketcan@hartkopp.net>
Subject: can: bcm: fix lockless bound/ifindex race and silent RX_SETUP failure
This commit fixes a data race between lockless reads of bo->bound and
bo->ifindex in bcm_sendmsg() and locked updates in bcm_notify() and other
paths. It also addresses a silent failure in bcm_rx_setup() when the
requested target device concurrently disappears.
Link: Closes: 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
> --- 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 is a pre-existing issue, but does the current iteration logic for
bo->tx_ops and bo->rx_ops in bcm_proc_show() risk wild memory accesses or
infinite loops?
bcm_proc_show() iterates over the operations holding only rcu_read_lock():
net/can/bcm.c:bcm_proc_show() {
...
list_for_each_entry_rcu(op, &bo->rx_ops, list) { ... }
...
list_for_each_entry(op, &bo->tx_ops, list) { ... }
}
Meanwhile, bcm_rx_setup() and bcm_tx_setup() insert new elements without
an RCU write memory barrier:
net/can/bcm.c:bcm_rx_setup() {
...
/* add this bcm_op to the list of the rx_ops */
list_add(&op->list, &bo->rx_ops);
}
Could this allow a local user reading /proc/net/can-bcm to crash the
system while operations are concurrently registered?
[Severity: High]
This isn't a bug introduced by this patch, but is it possible for local
users to exhaust kernel memory by creating a large number of BCM operations?
In bcm_rx_setup() and bcm_tx_setup(), new operation structures and their
associated frame arrays are allocated unboundedly:
net/can/bcm.c:bcm_rx_setup() {
...
op = kzalloc(OPSIZ, GFP_KERNEL);
...
op->frames = kmalloc_array(msg_head->nframes, op->cfsiz, GFP_KERNEL);
}
Since these allocations do not appear to enforce any per-socket limit
or charge the socket's memory quota (sk_rmem_alloc/sk_wmem_alloc), could an
unprivileged user repeatedly call sendmsg() with unique can_ids to trigger
an out-of-memory panic?
[Severity: Medium]
This is a pre-existing issue, but does bcm_rx_setup() silently fail to
resume frame delivery for updated RX operations if the target interface was
cycled?
When an interface is removed, bcm_notify() handles NETDEV_UNREGISTER by
unregistering the filter and setting op->rx_reg_dev = NULL, but leaves the
op in the active bo->rx_ops list:
net/can/bcm.c:bcm_rx_unreg() {
...
/* mark as removed subscription */
op->rx_reg_dev = NULL;
}
If an RX_SETUP request subsequently attempts to update this existing
filter, bcm_rx_setup() skips re-registration:
net/can/bcm.c:bcm_rx_setup() {
...
/* Only an update -> do not call can_rx_register() */
do_rx_register = 0;
}
Should this logic check if the operation is currently unregistered before
clearing do_rx_register?
[ ... ]
> @@ -1535,7 +1564,12 @@ static void bcm_notify(struct bcm_sock *bo, unsigned long msg,
> bo->bcm_proc_read = NULL;
> }
> #endif
> - bo->bound = 0;
> + /* Paired with the lockless fast-path check in
> + * bcm_sendmsg(); bo->ifindex itself is only ever
> + * accessed under lock_sock() so it needs no
> + * annotation.
> + */
> + WRITE_ONCE(bo->bound, 0);
> bo->ifindex = 0;
> notify_enodev = 1;
> }
[Severity: Medium]
This isn't a bug introduced by this patch, but does the handling of
NETDEV_DOWN in bcm_notify() have a data race on bo->ifindex and bo->bound?
While the target patch adds WRITE_ONCE() for bo->bound during device
removal, NETDEV_DOWN appears to read these fields locklessly:
net/can/bcm.c:bcm_notify() {
...
case NETDEV_DOWN:
if (bo->bound && bo->ifindex == dev->ifindex) {
}
If a socket is connecting to a new device while an unrelated device goes
down, could the lack of barriers allow bcm_notify() to observe a new
bo->bound=1 but the old bo->ifindex, leading to a spurious ENETDOWN error?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260709-bcm_fixes-v9-0-6eebb78ccfb2@hartkopp.net?part=2
next prev parent reply other threads:[~2026-07-09 8:36 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 8:16 [PATCH v9 00/10] can: bcm: collected fixes - final4 :-O Oliver Hartkopp via B4 Relay
2026-07-09 8:16 ` [PATCH v9 01/10] can: bcm: defer rx_op deallocation to workqueue to fix thrtimer UAF Oliver Hartkopp via B4 Relay
2026-07-09 8:34 ` sashiko-bot
2026-07-09 8:16 ` [PATCH v9 02/10] can: bcm: fix lockless bound/ifindex race and silent RX_SETUP failure Oliver Hartkopp via B4 Relay
2026-07-09 8:36 ` sashiko-bot [this message]
2026-07-09 8:16 ` [PATCH v9 03/10] can: bcm: add locking when updating filter and timer values Oliver Hartkopp via B4 Relay
2026-07-09 8:31 ` sashiko-bot
2026-07-09 8:16 ` [PATCH v9 04/10] can: bcm: fix CAN frame rx/tx statistics Oliver Hartkopp via B4 Relay
2026-07-09 8:31 ` sashiko-bot
2026-07-09 8:16 ` [PATCH v9 05/10] can: bcm: add missing rcu list annotations and operations Oliver Hartkopp via B4 Relay
2026-07-09 8:16 ` [PATCH v9 06/10] can: bcm: extend bcm_tx_lock usage for data and timer updates Oliver Hartkopp via B4 Relay
2026-07-09 8:16 ` [PATCH v9 07/10] can: bcm: validate frame length in bcm_rx_setup() for RTR replies Oliver Hartkopp via B4 Relay
2026-07-09 8:16 ` [PATCH v9 08/10] can: bcm: add missing device refcount for CAN filter removal Oliver Hartkopp via B4 Relay
2026-07-09 8:39 ` sashiko-bot
2026-07-09 8:16 ` [PATCH v9 09/10] can: bcm: fix stale rx/tx ops after device removal Oliver Hartkopp via B4 Relay
2026-07-09 8:16 ` [PATCH v9 10/10] can: bcm: fix data race on rx_stamp/rx_ifindex in bcm_rx_handler() Oliver Hartkopp via B4 Relay
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=20260709083642.4F5B91F000E9@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