Linux CAN drivers development
 help / color / mirror / Atom feed
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,
	"Oleksij Rempel" <o.rempel@pengutronix.de>,
	"Marc Kleine-Budde" <mkl@pengutronix.de>
Subject: Re: [PATCH v2 1/6] can: bcm: defer rx_op deallocation to workqueue to fix thrtimer UAF
Date: Tue, 07 Jul 2026 07:59:36 +0000	[thread overview]
Message-ID: <20260707075936.EB93B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707-bcm_fixes-v2-1-96620c534b75@hartkopp.net>

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

Pre-existing issues:
- [High] Missing list_add_rcu() when inserting into tx_ops and rx_ops causes RCU publish/subscribe rules violation, leading to data races and potential kernel panics with concurrent procfs readers.
- [High] Lockless updates to 64-bit ktime_t fields can cause torn reads on 32-bit architectures, leading to wildly incorrect timer timeouts.
- [High] Unprotected concurrent modification of `op->frames` via `memcpy_from_msg` in `bcm_rx_setup` and `bcm_tx_setup`.
--

--- Patch [1]: [PATCH v2 1/6] can: bcm: defer rx_op deallocation to workqueue to fix thrtimer UAF ---
commit 66477b55911323fb4b8a9cc14c9ed91e1fa4bfa5
Author: Lee Jones <lee@kernel.org>

can: bcm: defer rx_op deallocation to workqueue to fix thrtimer UAF

Commit f1b4e32aca08 replaced synchronize_rcu() with call_rcu() but omitted a 
flag check in the fast-path, causing a use-after-free when thrtimer fires. 
This patch defers timer cancellation and memory deallocation to a dedicated 
unbound workqueue to safely sleep and drop socket references.

Fixes: f1b4e32aca08 ("can: bcm: use call_rcu() instead of costly synchronize_rcu()")

> ---
> net/can/bcm.c | 37 ++++++++++++++++++++++++++++++++++---
>  1 file changed, 34 insertions(+), 3 deletions(-)
> 
> 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: High]
This is a pre-existing issue, but does the list insertion in bcm_tx_setup() 
and bcm_rx_setup() use list_add() instead of list_add_rcu()?

If a local unprivileged user repeatedly adds new TX/RX operations while 
concurrently reading /proc/net/can-bcm/<inode>, can bcm_proc_show() observe 
partially initialized bcm_op entries? 

bcm_proc_show() iterates over rx_ops using list_for_each_entry_rcu() and 
tx_ops using list_for_each_entry() without holding the socket lock. Could 
the missing smp_store_release() barrier in list_add() lead to torn reads of 
uninitialized list pointers and potential kernel panics?

[Severity: High]
This isn't a bug introduced by this patch, but are the 64-bit ktime_t 
fields (op->kt_ival1 and op->kt_ival2) updated locklessly in bcm_tx_setup() 
and bcm_rx_setup()?

On 32-bit architectures, can these lockless updates cause torn reads when 
bcm_tx_timeout_handler() or bcm_rx_timeout_handler() concurrently read 
these fields in softirq context to arm the hrtimer? 

Could this lead to wildly incorrect timer expirations, potentially stalling 
CAN transmissions indefinitely or flooding the bus?

[ ... ]

> @@ -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;
>  
>  		/* ifindex for timeout events w/o previous frame reception */

[Severity: High]
This is a pre-existing issue, but is it safe to write directly into the 
active op->frames using memcpy_from_msg() without holding a lock?

When updating an existing BCM operation, bcm_tx_setup() and bcm_rx_setup() 
appear to copy user data directly into op->frames locklessly. Because 
memcpy_from_msg() can sleep on user faults, is there a significant race 
window here?

Concurrently, bcm_can_tx() reads op->frames to transmit data, and 
bcm_rx_cmp_to_index() reads op->frames to filter incoming packets. Could 
this allow partially updated or torn CAN frames to be transmitted onto the 
physical CAN bus?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260707-bcm_fixes-v2-0-96620c534b75@hartkopp.net?part=1

  reply	other threads:[~2026-07-07  7:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07  7:27 [PATCH v2 0/6] can: bcm: collected fixes Oliver Hartkopp via B4 Relay
2026-07-07  7:27 ` [PATCH v2 1/6] can: bcm: defer rx_op deallocation to workqueue to fix thrtimer UAF Oliver Hartkopp via B4 Relay
2026-07-07  7:59   ` sashiko-bot [this message]
2026-07-07  7:27 ` [PATCH v2 2/6] can: bcm: fix lockless bound/ifindex race and silent RX_SETUP failure Oliver Hartkopp via B4 Relay
2026-07-07  8:13   ` sashiko-bot
2026-07-07  7:27 ` [PATCH v2 3/6] can: bcm: add locking when updating filter and timer values Oliver Hartkopp via B4 Relay
2026-07-07  8:28   ` sashiko-bot
2026-07-07  7:27 ` [PATCH v2 4/6] can: bcm: fix CAN frame rx/tx statistics Oliver Hartkopp via B4 Relay
2026-07-07  8:37   ` sashiko-bot
2026-07-07  7:27 ` [PATCH v2 5/6] can: bcm: add missing rcu list annotations and operations Oliver Hartkopp via B4 Relay
2026-07-07  8:50   ` sashiko-bot
2026-07-07  7:27 ` [PATCH v2 6/6] can: bcm: extend bcm_tx_lock usage for data and timer updates Oliver Hartkopp via B4 Relay
2026-07-07  8:58   ` 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=20260707075936.EB93B1F000E9@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