All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Oliver Hartkopp" <socketcan@hartkopp.net>
Cc: "Oleksij Rempel" <o.rempel@pengutronix.de>,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	linux-can@vger.kernel.org,
	"Oliver Hartkopp" <socketcan@hartkopp.net>,
	"Vincent Mailhol" <mailhol@kernel.org>
Subject: Re: [PATCH v12 01/11] can: bcm: defer rx_op deallocation to workqueue to fix thrtimer UAF
Date: Thu, 09 Jul 2026 20:40:21 +0000	[thread overview]
Message-ID: <20260709204021.D93D91F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260709-bcm_fixes-v12-1-61c06291bf1c@hartkopp.net>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Pre-existing issues:
- [Critical] In-place modification of `op->frames` via `memcpy_from_msg()` causes data races and heap Out-Of-Bounds reads
- [High] `bcm_rx_setup` and `bcm_tx_setup` add elements to RCU-protected lists using `list_add` instead of `list_add_rcu`
- [High] `bcm_proc_show` iterates over the RCU-protected list `bo->tx_ops` using `list_for_each_entry` instead of `list_for_each_entry_rcu`
--

--- Patch [1]: [PATCH v12 01/11] can: bcm: defer rx_op deallocation to workqueue to fix thrtimer UAF ---
commit 49ab02a8012b5c460ed2235ffc2a8c72c64c1653
Author: Lee Jones <lee@kernel.org>
Subject: can: bcm: defer rx_op deallocation to workqueue to fix thrtimer UAF

