From: sashiko-bot@kernel.org
To: "Oliver Hartkopp" <socketcan@hartkopp.net>
Cc: "Marc Kleine-Budde" <mkl@pengutronix.de>,
linux-can@vger.kernel.org,
"Oliver Hartkopp" <socketcan@hartkopp.net>,
"Vincent Mailhol" <mailhol@kernel.org>,
"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH v13 05/11] can: bcm: add missing rcu list annotations and operations
Date: Tue, 14 Jul 2026 10:32:33 +0000 [thread overview]
Message-ID: <20260714103234.2F1681F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260714-bcm_fixes-v13-5-fd667c61099a@hartkopp.net>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] In `bcm_tx_setup()`, when updating an existing `bcm_op`, the CAN frames array (`op->frames`) is overwritten directly from userspace data using `memcpy_from_msg` without holding `bcm_tx_lock` and without using a staging buffer. This introduces a data race with concurrent transmission. Crucially, the direct overwrite stores user-provided frames into the active array before length validation. If an invalid length is provided, the function subsequently returns an error, but the corrupted frame remains active in `op->frames`. Concurrent or subsequent timer executions will transmit this malformed frame to the CAN driver, leading to out-of-bounds accesses and kernel panics.
- [Medium] Timer values in `bcm_tx_setup()` (`op->kt_ival1` and `op->kt_ival2`) are updated directly without holding `bcm_tx_lock`. Concurrently, `bcm_tx_timeout_handler()` running in softirq context reads these 64-bit `ktime_t` values without locks. On 32-bit architectures, this leads to torn reads, causing unpredictable timer behavior.
--
--- Patch [5]: [PATCH v13 05/11] can: bcm: add missing rcu list annotations and operations ---
commit 74409df5d31bac1c2081de9ebaae45419726cd9c
Author: Oliver Hartkopp <socketcan@hartkopp.net>
can: bcm: add missing rcu list annotations and operations
This commit addresses missing list_add_rcu() and list_del_rcu() calls in
the CAN broadcast manager to properly initialize and clean up bcm_op
structures. The operations are updated to protect concurrent procfs
traversals that use rcu_read_lock().
Link: https://lore.kernel.org/linux-can/20260610094654.A1FFE1F00893@smtp.kernel.org/
> diff --git a/net/can/bcm.c b/net/can/bcm.c
> index 38c3f690c1cd0..940cd9df1cca3 100644
> --- a/net/can/bcm.c
> +++ b/net/can/bcm.c
> @@ -1009,6 +1009,7 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
> struct bcm_sock *bo = bcm_sk(sk);
> struct bcm_op *op;
> struct canfd_frame *cf;
> + bool add_op_to_list = false;
> unsigned int i;
> int err;
[Severity: High]
This is a pre-existing issue, but does this code overwrite the CAN frames
directly from userspace before validating their lengths?
In bcm_tx_setup() when updating an existing bcm_op, the frames array is
updated directly without holding bcm_tx_lock and without a staging buffer:
bcm_tx_setup() {
...
err = memcpy_from_msg((u8 *)cf, msg, op->cfsiz);
if (op->flags & CAN_FD_FRAME) {
if (cf->len > 64)
err = -EINVAL;
...
}
If an invalid length is provided, the function returns -EINVAL but the
corrupted frame remains active in op->frames.
Could concurrent or subsequent timer executions transmit this malformed frame
to the CAN driver, potentially triggering out-of-bounds accesses and panics?
[Severity: Medium]
This is a pre-existing issue, but are the timer values updated locklessly?
bcm_tx_setup() updates the 64-bit ktime_t variables kt_ival1 and kt_ival2
directly without holding bcm_tx_lock:
bcm_tx_setup() {
...
op->kt_ival1 = bcm_timeval_to_ktime(msg_head->ival1);
op->kt_ival2 = bcm_timeval_to_ktime(msg_head->ival2);
...
}
Concurrently, bcm_tx_timeout_handler() in softirq context reads these
values locklessly:
bcm_tx_timeout_handler() {
...
if (op->kt_ival1 && (op->count > 0)) {
...
}
On 32-bit architectures, a 64-bit read/write is not atomic.
Could this result in torn reads where the timer handler sees a mix of old
and new 32-bit halves, leading to unpredictable timer behavior and erratic
transmission intervals?
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260714-bcm_fixes-v13-0-fd667c61099a@hartkopp.net?part=5
next prev parent reply other threads:[~2026-07-14 10:32 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 10:12 [PATCH v13 00/11] can: bcm: collected fixes - final final Oliver Hartkopp via B4 Relay
2026-07-14 10:12 ` Oliver Hartkopp
2026-07-14 10:12 ` [PATCH v13 01/11] can: bcm: defer rx_op deallocation to workqueue to fix thrtimer UAF Oliver Hartkopp via B4 Relay
2026-07-14 10:12 ` Oliver Hartkopp
2026-07-14 10:39 ` sashiko-bot
2026-07-14 10:42 ` Oliver Hartkopp
2026-07-14 10:12 ` [PATCH v13 02/11] can: bcm: fix lockless bound/ifindex race and silent RX_SETUP failure Oliver Hartkopp via B4 Relay
2026-07-14 10:12 ` Oliver Hartkopp
2026-07-14 10:33 ` sashiko-bot
2026-07-14 10:41 ` Oliver Hartkopp
2026-07-14 10:12 ` [PATCH v13 03/11] can: bcm: add locking when updating filter and timer values Oliver Hartkopp via B4 Relay
2026-07-14 10:12 ` Oliver Hartkopp
2026-07-14 10:27 ` sashiko-bot
2026-07-14 10:34 ` Oliver Hartkopp
2026-07-14 10:12 ` [PATCH v13 04/11] can: bcm: fix CAN frame rx/tx statistics Oliver Hartkopp via B4 Relay
2026-07-14 10:12 ` Oliver Hartkopp
2026-07-14 10:33 ` sashiko-bot
2026-07-14 10:35 ` Oliver Hartkopp
2026-07-14 10:12 ` [PATCH v13 05/11] can: bcm: add missing rcu list annotations and operations Oliver Hartkopp via B4 Relay
2026-07-14 10:12 ` Oliver Hartkopp
2026-07-14 10:32 ` sashiko-bot [this message]
2026-07-14 10:46 ` Oliver Hartkopp
2026-07-14 10:12 ` [PATCH v13 06/11] can: bcm: extend bcm_tx_lock usage for data and timer updates Oliver Hartkopp via B4 Relay
2026-07-14 10:12 ` Oliver Hartkopp
2026-07-14 10:34 ` sashiko-bot
2026-07-14 10:56 ` Oliver Hartkopp
2026-07-14 10:12 ` [PATCH v13 07/11] can: bcm: validate frame length in bcm_rx_setup() for RTR replies Oliver Hartkopp via B4 Relay
2026-07-14 10:12 ` Oliver Hartkopp
2026-07-14 10:12 ` [PATCH v13 08/11] can: bcm: add missing device refcount for CAN filter removal Oliver Hartkopp via B4 Relay
2026-07-14 10:12 ` Oliver Hartkopp
2026-07-14 10:12 ` [PATCH v13 09/11] can: bcm: fix stale rx/tx ops after device removal Oliver Hartkopp via B4 Relay
2026-07-14 10:12 ` Oliver Hartkopp
2026-07-14 10:44 ` sashiko-bot
2026-07-14 11:24 ` Oliver Hartkopp
2026-07-14 11:41 ` Marc Kleine-Budde
2026-07-14 11:47 ` Oliver Hartkopp
2026-07-14 12:36 ` Marc Kleine-Budde
2026-07-14 13:07 ` Oliver Hartkopp
2026-07-14 13:41 ` Marc Kleine-Budde
2026-07-14 14:40 ` Oliver Hartkopp
2026-07-14 10:12 ` [PATCH v13 10/11] can: bcm: fix data race on rx_stamp/rx_ifindex in bcm_rx_handler() Oliver Hartkopp via B4 Relay
2026-07-14 10:12 ` Oliver Hartkopp
2026-07-14 10:12 ` [PATCH v13 11/11] can: bcm: track a single source interface for ANYDEV timeout/throttle ops Oliver Hartkopp via B4 Relay
2026-07-14 10:12 ` Oliver Hartkopp
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=20260714103234.2F1681F000E9@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.