From: Oleksij Rempel <o.rempel@pengutronix.de>
To: sashiko-reviews@lists.linux.dev, Patrick Dahlke <me@patrickdahlke.com>
Cc: linux-can@vger.kernel.org, Marc Kleine-Budde <mkl@pengutronix.de>,
Oliver Hartkopp <socketcan@hartkopp.net>,
Vincent Mailhol <mailhol@kernel.org>,
Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Subject: Re: [PATCH can] can: j1939: don't drop the last ECU reference without priv->lock
Date: Fri, 27 Nov 2026 11:55:56 +0100 [thread overview]
Message-ID: <awlhvDKawNFb96WV@pengutronix.de> (raw)
In-Reply-To: <sashiko-outbox-172364@kernel.org>
Hi Patrick,
thank you for the patch and the careful testing, and sorry for the
long silence.
On Thu, Oct 15, 2026 at 06:47:20AM +0000, sashiko-bot@kernel.org wrote:
> > diff --git a/net/can/j1939/bus.c b/net/can/j1939/bus.c
> > index cdc3c0a719379..ec8ee0f980fb4 100644
> > --- a/net/can/j1939/bus.c
> > +++ b/net/can/j1939/bus.c
> > @@ -19,6 +19,11 @@ static void __j1939_ecu_release(struct kref *kref)
> > struct j1939_ecu *ecu = container_of(kref, struct j1939_ecu, kref);
> > struct j1939_priv *priv = ecu->priv;
> >
> > + /* priv->ecus is protected by priv->lock, so the last reference
> > + * must only be dropped with priv->lock held for writing.
> > + */
> > + lockdep_assert_held_write(&priv->lock);
> > +
> > list_del(&ecu->list);
> > netdev_put(priv->ndev, &ecu->priv_dev_tracker);
> > kfree(ecu);
> > j1939_priv_put(priv);
> > }
>
> [Severity: High]
> Does enforcing this pattern cause a use-after-free of priv->lock?
>
> If j1939_priv_put() drops the last reference to priv, it will free
> priv while
> priv->lock is still held by the caller of j1939_ecu_put().
[...]
> Can this use-after-free be avoided by taking an explicit reference to
> priv
> before dropping the ECU, or deferring j1939_priv_put() outside the
> lock?
This looks valid to me. Tetsuo is already working on that part in his
series:
https://lore.kernel.org/all/98c16a74-5ea7-476e-ab36-c98fb77b6be4@I-love.SAKURA.ne.jp/
Tetsuo, for your information: if I read it right, this patch addresses
the same list corruption as "Problem 3" in your v15 1/3, in a different
way.
Regards,
Oleksij
next prev parent reply other threads:[~2026-11-27 10:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 6:26 [PATCH can] can: j1939: don't drop the last ECU reference without priv->lock Patrick Dahlke via B4 Relay
2026-10-15 6:47 ` sashiko-bot
2026-11-27 10:55 ` Oleksij Rempel [this message]
2026-11-27 11:34 ` Tetsuo Handa
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=awlhvDKawNFb96WV@pengutronix.de \
--to=o.rempel@pengutronix.de \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=me@patrickdahlke.com \
--cc=mkl@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