All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND v4] can: j1939: cancel all pending ECUs on device stop
@ 2026-11-26  8:22 Dmitry Antipov
  2026-11-26  8:35 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Dmitry Antipov @ 2026-11-26  8:22 UTC (permalink / raw)
  To: Robin van der Gracht, Oleksij Rempel, Oliver Hartkopp,
	Marc Kleine-Budde
  Cc: linux-can, lvc-project, Dmitry Antipov,
	syzbot+489e907b2a026a6f5fa0

Cancel all pending ECUs in j1939_netdev_stop(). This is needed
to prevent the case when stopped device no longer processes ECUs
and, since ECU holds the reference to 'struct j1939_priv', the
latter (and ECU itself) is never freed. Since hrtimer_cancel()
waits for timer callback, use hrtimer_try_to_cancel() to avoid
deadlock on 'priv->lock' between j1939_ecu_timer_handler() and
j1939_ecu_cancel_all().

Reported-by: syzbot+489e907b2a026a6f5fa0@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=489e907b2a026a6f5fa0
Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
v4: go back to simpler approach with hrtimer_try_to_cancel()
v3: rebase on top of experimental lockless hrtimer handler
    and asynchronous ECU freeing
v2: add extra precaution to avoid ABBA deadlock between
    j1939_ecu_cancel_all() and timer callbacks (Sashiko)
---
 net/can/j1939/bus.c        | 11 +++++++++++
 net/can/j1939/j1939-priv.h |  1 +
 net/can/j1939/main.c       |  1 +
 3 files changed, 13 insertions(+)

diff --git a/net/can/j1939/bus.c b/net/can/j1939/bus.c
index cdc3c0a71937..0b5232b53605 100644
--- a/net/can/j1939/bus.c
+++ b/net/can/j1939/bus.c
@@ -96,6 +96,17 @@ void j1939_ecu_unmap(struct j1939_ecu *ecu)
 	write_unlock_bh(&ecu->priv->lock);
 }
 
+void j1939_ecu_cancel_all(struct j1939_priv *priv)
+{
+	struct j1939_ecu *ecu, *tmp;
+
+	write_lock_bh(&priv->lock);
+	list_for_each_entry_safe(ecu, tmp, &priv->ecus, list)
+		if (hrtimer_try_to_cancel(&ecu->ac_timer) != -1)
+			j1939_ecu_put(ecu);
+	write_unlock_bh(&priv->lock);
+}
+
 void j1939_ecu_unmap_all(struct j1939_priv *priv)
 {
 	int i;
diff --git a/net/can/j1939/j1939-priv.h b/net/can/j1939/j1939-priv.h
index cf26352d1d8c..37a245ef9b73 100644
--- a/net/can/j1939/j1939-priv.h
+++ b/net/can/j1939/j1939-priv.h
@@ -204,6 +204,7 @@ struct j1939_ecu *j1939_ecu_create_locked(struct j1939_priv *priv, name_t name);
 
 void j1939_ecu_timer_start(struct j1939_ecu *ecu);
 void j1939_ecu_timer_cancel(struct j1939_ecu *ecu);
+void j1939_ecu_cancel_all(struct j1939_priv *priv);
 void j1939_ecu_unmap_all(struct j1939_priv *priv);
 
 struct j1939_priv *j1939_netdev_start(struct net_device *ndev);
diff --git a/net/can/j1939/main.c b/net/can/j1939/main.c
index 5e5e6c228f22..1f68ba803700 100644
--- a/net/can/j1939/main.c
+++ b/net/can/j1939/main.c
@@ -306,6 +306,7 @@ struct j1939_priv *j1939_netdev_start(struct net_device *ndev)
 
 void j1939_netdev_stop(struct j1939_priv *priv)
 {
+	j1939_ecu_cancel_all(priv);
 	kref_put_mutex(&priv->rx_kref, __j1939_rx_release, &j1939_netdev_lock);
 	j1939_priv_put(priv);
 }
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH RESEND v4] can: j1939: cancel all pending ECUs on device stop
  2026-11-26  8:22 [PATCH RESEND v4] can: j1939: cancel all pending ECUs on device stop Dmitry Antipov