Commit f1b4e32aca08 ("can: bcm: use call_rcu() instead of costly
synchronize_rcu()") replaced synchronize_rcu() in bcm_delete_rx_op()
with call_rcu() and introduced the RX_NO_AUTOTIMER flag.

However, this flag check was omitted for thrtimer in the packet rx
fast-path. During BCM RX operation teardown, a concurrent RCU reader
can race and re-arm thrtimer via bcm_rx_update_and_send() after
call_rcu() has been scheduled. Once the RCU grace period elapses,
bcm_op is freed and the subsequently firing thrtimer dereferences
the deallocated op.

> diff --git a/net/can/bcm.c b/net/can/bcm.c
> index a4bef2c48a559..bdf53241bd7b3 100644
> --- a/net/can/bcm.c
> +++ b/net/can/bcm.c
[ ... ]
> @@ -1060,6 +1081,7 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
>  
>  		/* bcm_can_tx / bcm_tx_timeout_handler needs this */
>  		op->sk = sk;
> +		sock_hold(sk);
>  		op->ifindex = ifindex;
>  
>  		/* initialize uninitialized (kzalloc) structure */

[Severity: Critical]
This is a pre-existing issue, but does bcm_tx_setup() allow invalid frames
to be sent?

If a user creates an active TX operation with a timer, and then updates it
by calling sendmsg() with a frame length greater than 64:

bcm_tx_setup()
  err = memcpy_from_msg((u8 *)cf, msg, op->cfsiz);
  if (op->flags & CAN_FD_FRAME) {
      if (cf->len > 64)
          err = -EINVAL;

Because memcpy_from_msg() modifies op->frames before validation,
the corrupted frame remains on error and bcm_tx_setup() returns -EINVAL.

However, the timer continues running and transmits the corrupted frame
via bcm_tx_timeout_handler().  Since can_send() and drivers blindly trust
cf->len, could CAN drivers read past the 72-byte SKB buffer into adjacent
heap memory?

[Severity: High]
This isn't a bug introduced by this patch, but are we using the correct
list insertion function here?

bcm_tx_setup() inserts new elements into bo->tx_ops using list_add()
instead of list_add_rcu(). Because list_add() lacks smp_store_release()
barriers, can a concurrent RCU reader like bcm_proc_show() read the list
pointer before the CPU writes the kzalloc initialization, leading to a
wild pointer dereference?

> @@ -1221,6 +1243,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
>  
>  		/* bcm_can_tx / bcm_tx_timeout_handler needs this */
>  		op->sk = sk;
> +		sock_hold(sk);
>  		op->ifindex = ifindex;
>  

[Severity: Critical]
This is a pre-existing issue, but does bcm_rx_setup() suffer from a similar
data race as bcm_tx_setup()?

bcm_rx_setup() also modifies op->frames directly:

bcm_rx_setup()
  err = memcpy_from_msg(op->frames, msg, msg_head->nframes * op->cfsiz);

Can this be modified concurrently with bcm_rx_handler() without
synchronization?

[Severity: High]
This isn't a bug introduced by this patch, but does bcm_rx_setup() also insert
new elements into bo->rx_ops using list_add() without RCU barriers,
similar to bcm_tx_setup()?

[Severity: High]
This is a pre-existing issue, but does bcm_proc_show() safely traverse
the RCU list?

bcm_proc_show() iterates over the RCU-protected list bo->tx_ops:

bcm_proc_show()
  list_for_each_entry(op, &bo->tx_ops, list) {

Since list_for_each_entry() lacks the READ_ONCE() wrapper for fetching
pos->next, if bcm_delete_tx_op() deletes an element concurrently, could the
compiler reload the list pointer unpredictably and violate RCU safety
guarantees?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260709-bcm_fixes-v12-0-61c06291bf1c@hartkopp.net?part=1

  reply	other threads:[~2026-07-09 20:40 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09 20:22 [PATCH v12 00/11] can: bcm: collected fixes - final7 \o/ \o/ Oliver Hartkopp
2026-07-09 20:22 ` Oliver Hartkopp via B4 Relay
2026-07-09 20:22 ` [PATCH v12 01/11] can: bcm: defer rx_op deallocation to workqueue to fix thrtimer UAF Oliver Hartkopp
2026-07-09 20:22   ` Oliver Hartkopp via B4 Relay
2026-07-09 20:40   ` sashiko-bot [this message]
2026-07-09 20:22 ` [PATCH v12 02/11] can: bcm: fix lockless bound/ifindex race and silent RX_SETUP failure Oliver Hartkopp
2026-07-09 20:22   ` Oliver Hartkopp via B4 Relay
2026-07-10  0:40   ` sashiko-bot
2026-07-09 20:22 ` [PATCH v12 03/11] can: bcm: add locking when updating filter and timer values Oliver Hartkopp
2026-07-09 20:22   ` Oliver Hartkopp via B4 Relay
2026-07-09 20:38   ` sashiko-bot
2026-07-09 20:22 ` [PATCH v12 04/11] can: bcm: fix CAN frame rx/tx statistics Oliver Hartkopp
2026-07-09 20:22   ` Oliver Hartkopp via B4 Relay
2026-07-09 20:35   ` sashiko-bot
2026-07-09 20:22 ` [PATCH v12 05/11] can: bcm: add missing rcu list annotations and operations Oliver Hartkopp
2026-07-09 20:22   ` Oliver Hartkopp via B4 Relay
2026-07-09 20:35   ` sashiko-bot
2026-07-09 20:22 ` [PATCH v12 06/11] can: bcm: extend bcm_tx_lock usage for data and timer updates Oliver Hartkopp
2026-07-09 20:22   ` Oliver Hartkopp via B4 Relay
2026-07-09 20:22 ` [PATCH v12 07/11] can: bcm: validate frame length in bcm_rx_setup() for RTR replies Oliver Hartkopp
2026-07-09 20:22   ` Oliver Hartkopp via B4 Relay
2026-07-09 20:22 ` [PATCH v12 08/11] can: bcm: add missing device refcount for CAN filter removal Oliver Hartkopp
2026-07-09 20:22   ` Oliver Hartkopp via B4 Relay
2026-07-09 20:35   ` sashiko-bot
2026-07-09 20:22 ` [PATCH v12 09/11] can: bcm: fix stale rx/tx ops after device removal Oliver Hartkopp
2026-07-09 20:22   ` Oliver Hartkopp via B4 Relay
2026-07-09 20:40   ` sashiko-bot
2026-07-09 20:22 ` [PATCH v12 10/11] can: bcm: fix data race on rx_stamp/rx_ifindex in bcm_rx_handler() Oliver Hartkopp
2026-07-09 20:22   ` Oliver Hartkopp via B4 Relay
2026-07-09 20:44   ` sashiko-bot
2026-07-09 20:22 ` [PATCH v12 11/11] can: bcm: track a single source interface for ANYDEV timeout/throttle ops Oliver Hartkopp
2026-07-09 20:22   ` 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=20260709204021.D93D91F000E9@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.