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] can: j1939: fix possibility of UAF on module unload
Date: Tue, 01 Dec 2026 15:44:36 +0000 [thread overview]
Message-ID: <sashiko-outbox-243609@kernel.org> (raw)
In-Reply-To: <aa93c245-399c-499b-a89e-dddefbf42fcb@I-love.SAKURA.ne.jp>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] can: j1939: uninterruptible hang in j1939_module_exit() on ECU
timer leak
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] can: j1939: resource leak via uncancelled ac_timer in
j1939_netdev_notify() [1]
--
commit 1a795dad5311bf5450a9def8e0e2df926f4b99f7
Author: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
can: j1939: fix possibility of UAF on module unload
This commit defers struct j1939_priv release to a module-local workqueue
and waits in j1939_module_exit() for all struct j1939_priv instances and
pending release work to finish before unloading the module.
> diff --git a/net/can/j1939/main.c b/net/can/j1939/main.c
> index d9384cf0e356f..858f9fa1a02ff 100644
> --- a/net/can/j1939/main.c
> +++ b/net/can/j1939/main.c
[ ... ]
> @@ -416,14 +441,28 @@ static __init int j1939_module_init(void)
> fail_sk:
> unregister_netdevice_notifier(&j1939_netdev_notifier);
> fail_notifier:
> + destroy_workqueue(j1939_wq);
> + fail_wq:
> return ret;
> }
>
> static __exit void j1939_module_exit(void)
> {
> +#if defined(MODULE) && defined(CONFIG_MODULE_UNLOAD)
> + /* Wait until all "struct j1939_priv", "struct j1939_ecu" and
> + * "struct j1939_session" are released.
> + */
> + wait_event(j1939_unload_wait, !atomic_read(&j1939_unload_blocker_count));
> +#endif
[Severity: High]
Can this wait_event() hang forever if a J1939 socket is closed while an
ECU address-claim timer (ecu->ac_timer) is pending?
When an address-claim frame starts ecu->ac_timer and the last socket closes
before the 250ms timer expires, j1939_sk_release() -> j1939_netdev_stop()
-> __j1939_rx_release() calls j1939_ecu_unmap_all(priv) and detaches priv
from the net_device, without canceling timers on ECUs in priv->ecus that
are not yet mapped in priv->ents[]. When ecu->ac_timer fires later,
j1939_ecu_timer_handler() -> j1939_ecu_map_locked() calls
j1939_ecu_get(ecu) and maps ecu into priv->ents[ecu->addr]. Nothing will
ever unmap that ECU again, leaking its reference on struct j1939_priv so
j1939_unload_blocker_count never reaches 0 and delete_module() blocks
uninterruptibly with module_mutex held.
[Severity: High]
This problem wasn't introduced by this patch, but the same uncancelled
ecu->ac_timer in j1939_netdev_notify() on NETDEV_DOWN [1] also leaks
struct j1939_priv and its netdev_hold() reference, hanging both
unregister_netdevice() and this wait_event() on module unload:
net/can/j1939/main.c:j1939_netdev_notify() {
...
case NETDEV_DOWN:
j1939_cancel_active_session(priv, NULL);
j1939_sk_netdev_event_netdown(priv);
j1939_ecu_unmap_all(priv);
break;
...
}
If the interface goes down within 250ms of receiving an address claim,
j1939_ecu_unmap_all(priv) leaves the pending ecu->ac_timer running, and
j1939_ecu_timer_handler() later maps the ECU back into priv->ents[] after
teardown has already finished.
[1] https://sashiko.dev/#/bug/linux-22e9fd14-7c3e-4d83-9e1d-af25b216d399
--
Sashiko AI review · https://sashiko.dev/#/patchset/aa93c245-399c-499b-a89e-dddefbf42fcb@I-love.SAKURA.ne.jp?part=1
prev parent reply other threads:[~2026-12-01 15:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 15:26 [PATCH] can: j1939: fix possibility of UAF on module unload Tetsuo Handa
2026-12-01 15:44 ` sashiko-bot [this message]
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-243609@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