@ 2026-11-26  8:35 ` sashiko-bot
  2026-11-27  9:40 ` Oleksij Rempel
  2026-11-27 21:20 ` netdev-bot+sashiko
  2 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-26  8:35 UTC (permalink / raw)
  To: Dmitry Antipov
  Cc: linux-can, Marc Kleine-Budde, Oliver Hartkopp, Vincent Mailhol,
	Oleksij Rempel

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Critical] can: j1939: refcount underflow and UAF in
  j1939_ecu_cancel_all()
- [High] can: j1939: premature j1939_ecu_cancel_all() in
  j1939_netdev_stop()
- [Medium] can: j1939: ECU leak in j1939_ecu_cancel_all() on in-flight
  ac_timer
--

commit 93803049529a18174c52d42d8612110310952b12
Author: Dmitry Antipov <dmantipov@yandex.ru>

can: j1939: cancel all pending ECUs on device stop

This commit adds j1939_ecu_cancel_all() and calls it from
j1939_netdev_stop() to cancel pending ECU address-claim timers and drop
their ECU references.

> diff --git a/net/can/j1939/bus.c b/net/can/j1939/bus.c
> index cdc3c0a719379..0b5232b536051 100644
> --- a/net/can/j1939/bus.c
> +++ b/net/can/j1939/bus.c
> @@ -96,6 +96,17 @@ void j1939_ecu_unmap(struct j1939_ecu *ecu)
>  	write_unlock_bh(&ecu->priv->lock);
>  }
>  
> +void j1939_ecu_cancel_all(struct j1939_priv *priv)
> +{
> +	struct j1939_ecu *ecu, *tmp;
> +
> +	write_lock_bh(&priv->lock);
> +	list_for_each_entry_safe(ecu, tmp, &priv->ecus, list)
> +		if (hrtimer_try_to_cancel(&ecu->ac_timer) != -1)
> +			j1939_ecu_put(ecu);
> +	write_unlock_bh(&priv->lock);
> +}
> +

[Severity: Critical]
Does checking hrtimer_try_to_cancel(&ecu->ac_timer) != -1 drop an unowned
reference on ecu when ac_timer is inactive?

hrtimer_try_to_cancel() returns 1 when an active timer is cancelled, 0
when the timer is not active, and -1 when the callback is running.  For
an ECU whose ac_timer is not active (for example, an ECU that has already
completed address claiming and is mapped in priv->ents[ecu->addr].ecu, or
a local ECU whose timer was never started), hrtimer_try_to_cancel()
returns 0 and j1939_ecu_cancel_all() drops a reference that ac_timer does
not hold.  When the mapped reference in priv->ents[] was the only
remaining reference, this frees ecu before __j1939_rx_release() ->
j1939_ecu_unmap_all() dereferences priv->ents[i].ecu, causing a
use-after-free and refcount underflow.

Should this check hrtimer_try_to_cancel(&ecu->ac_timer) == 1 instead?

[Severity: Medium]
Can an in-flight j1939_ecu_timer_handler() still map and leak ecu when
hrtimer_try_to_cancel() returns -1?

CPU0                                  CPU1
j1939_netdev_stop()
  j1939_ecu_cancel_all()
    write_lock_bh(&priv->lock)
                                      j1939_ecu_timer_handler()
                                        write_lock_bh(&priv->lock)
    hrtimer_try_to_cancel() -> -1
    write_unlock_bh(&priv->lock)
  __j1939_rx_release()
    j1939_ecu_unmap_all()
                                        j1939_ecu_map_locked(ecu)
                                          j1939_ecu_get(ecu)  <-- leaked
                                        j1939_ecu_put(ecu)

When ac_timer expires on CPU1 while CPU0 holds priv->lock,
hrtimer_try_to_cancel() returns -1 and j1939_ecu_timer_handler() waits on
priv->lock.  If j1939_ecu_unmap_all() runs before CPU1 acquires
priv->lock, j1939_ecu_timer_handler() subsequently maps ecu into
priv->ents[ecu->addr].ecu and takes a new reference that is never
unmapped, leaking ecu, priv, and their net_device references.

[ ... ]

> diff --git a/net/can/j1939/main.c b/net/can/j1939/main.c
> index d9384cf0e356f..4b62da9fd96dc 100644
> --- a/net/can/j1939/main.c
> +++ b/net/can/j1939/main.c
> @@ -306,6 +306,7 @@ struct j1939_priv *j1939_netdev_start(struct net_device *ndev)
>  
>  void j1939_netdev_stop(struct j1939_priv *priv)
>  {
> +	j1939_ecu_cancel_all(priv);
>  	kref_put_mutex(&priv->rx_kref, __j1939_rx_release, &j1939_netdev_lock);
>  	j1939_priv_put(priv);
>  }

[Severity: High]
Should j1939_ecu_cancel_all() be called inside __j1939_rx_release() after
j1939_can_rx_unregister() rather than unconditionally in
j1939_netdev_stop()?

All J1939 sockets bound to the same net_device share a single struct
j1939_priv, and each socket release calls j1939_netdev_stop().  Running
j1939_ecu_cancel_all() when priv->rx_kref > 1 cancels pending
address-claim timers for other active sockets on the same interface,
leaving their ECUs unmapped so later NAME-based sends fail with
-EADDRNOTAVAIL.

Even when the last socket closes, calling j1939_ecu_cancel_all() before
__j1939_rx_release() calls j1939_can_rx_unregister() leaves a window where
incoming Address Claim frames in j1939_can_recv() can start a new
ac_timer after j1939_ecu_cancel_all() has already returned.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126082257.491041-1-dmantipov@yandex.ru?part=1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH RESEND v4] can: j1939: cancel all pending ECUs on device stop
  2026-11-26  8:22 [PATCH RESEND v4] can: j1939: cancel all pending ECUs on device stop Dmitry Antipov
  2026-11-26  8:35 ` sashiko-bot
