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 5/6] can: j1939: fix "struct j1939_ecu" refcount leak
Date: Mon, 16 Nov 2026 18:51:09 +0000	[thread overview]
Message-ID: <179485506949.3132.11506849570102968027@kernel.org> (raw)
In-Reply-To: <8b40dfe5-2b1c-4f42-998f-0d0e82ec2246@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 only describes the bus.c changes: (1)
  j1939_ecu_timer_start() no longer re-arms, and (2)…

--

can: j1939: fix "struct j1939_ecu" refcount leak

This patch fixes an ECU refcount leak reported by syzbot. The leak happens
when j1939_ecu_map_locked() runs from j1939_ecu_timer_handler() after
j1939_ecu_unmap_all() has already completed. A new helper,
j1939_ecu_verify_get(), refuses to take an ECU reference once the netdev is
no longer registered or rx_kref has dropped to zero. The helper is used in
both j1939_ecu_timer_start() and j1939_ecu_map_locked().

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

> diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
> index 50a598ef5fd4a..6e22ec5e88f5a 100644
> --- a/net/can/j1939/socket.c
> +++ b/net/can/j1939/socket.c
> @@ -484,7 +484,15 @@ static int j1939_sk_bind(struct socket *sock, struct sockaddr_unsized *uaddr, in
>  			goto out_release_sock;
>  		}
>
> -		if (ndev->reg_state != NETREG_REGISTERED) {
> +		/* Do nothing and fail early if netdev is no longer registered.
> +		 * This check is racy but we don't need to recheck after j1939_jsk_add()
> +		 * is called, for either j1939_sk_netdev_event_unregister() from
> +		 * j1939_netdev_notify(NETDEV_UNREGISTER) (which is retried by
> +		 * netdev_wait_allrefs_any() as long as priv->rx_kref held by
> +		 * j1939_netdev_start() is preventing j1939_priv_set(priv->ndev, NULL)
> +		 * from being called) or j1939_sk_release() will take care of this race.
> +		 */
> +		if (READ_ONCE(ndev->reg_state) != NETREG_REGISTERED) {

[Severity: Low]
This isn't a bug, but the commit message doesn't mention this
j1939_sk_bind() hunk. It only describes the bus.c changes:

  Fix this problem by

    (1) preventing ecu->ac_timer from re-arming in j1939_ecu_timer_start()
    (2) making j1939_ecu_map_locked() no-op

This hunk adds READ_ONCE() and a comment explaining why the bind-time
reg_state check doesn't need a recheck. As far as I can tell it doesn't
change behaviour, and it isn't part of the ECU refcount leak fix. Since the
patch is tagged for stable, could the commit message cover this change, or
could it go in a separate patch?

The READ_ONCE() annotation is also applied inconsistently. A similar
lockless read in j1939_session_activate() in net/can/j1939/transport.c is
left as is:

	} else if (priv->ndev->reg_state != NETREG_REGISTERED) {
		ret = -ENODEV;

>  			dev_put(ndev);
>  			ret = -ENODEV;
>  			goto out_release_sock;

-- 
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
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 [this message]
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=179485506949.3132.11506849570102968027@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