Linux CAN drivers development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tetsuo Handa" <penguin-kernel@I-love.SAKURA.ne.jp>,
	linux-can@vger.kernel.org
Cc: "Marc Kleine-Budde" <mkl@pengutronix.de>,
	"Oliver Hartkopp" <socketcan@hartkopp.net>,
	"Vincent Mailhol" <mailhol@kernel.org>,
	"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH v11 2/3] can: j1939: fix possibility of hard-lockup/deadlock in j1939_ecu_timer_cancel()
Date: Tue, 10 Nov 2026 16:39:00 +0000	[thread overview]
Message-ID: <sashiko-outbox-207397@kernel.org> (raw)
In-Reply-To: <f516220f-b922-4172-bf35-ce34d5f21b39@I-love.SAKURA.ne.jp>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] can: j1939: j1939_ac_process() drops address claim when timer
  handler is running
--

commit 80762ad6fa3d1299e982ed85f13042798ab71255
Author: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>

can: j1939: fix possibility of hard-lockup/deadlock in j1939_ecu_timer_cancel()

This commit replaces hrtimer_cancel() with hrtimer_try_to_cancel() in
j1939_ecu_timer_cancel() and drops incoming address claim frames in
j1939_ac_process() when the address claim timer is currently executing.

> diff --git a/net/can/j1939/address-claim.c b/net/can/j1939/address-claim.c
> index ca4ad6cdd5cbf..89ba8c6fbe74d 100644
> --- a/net/can/j1939/address-claim.c
> +++ b/net/can/j1939/address-claim.c
> @@ -212,7 +212,8 @@ static void j1939_ac_process(struct j1939_priv *priv, struct sk_buff *skb)
>  		goto out_unlock_bh;
>  
>  	/* cancel pending (previous) address claim */
> -	j1939_ecu_timer_cancel(ecu);
> +	if (!j1939_ecu_timer_cancel(ecu))
> +		goto out_ecu_put;
>  
>  	if (j1939_address_is_idle(skcb->addr.sa)) {
>  		j1939_ecu_unmap_locked(ecu);

[Severity: Medium]
Can jumping to out_ecu_put when j1939_ecu_timer_cancel() returns false
leave ecu->addr and priv->ents[] out of sync with the address claim
frame?

If a new address claim or J1939_IDLE_ADDR frame arrives for the same ECU
while j1939_ecu_timer_handler() is running on another CPU, the handler
can be spinning on write_lock_bh(&priv->lock):

CPU0                              CPU1
j1939_ac_process()
  write_lock_bh(&priv->lock)
                                  j1939_ecu_timer_handler()
                                    write_lock_bh(&priv->lock)
  j1939_ecu_timer_cancel(ecu)
    hrtimer_try_to_cancel() -> -1
  goto out_ecu_put;
  write_unlock_bh(&priv->lock)
                                    j1939_ecu_map_locked(ecu)
                                      <-- maps stale ecu->addr

Even if j1939_ecu_timer_handler() has already dropped priv->lock and is
returning, bailing out skips unmapping the old address, updating
ecu->addr, and starting the 250 ms timer for the new address.  For a
local ECU claiming a new address, j1939_ac_fixup() has already unmapped
the old address on TX, so dropping the echoed RX frame leaves the ECU
permanently unmapped and causes subsequent sendmsg() calls to fail with
-EADDRNOTAVAIL.

Since both j1939_ac_process() and j1939_ecu_timer_handler() serialize on
priv->lock, could timer cancellation be tracked under priv->lock so the
handler skips j1939_ecu_map_locked() when superseded instead of dropping
the frame?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/a1dd9760-7815-400a-a39c-a1a03cf8262e@I-love.SAKURA.ne.jp?part=2

  parent reply	other threads:[~2026-11-10 16:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 16:04 [PATCH v11 1/3] can: j1939: fix possibility of UAF in __j1939_ecu_release() Tetsuo Handa
2026-11-10 16:04 ` [PATCH v11 2/3] can: j1939: fix possibility of hard-lockup/deadlock in j1939_ecu_timer_cancel() Tetsuo Handa
2026-11-10 16:05   ` [PATCH v11 3/3] can: j1939: fix "struct j1939_ecu" refcount leak Tetsuo Handa
2026-11-12  8:50     ` netdev-bot+sashiko
2026-11-10 16:39   ` sashiko-bot [this message]
2026-11-12  8:50   ` [PATCH v11 2/3] can: j1939: fix possibility of hard-lockup/deadlock in j1939_ecu_timer_cancel() 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=sashiko-outbox-207397@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=penguin-kernel@I-love.SAKURA.ne.jp \
    --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