@ 2026-11-27  9:40 ` Oleksij Rempel
  2026-11-27 11:01   ` Dmitry Antipov
  2026-11-27 21:20 ` netdev-bot+sashiko
  2 siblings, 1 reply; 6+ messages in thread
From: Oleksij Rempel @ 2026-11-27  9:40 UTC (permalink / raw)
  To: Dmitry Antipov
  Cc: Robin van der Gracht, Oliver Hartkopp, Marc Kleine-Budde,
	linux-can, lvc-project, syzbot+489e907b2a026a6f5fa0, Tetsuo Handa

Hi Dmitry,

thank you, and sorry for the long silence.

On Thu, Nov 26, 2026 at 11:22:57AM +0300, Dmitry Antipov wrote:
> +             if (hrtimer_try_to_cancel(&ecu->ac_timer) != -1)
> +                     j1939_ecu_put(ecu);

Unless I am missing something, hrtimer_try_to_cancel() returns 0 for an
inactive timer, so this drops a reference the timer does not hold.

> +     j1939_ecu_cancel_all(priv);
>       kref_put_mutex(&priv->rx_kref, __j1939_rx_release,
>       &j1939_netdev_lock);

As far as I can see, j1939_netdev_stop() runs for every closed bound
socket, not only the last one. So this would also cancel address claims
of other sockets and remote ECUs. And an address claim received after
the cancel can still arm a new timer.

If I read the code right, the leak is the reference that
j1939_ecu_map_locked() takes when the timer fires after
j1939_ecu_unmap_all(). Tetsuo's v15 2/3 stops exactly this, without
cancelling anything:

https://lore.kernel.org/all/f778db47-a217-448e-9dbd-f1860afab00b@I-love.SAKURA.ne.jp/

So I would not take this patch. Could you please test the whole v15
series with your syzbot reproducer and reply there, ideally with a
Tested-by? If v15 does not fix your leak, or I overlooked something,
please let me know.

Regards,
Oleksij

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH RESEND v4] can: j1939: cancel all pending ECUs on device stop
  2026-11-27  9:40 ` Oleksij Rempel
@ 2026-11-27 11:01   ` Dmitry Antipov
  2026-11-27 11:04     ` Marc Kleine-Budde
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Antipov @ 2026-11-27 11:01 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Robin van der Gracht, Oliver Hartkopp, Marc Kleine-Budde,
	linux-can, lvc-project, syzbot+489e907b2a026a6f5fa0, Tetsuo Handa

