From: sashiko-bot@kernel.org
To: "Tetsuo Handa" <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: "Marc Kleine-Budde" <mkl@pengutronix.de>,
"Vincent Mailhol" <mailhol@kernel.org>,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
linux-can@vger.kernel.org,
"Oliver Hartkopp" <socketcan@hartkopp.net>
Subject: Re: [PATCH v2 (repost)] can: j1939: j1939_sk_bind(): fix j1939_ecu leak when re-bind failed
Date: Sat, 05 Sep 2026 09:58:55 +0000 [thread overview]
Message-ID: <20260905095856.510841F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <deb3ac27-5eaf-406a-9bf4-733cc43ecaba@I-love.SAKURA.ne.jp>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Race condition between socket re-bind and netdevice unregister leads to a permanent netdevice refcount leak and indefinite hang.
--
commit b8691a5ee88f84f344aebc052218bc8abf2cba8a
Author: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
can: j1939: j1939_sk_bind(): fix j1939_ecu leak when re-bind failed
This commit defers the removal and release of the old ECU references during
a socket re-bind operation until after successfully acquiring new resources.
This resolves a netdevice refcount leak that occurred when
j1939_local_ecu_get() failed during the bind process.
> diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
> index 50a598ef5fd4a..24efb25c58c3f 100644
> --- a/net/can/j1939/socket.c
> +++ b/net/can/j1939/socket.c
[ ... ]
> @@ -519,22 +517,31 @@ static int j1939_sk_bind(struct socket *sock, struct sockaddr_unsized *uaddr, in
[ ... ]
> + /* drop old references after re-bind() succeeded */
> + if (was_bound) {
> + j1939_jsk_del(priv, jsk);
> + j1939_local_ecu_put(priv, jsk->addr.src_name, jsk->addr.sa);
> + }
> +
> /* set default transmit pgn */
> if (j1939_pgn_is_valid(addr->can_addr.j1939.pgn))
> jsk->pgn_rx_filter = addr->can_addr.j1939.pgn;
> jsk->addr.src_name = addr->can_addr.j1939.name;
> jsk->addr.sa = addr->can_addr.j1939.addr;
>
> - /* get new references */
> - ret = j1939_local_ecu_get(priv, jsk->addr.src_name, jsk->addr.sa);
> - if (ret) {
> - j1939_netdev_stop(priv);
> - jsk->priv = NULL;
> - synchronize_rcu();
> - j1939_priv_put(priv);
> - goto out_release_sock;
> - }
> -
> j1939_jsk_add(priv, jsk);
[Severity: High]
This isn't a bug introduced by this patch, but does this sequence leave a race
window between socket re-bind and netdevice unregister?
When the socket is temporarily unlinked via j1939_jsk_del() and then added
back via j1939_jsk_add() in j1939_sk_bind(), can a concurrent netdevice
unregister operation completely miss the socket?
If an interface is being unregistered (e.g. via ip link del) while a socket
is re-binding to the same interface, j1939_sk_netdev_event_unregister()
could scan the priv->j1939_socks list during this gap:
net/can/j1939/socket.c:j1939_sk_netdev_event_unregister() {
...
read_lock_bh(&priv->j1939_socks_lock);
list_for_each_entry(jsk, &priv->j1939_socks, list) {
...
}
If the unregister notifier iterates the list while the socket is removed,
doesn't the unregister process bypass cleaning up this socket?
Could this result in the socket permanently holding a reference to the
net_device via j1939_priv, causing an indefinite hang in
netdev_wait_allrefs()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/deb3ac27-5eaf-406a-9bf4-733cc43ecaba@I-love.SAKURA.ne.jp?part=1
prev parent reply other threads:[~2026-09-05 9:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-05 9:44 [PATCH v2 (repost)] can: j1939: j1939_sk_bind(): fix j1939_ecu leak when re-bind failed Tetsuo Handa
2026-09-05 9:58 ` 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=20260905095856.510841F00A3D@smtp.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