Linux CAN drivers development
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: penguin-kernel@I-love.SAKURA.ne.jp
Cc: linux-can@vger.kernel.org, mkl@pengutronix.de,
	o.rempel@pengutronix.de, robin@protonic.nl,
	kernel@pengutronix.de, socketcan@hartkopp.net, kuba@kernel.org
Subject: Re: [PATCH v13 4/6] can: j1939: add a safeguard to __j1939_ecu_release_work()
Date: Mon, 16 Nov 2026 18:51:08 +0000	[thread overview]
Message-ID: <179485506852.3132.632621305382559314@kernel.org> (raw)
In-Reply-To: <37069926-e687-4062-97a9-db0643645f82@I-love.SAKURA.ne.jp>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message for "can: j1939: add a safeguard to
  __j1939_ecu_release_work()" describes a bug that cannot happen in the…

--

can: j1939: add a safeguard to __j1939_ecu_release_work()

This patch adds a hrtimer_cancel() of ecu->ac_timer, wrapped in WARN_ON(),
to __j1939_ecu_release_work() before the ECU is freed. The commit message
says this fixes a use-after-free where a pending ac_timer fires after
__j1939_ecu_release() or j1939_module_exit().

> diff --git a/net/can/j1939/bus.c b/net/can/j1939/bus.c
> index 0aeeee1491e4f..3924404152a2f 100644
> --- a/net/can/j1939/bus.c
> +++ b/net/can/j1939/bus.c
> @@ -22,6 +22,11 @@ static void __j1939_ecu_release_work(struct work_struct *work)
>  	write_lock_bh(&priv->lock);
>  	list_del(&ecu->list);
>  	write_unlock_bh(&priv->lock);
> +	/* There can't be any ref on this ECU because __j1939_ecu_release()
> +	 * was already called. But we need to make sure that
> +	 * j1939_ecu_timer_handler() is no longer running before kfree().
> +	 */
> +	WARN_ON(hrtimer_cancel(&ecu->ac_timer));

[Severity: Low]
Is the commit message accurate about what this fixes? It says:

  Since pending ecu->ac_timer is not canceled during j1939_ecu_unmap_all()
  or __j1939_rx_release(), ecu->ac_timer can call j1939_ecu_timer_handler()
  after __j1939_ecu_release() or j1939_module_exit() (i.e. causing UAF).

A pending ac_timer always holds an ECU reference. j1939_ecu_timer_start()
takes one before it arms the timer, and does not arm the timer if that
fails:

net/can/j1939/bus.c:j1939_ecu_timer_start() {
    ...
	if (!j1939_ecu_get(ecu))
		return;
    ...
	hrtimer_start(&ecu->ac_timer, ms_to_ktime(250),
		      HRTIMER_MODE_REL_SOFT);
}

That reference is dropped only in j1939_ecu_timer_handler(), or in
j1939_ecu_timer_cancel() when hrtimer_cancel() actually dequeues the timer:

net/can/j1939/bus.c:j1939_ecu_timer_cancel() {
	if (hrtimer_cancel(&ecu->ac_timer))
		/* Drop the ref from j1939_ecu_timer_start(). */
		j1939_ecu_put(ecu);
}

So __j1939_ecu_release() can't be reached while the timer is queued. The
ECU's reference on priv keeps priv alive. Since "can: j1939: fix
possibility of UAF on module unload", priv also holds a try_module_get()
reference, so the module stays loaded too.

Doesn't that mean the hrtimer_cancel() here always returns 0, so the
WARN_ON() can never fire? The comment above it says the same thing.

The only effect of the added hrtimer_cancel() is a wait in
hrtimer_cancel_wait_running(). It waits for a handler that has already
dropped the last reference but hasn't yet returned to __run_hrtimer().

For a HRTIMER_NORESTART callback, __run_hrtimer() doesn't touch timer
memory after the callback returns. That makes this extra hardening, not a
fix for a pending-timer UAF.

The patch also doesn't change j1939_ecu_unmap_all() or __j1939_rx_release(),
the teardown paths the message names. Not cancelling the timer there causes
a refcount leak rather than a UAF. A later patch in this series fixes that
leak: "can: j1939: fix "struct j1939_ecu" refcount leak".

This patch carries Fixes: and Cc: stable. Could the commit message describe
the change as a hardening wait for an in-flight handler, rather than as a
fix for a pending-timer UAF?

>  	netdev_put(priv->ndev, &ecu->priv_dev_tracker);
>  	kfree(ecu);
>  	j1939_priv_put(priv);

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/7cc08b0f-290e-464b-ab13-0a5ce3c57f4f%40I-love.SAKURA.ne.jp

  reply	other threads:[~2026-11-16 18:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15  5:34 [PATCH v13 0/6] can: j1939: make module more robust Tetsuo Handa
2026-11-15  5:34 ` [PATCH v13 1/6] can: j1939: fix possibility of UAF on module unload Tetsuo Handa
2026-11-15  6:01   ` sashiko-bot
2026-11-15  5:34 ` [PATCH v13 2/6] can: j1939: add a safeguard to __j1939_priv_release_work() Tetsuo Handa
2026-11-16 18:51   ` netdev-bot+sashiko
2026-11-15  5:35 ` [PATCH v13 3/6] can: j1939: fix possibility of list corruption in __j1939_ecu_release() Tetsuo Handa
2026-11-16 18:51   ` netdev-bot+sashiko
2026-11-15  5:35 ` [PATCH v13 4/6] can: j1939: add a safeguard to __j1939_ecu_release_work() Tetsuo Handa
2026-11-16 18:51   ` netdev-bot+sashiko [this message]
2026-11-15  5:35 ` [PATCH v13 5/6] can: j1939: fix "struct j1939_ecu" refcount leak Tetsuo Handa
2026-11-16 18:51   ` netdev-bot+sashiko
2026-11-15  5:36 ` [PATCH v13 6/6] can: j1939: fix possibility of hard-lockup/deadlock in j1939_ecu_timer_cancel() Tetsuo Handa
2026-11-15  5:51   ` sashiko-bot
2026-11-16 18:51   ` netdev-bot+sashiko

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=179485506852.3132.632621305382559314@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=o.rempel@pengutronix.de \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=robin@protonic.nl \
    --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