On 11/27/26 12:40 PM, Oleksij Rempel wrote:

> So I would not take this patch. Could you please test the whole v15
> series with your syzbot reproducer and reply there, ideally with a
> Tested-by? If v15 does not fix your leak, or I overlooked something,
> please let me know.

Yes, v15 fixes the leak reported at https://syzkaller.appspot.com/bug?extid=489e907b2a026a6f5fa0.
So feel free to add:

Tested-by: Dmitry Antipov <dmantipov@yandex.ru>

to patch 1 of v15. Most likely

Closes: https://syzkaller.appspot.com/bug?extid=489e907b2a026a6f5fa0

should be added as well.

Dmitry

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH RESEND v4] can: j1939: cancel all pending ECUs on device stop
  2026-11-27 11:01   ` Dmitry Antipov
@ 2026-11-27 11:04     ` Marc Kleine-Budde
  0 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2026-11-27 11:04 UTC (permalink / raw)
  To: Dmitry Antipov
  Cc: Oleksij Rempel, Robin van der Gracht, Oliver Hartkopp, linux-can,
	lvc-project, syzbot+489e907b2a026a6f5fa0, Tetsuo Handa

[-- Attachment #1: Type: text/plain, Size: 1010 bytes --]

On 27.11.2026 14:01:14, Dmitry Antipov wrote:
> On 11/27/26 12:40 PM, Oleksij Rempel wrote:
>
> > So I would not take this patch. Could you please test the whole v15
> > series with your syzbot reproducer and reply there, ideally with a
> > Tested-by? If v15 does not fix your leak, or I overlooked something,
> > please let me know.
>
> Yes, v15 fixes the leak reported at https://syzkaller.appspot.com/bug?extid=489e907b2a026a6f5fa0.
> So feel free to add:
>
> Tested-by: Dmitry Antipov <dmantipov@yandex.ru>
>
> to patch 1 of v15. Most likely
>
> Closes: https://syzkaller.appspot.com/bug?extid=489e907b2a026a6f5fa0
>
> should be added as well.

Please reply to the patch you want to add your tag to.

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH RESEND v4] can: j1939: cancel all pending ECUs on device stop
  2026-11-26  8:22 [PATCH RESEND v4] can: j1939: cancel all pending ECUs on device stop Dmitry Antipov
  2026-11-26  8:35 ` sashiko-bot
  2026-11-27  9:40 ` Oleksij Rempel
