Linux CAN drivers development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Oliver Hartkopp" <socketcan@hartkopp.net>
Cc: "Marc Kleine-Budde" <mkl@pengutronix.de>,
	"Oleksij Rempel" <o.rempel@pengutronix.de>,
	"Vincent Mailhol" <mailhol@kernel.org>,
	"Oliver Hartkopp" <socketcan@hartkopp.net>,
	linux-can@vger.kernel.org
Subject: Re: [PATCH v13 01/11] can: bcm: defer rx_op deallocation to workqueue to fix thrtimer UAF
Date: Tue, 14 Jul 2026 10:39:49 +0000	[thread overview]
Message-ID: <20260714103950.538C31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260714-bcm_fixes-v13-1-fd667c61099a@hartkopp.net>

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

New issues:
- [High] Module exit sequence destroys the socket slab cache before flushing the deferred workqueue, causing a kernel warning and slab cache leak.

Pre-existing issues:
- [High] Missing RCU-safe list primitives for rx_ops and tx_ops list modifications and traversals, causing potential crashes during procfs reads.
--

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

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

This commit fixes a use-after-free by deferring the deallocation of
bcm_op to a dedicated workqueue instead of using call_rcu(). It ensures
that hrtimer cancellation and memory freeing occur in a sleepable context.
It also takes a reference on the socket while the work is pending to
prevent the socket from being freed prematurely.

> 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 can traversing the RCU-protected tx_ops
and rx_ops lists without RCU-safe primitives cause crashes during procfs
reads?

Looking at bcm_tx_setup() and bcm_rx_setup(), list_add() is used instead
of list_add_rcu(), which lacks the smp_store_release() memory barriers:

bcm_tx_setup() {
    ...
    /* add this bcm_op to the list of the tx_ops */
    list_add(&op->list, &bo->tx_ops);
    ...
}

Concurrently, if another thread reads /proc/net/can-bcm, bcm_proc_show()
traverses bo->tx_ops locklessly under rcu_read_lock() using the non-RCU
list_for_each_entry():

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

Can weakly ordered CPUs reorder the initialization of the bcm_op structure
after its insertion, allowing lockless RCU readers to observe uninitialized
memory and crash?

[ ... ]

> @@ -1869,6 +1898,8 @@ static void __exit bcm_module_exit(void)
>  	can_proto_unregister(&bcm_can_proto);
>  	unregister_netdevice_notifier(&canbcm_notifier);
>  	unregister_pernet_subsys(&canbcm_pernet_ops);
> +	rcu_barrier();
> +	destroy_workqueue(bcm_wq);
>  }

[Severity: High]
Does this module exit sequence destroy the socket slab cache before flushing
the deferred workqueue?

Looking at bcm_free_op_work(), the deferred work item drops the final socket
reference:

bcm_free_op_work() {
    ...
    sock_put(op->sk);
    kfree(op);
}

If there are pending work items in bcm_wq during module unload,
can_proto_unregister() will call kmem_cache_destroy() on the protocol's
slab cache while sockets are still allocated.

Will this cause a kernel warning and a slab cache leak, since
destroy_workqueue() runs after can_proto_unregister() and will attempt to
free sockets into the destroyed slab?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260714-bcm_fixes-v13-0-fd667c61099a@hartkopp.net?part=1

  reply	other threads:[~2026-07-14 10:39 UTC|newest]

Thread overview: 32+ 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 ` [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:39   ` sashiko-bot [this message]
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: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: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: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:32   ` sashiko-bot
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: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 ` [PATCH v13 08/11] can: bcm: add missing device refcount for CAN filter removal Oliver Hartkopp via B4 Relay
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: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 ` [PATCH v13 11/11] can: bcm: track a single source interface for ANYDEV timeout/throttle ops 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=20260714103950.538C31F000E9@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