From: Marc Kleine-Budde <mkl@pengutronix.de>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, linux-can@vger.kernel.org,
kernel@pengutronix.de, Lee Jones <lee@kernel.org>,
Oliver Hartkopp <socketcan@hartkopp.net>,
Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH net 2/6] can: bcm: prevent thrtimer UAF in rx path by checking RX_NO_AUTOTIMER
Date: Thu, 7 May 2026 10:22:24 +0200 [thread overview]
Message-ID: <20260507112321.439968-3-mkl@pengutronix.de> (raw)
In-Reply-To: <20260507112321.439968-1-mkl@pengutronix.de>
From: Lee Jones <lee@kernel.org>
Commit f1b4e32aca08 ("can: bcm: use call_rcu() instead of costly
synchronize_rcu()") removed the synchronize_rcu() call from
bcm_delete_rx_op() and introduced the RX_NO_AUTOTIMER flag to prevent
timers from being rearmed during deletion. However, it only applied
this check to op->timer via bcm_rx_starttimer().
It missed the fact that op->thrtimer can also be rearmed by an
in-flight bcm_rx_handler() (which runs as an RCU reader) via
bcm_rx_update_and_send(). This allows op->thrtimer to be queued after
bcm_remove_op() has already cancelled it, leading to a use-after-free
when the timer fires on the deferred-freed struct bcm_op.
Address the omission by checking the RX_NO_AUTOTIMER flag
in bcm_rx_update_and_send() before starting op->thrtimer, effectively
preventing it from being rearmed concurrently with teardown.
Signed-off-by: Lee Jones <lee@kernel.org>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Fixes: f1b4e32aca08 ("can: bcm: use call_rcu() instead of costly synchronize_rcu()")
Link: https://patch.msgid.link/20260422102239.948594-1-lee@kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
net/can/bcm.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/net/can/bcm.c b/net/can/bcm.c
index a4bef2c48a55..67e5b3149a8f 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -539,6 +539,12 @@ static void bcm_rx_update_and_send(struct bcm_op *op,
if (hrtimer_active(&op->thrtimer))
return;
+ /* bcm_remove_op() may have cancelled thrtimer concurrently with this
+ * RCU-protected handler; do not rearm it. Mirrors bcm_rx_starttimer().
+ */
+ if (op->flags & RX_NO_AUTOTIMER)
+ return;
+
/* first reception with enabled throttling mode */
if (!op->kt_lastmsg)
goto rx_changed_settime;
--
2.53.0
next prev parent reply other threads:[~2026-05-07 11:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-07 8:22 [PATCH net 0/6] pull-request: can 2026-05-07 Marc Kleine-Budde
2026-05-07 8:22 ` [PATCH net 1/6] can: raw: add locking for raw flags bitfield Marc Kleine-Budde
2026-05-07 8:22 ` Marc Kleine-Budde [this message]
2026-05-08 22:12 ` [PATCH net 2/6] can: bcm: prevent thrtimer UAF in rx path by checking RX_NO_AUTOTIMER Jakub Kicinski
2026-05-07 8:22 ` [PATCH net 3/6] can: j1939: fix wrong RX timeout for CTS hold messages Marc Kleine-Budde
2026-05-07 8:22 ` [PATCH net 4/6] can: j1939: fix lockless local-destination check Marc Kleine-Budde
2026-05-07 8:22 ` [PATCH net 5/6] can: peak: Modification of references to email accounts being deleted Marc Kleine-Budde
2026-05-07 8:22 ` [PATCH net 6/6] can: flexcan: disable all IRQ lines in flexcan_chip_interrupts_enable() Marc Kleine-Budde
2026-05-08 22:11 ` Jakub Kicinski
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=20260507112321.439968-3-mkl@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=davem@davemloft.net \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=lee@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--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