@ 2026-11-27 21:20 ` netdev-bot+sashiko
  2 siblings, 0 replies; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-11-27 21:20 UTC (permalink / raw)
  To: dmantipov
  Cc: robin, o.rempel, socketcan, mkl, linux-can, lvc-project,
	syzbot+489e907b2a026a6f5fa0, kuba

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

Critical: 1 · High: 2 (1) · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Critical] j1939_ecu_cancel_all() (net/can/j1939/bus.c:99-108) calls
  j1939_ecu_put() whenever `hrtimer_try_to_cancel(&ecu->ac_timer) != -1`.
- [High] The fix is incomplete: the claim timer can still map an ECU
  after j1939_ecu_unmap_all(), so the ECU/priv/netdev leak the patch…
- [High] The commit message says pending ECUs are cancelled "on device
  stop", but j1939_ecu_cancel_all() runs unconditionally at the top of…
- [Low] The ownership comment in j1939_ecu_timer_start() (bus.c:123-125)
  says the timer's ECU reference "is held here and released in the…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is the same
  lock/timer inversion the patch says it avoids.

--

can: j1939: cancel all pending ECUs on device stop

This patch adds j1939_ecu_cancel_all(). It walks priv->ecus under
priv->lock, cancels each ECU's address-claim timer with
hrtimer_try_to_cancel() and drops the ECU reference. It is called from
j1939_netdev_stop() so that ECUs, and the j1939_priv they reference, are
not left unfreed after the device is stopped.

Closes: https://syzkaller.appspot.com/bug?extid=489e907b2a026a6f5fa0

> diff --git a/net/can/j1939/bus.c b/net/can/j1939/bus.c
> index cdc3c0a719379..0b5232b536051 100644
> --- a/net/can/j1939/bus.c
> +++ b/net/can/j1939/bus.c
> @@ -96,6 +96,17 @@ void j1939_ecu_unmap(struct j1939_ecu *ecu)
>  	write_unlock_bh(&ecu->priv->lock);
>  }
>  
> +void j1939_ecu_cancel_all(struct j1939_priv *priv)
> +{
> +	struct j1939_ecu *ecu, *tmp;
> +
> +	write_lock_bh(&priv->lock);
> +	list_for_each_entry_safe(ecu, tmp, &priv->ecus, list)
> +		if (hrtimer_try_to_cancel(&ecu->ac_timer) != -1)
> +			j1939_ecu_put(ecu);

[Severity: Critical]
Can this drop a reference that the timer never held?

hrtimer_try_to_cancel() returns 0 when the timer is not active. That is
the case for an ECU whose claim timer was never armed or has already
fired. The != -1 test handles 0 the same way as a successful cancel (1),
so j1939_ecu_put() runs for every idle ECU on priv->ecus.

The timer reference is only taken in j1939_ecu_timer_start():

	j1939_ecu_get(ecu);

	/* Schedule timer in 250 msec to commit address change. */
	hrtimer_start(&ecu->ac_timer, ms_to_ktime(250),
		      HRTIMER_MODE_REL_SOFT);

The existing j1939_ecu_timer_cancel() only puts when an armed timer was
actually removed:

	if (hrtimer_cancel(&ecu->ac_timer))
		j1939_ecu_put(ecu);

For a remote ECU that has finished its address claim, the sequence is:

j1939_ac_process()
    j1939_ecu_create_locked()       kref = 1
    j1939_ecu_timer_start()         kref = 2
    out_ecu_put: j1939_ecu_put()    kref = 1

j1939_ecu_timer_handler()  (250 ms later)
    j1939_ecu_map_locked()          kref = 2, priv->ents[sa].ecu = ecu
    j1939_ecu_put()                 kref = 1

j1939_sk_release()  (any j1939 socket on that interface)
    j1939_netdev_stop()
        j1939_ecu_cancel_all()
            hrtimer_try_to_cancel() returns 0
            j1939_ecu_put()         kref = 0, kfree(ecu)

At this point priv->ents[sa].ecu still points at the freed ECU.

If that was the last socket, __j1939_rx_release()->j1939_ecu_unmap_all()
calls j1939_ecu_unmap_locked() on it. That reads ecu->priv and ecu->addr
from freed memory, puts the freed object a second time, and drops
priv->kref an extra time.

If other sockets keep the device alive, the next frame from that address
goes through j1939_ac_recv()->j1939_ecu_get_by_addr(). That calls
kref_get() on the freed ECU and then reads ecu->name.

Local ECUs are hit the same way. Closing an unrelated socket can drop a
reference owned by a bound socket's j1939_local_ecu_get() or by the ents[]
mapping. The owner then gets a use-after-free later, or hits the
WARN_ON_ONCE(!ecu) in j1939_local_ecu_put().

Should this check be == 1 instead, to match j1939_ecu_timer_cancel()?

> +	write_unlock_bh(&priv->lock);

[Severity: High]
Does this fully close the leak described in the commit message?

j1939_ecu_cancel_all() runs at the top of j1939_netdev_stop(), while
j1939_can_recv() is still registered. The RX handler is only unregistered
later, in __j1939_rx_release():

	j1939_can_rx_unregister(priv);
	j1939_ecu_unmap_all(priv);
	j1939_priv_set(priv->ndev, NULL);

Once priv->lock is dropped here, a PGN_ADDRESS_CLAIMED frame can still
reach j1939_ac_recv()->j1939_ac_process()->j1939_ecu_timer_start(). That
arms a new claim timer with a new ECU reference. can_rx_unregister() also
does not wait for receivers that are already running under RCU.

When hrtimer_try_to_cancel() returns -1, the callback is already running
and spinning on the priv->lock held here. In that case the ECU is skipped
and nothing waits for the callback to finish.

Either way, j1939_ecu_timer_handler() can run j1939_ecu_map_locked() after
j1939_ecu_unmap_all(). That sets priv->ents[addr].ecu and takes a
reference. Because priv has already been detached from the netdev, nothing
unmaps it again. The ECU, its j1939_priv reference and the netdev_hold() in
ecu->priv_dev_tracker are all leaked.

Would it be better to kill the timers synchronously in the last-reference
path, after the RX handler is unregistered and RCU readers have drained?

> +}

[Severity: High]
This isn't a bug introduced by this patch, but the commit message gives
the priv->lock vs. timer callback deadlock as the reason for using
hrtimer_try_to_cancel() here. The same pattern is still present in
j1939_ac_process(), which calls hrtimer_cancel() while holding priv->lock:

net/can/j1939/address-claim.c:j1939_ac_process() {
    ...
	write_lock_bh(&priv->lock);
    ...
	/* cancel pending (previous) address claim */
	j1939_ecu_timer_cancel(ecu);
    ...
}

j1939_ecu_timer_cancel() calls hrtimer_cancel(), which loops until the
callback has finished. j1939_ecu_timer_handler() starts with:

	write_lock_bh(&priv->lock);

CPU0 (NET_RX softirq)                 CPU1 (HRTIMER_SOFTIRQ)
                                      j1939_ecu_timer_handler()
j1939_ac_process()
    write_lock_bh(&priv->lock)
                                          write_lock_bh(&priv->lock)
                                          <spins>
    j1939_ecu_timer_cancel()
        hrtimer_cancel()
        <spins waiting for callback>

To trigger this, a remote node sends an AC frame for the same NAME with a
different address just as the previous 250 ms claim timer expires.

Can either CPU make progress in this case?

[Severity: Low]
This isn't a bug, but the ownership comment in j1939_ecu_timer_start()
still says:

	/* The ECU is held here and released in the
	 * j1939_ecu_timer_handler() or j1939_ecu_timer_cancel().
	 */

Should it also list j1939_ecu_cancel_all() as a release site?

[ ... ]

> diff --git a/net/can/j1939/main.c b/net/can/j1939/main.c
> index d9384cf0e356f..4b62da9fd96dc 100644
> --- a/net/can/j1939/main.c
> +++ b/net/can/j1939/main.c
> @@ -306,6 +306,7 @@ struct j1939_priv *j1939_netdev_start(struct net_device *ndev)
>  
>  void j1939_netdev_stop(struct j1939_priv *priv)
>  {
> +	j1939_ecu_cancel_all(priv);
>  	kref_put_mutex(&priv->rx_kref, __j1939_rx_release, &j1939_netdev_lock);

[Severity: High]
Is this the right place for the cancel?

j1939_netdev_stop() is called once per socket: from j1939_sk_bind() on
failure, from j1939_sk_release(), and from the netdev notifier. The real
device teardown only happens in __j1939_rx_release(), when the last
rx_kref is dropped.

As written, closing any single j1939 socket cancels every pending
address-claim timer on the interface. That includes claims owned by other
bound sockets and claims from remote ECUs seen on the bus.

j1939_ecu_map_locked() never runs for a cancelled claim, so the ECU keeps
ecu->addr but has no priv->ents[] entry. j1939_name_to_addr() then returns
J1939_IDLE_ADDR because j1939_ecu_is_mapped_locked() is false. Name-based
senders on the remaining sockets fail with EADDRNOTAVAIL.

This does not recover when the peer repeats its claim. j1939_ac_process()
skips re-arming the timer if the NAME and address match:

	if (ecu && ecu->addr == skcb->addr.sa) {
		...
		goto out_ecu_put;
	}

Should the cancellation move into __j1939_rx_release() instead?

The subject says "cancel all pending ECUs on device stop", but the code
runs the cancel on every socket stop, not only on device stop.

>  	j1939_priv_put(priv);
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126082257.491041-1-dmantipov%40yandex.ru

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-27 21:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  8:22 [PATCH RESEND v4] can: j1939: cancel all pending ECUs on device stop Dmitry Antipov
2026-11-26  8:35 ` sashiko-bot
2026-11-27  9:40 ` Oleksij Rempel
2026-11-27 11:01   ` Dmitry Antipov
2026-11-27 11:04     ` Marc Kleine-Budde
2026-11-27 21:20 ` netdev-bot+sashiko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.