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 v16 4/5] can: j1939: fix "struct j1939_ecu" refcount leak
Date: Fri, 04 Dec 2026 16:23:22 +0000	[thread overview]
Message-ID: <sashiko-outbox-250178@kernel.org> (raw)
In-Reply-To: <29d5b6ac-93c1-4925-97ec-f94047d26a14@I-love.SAKURA.ne.jp>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] can: j1939: undocumented stable dependency in
  j1939_ecu_map_locked() fix
- [Low] can: j1939: commit message omits testing description required by
  netdev policy
--

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

> can: j1939: fix "struct j1939_ecu" refcount leak
>
> syzbot is reporting "struct j1939_ecu" refcount leak, for
>
>   j1939_ecu_get(ecu);
>   priv->ents[ecu->addr] = ecu;
>
> in j1939_ecu_map_locked() from j1939_ecu_timer_handler() can succeed
> even after
>
>   priv->ents[ecu->addr] = NULL;
>   j1939_ecu_put(ecu);
>
> in j1939_ecu_unmap_locked() from j1939_ecu_unmap_all() from
> __j1939_rx_release() from j1939_netdev_stop() has completed.
>
> Fix this problem by making j1939_ecu_map_locked() no-op
> when __j1939_rx_release() was already called (indicated by
> ecu->priv->rx_kref == 0).
>
> Reported-by: syzbot+e2af46126e0644cbebdd@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=e2af46126e0644cbebdd
> Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
> Cc: stable@vger.kernel.org
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>

[Severity: Low]
As reported by Oleksij Rempel on v15 [1], the commit message still omits how
the fix was tested.  Documentation/process/maintainer-netdev.rst requires
every bug fix to state how it was tested.

> diff --git a/net/can/j1939/bus.c b/net/can/j1939/bus.c
> index 7e22a7f7ecad5..b8e517c6ad1ce 100644
> --- a/net/can/j1939/bus.c
> +++ b/net/can/j1939/bus.c
> @@ -74,6 +74,8 @@ static void j1939_ecu_map_locked(struct j1939_ecu *ecu)
>  	struct j1939_addr_ent *ent;
>  
>  	lockdep_assert_held(&priv->lock);
> +	if (!kref_read(&priv->rx_kref))
> +		return;
>  
>  	if (!j1939_address_is_unicast(ecu->addr))
>  		return;

[Severity: Medium]
As reported by Oleksij Rempel on v15 [1], can this patch cause a
use-after-free in j1939_ecu_timer_handler() if backported to stable without
earlier commits from this series?

This two-line diff carries Cc: stable@vger.kernel.org and applies cleanly on
older trees.  Without commit "can: j1939: fix possibility of UAF on
j1939_ecu upon module unload", skipping the map lets j1939_ecu_put(ecu) call
kfree(priv) before write_unlock(&priv->lock), causing a use-after-free.

Preceding this fix with kfree_rcu() for j1939_priv (as suggested on v15)
would keep it safe for standalone backporting; otherwise the commit message
should note the dependency on the earlier workqueue release commits.

[1] https://lore.kernel.org/r/awv_tkJZbviq3RBT@pengutronix.de

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/02d9f333-d774-4cec-9d12-cb181395fd8a@I-love.SAKURA.ne.jp?part=4

  reply	other threads:[~2026-12-04 16:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 16:03 [PATCH v16 0/5] can: j1939: make module more robust Tetsuo Handa
2026-12-04 16:03 ` [PATCH v16 1/5] can: j1939: fix possibility of UAF on j1939_priv upon module unload Tetsuo Handa
2026-12-04 16:34   ` sashiko-bot
2026-12-04 16:04 ` [PATCH v16 2/5] can: j1939: fix possibility of UAF on j1939_session " Tetsuo Handa
2026-12-04 16:29   ` sashiko-bot
2026-12-04 16:04 ` [PATCH v16 3/5] can: j1939: fix possibility of UAF on j1939_ecu " Tetsuo Handa
2026-12-04 16:04 ` [PATCH v16 4/5] can: j1939: fix "struct j1939_ecu" refcount leak Tetsuo Handa
2026-12-04 16:23   ` sashiko-bot [this message]
2026-12-04 16:05 ` [PATCH v16 5/5] can: j1939: fix possibility of list corruption in __j1939_ecu_release() Tetsuo Handa
2026-12-04 16:23   ` sashiko-bot

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-250178@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