From: Oleksij Rempel <o.rempel@pengutronix.de>
To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: linux-can@vger.kernel.org, Marc Kleine-Budde <mkl@pengutronix.de>,
Robin van der Gracht <robin@protonic.nl>,
kernel@pengutronix.de, Oliver Hartkopp <socketcan@hartkopp.net>
Subject: Re: [PATCH v15 2/3] can: j1939: fix "struct j1939_ecu" refcount leak
Date: Sun, 29 Nov 2026 11:34:30 +0100 [thread overview]
Message-ID: <awv_tkJZbviq3RBT@pengutronix.de> (raw)
In-Reply-To: <f778db47-a217-448e-9dbd-f1860afab00b@I-love.SAKURA.ne.jp>
Hi Tetsuo,
On Wed, Nov 18, 2026 at 12:57:19AM +0900, Tetsuo Handa wrote:
> +static bool __must_check j1939_ecu_verify_get(struct j1939_ecu *ecu)
> +{
> + struct j1939_priv *priv = ecu->priv;
> +
> + /* Don't get an ECU ref if netdev is no longer registered or
> + * __j1939_rx_release() was called or __j1939_ecu_release() was
> called.
> + */
> + return READ_ONCE(priv->ndev->reg_state) == NETREG_REGISTERED &&
> + kref_read(&priv->rx_kref) && j1939_ecu_get(ecu);
> +}
Let's take the patches incrementally. I will take a deeper look at 1/3
later. Could you send 2/3 and 3/3 first, as a new small series? For
that, this patch needs some rework, because it relies on 1/3.
I guess a small priv->stopping flag would fit better than the reg_state
and rx_kref checks. It can be set under priv->lock in
__j1939_rx_release() before the ECUs are unmapped, and checked where
the ECU gets mapped. Then this patch does not need the bool
j1939_ecu_get() from 1/3, and a similar flag may help in other places
later.
One more problem without 1/3: once the map is skipped, the
j1939_ecu_put() in the timer handler can free priv while priv->lock is
still held, as far as I can see. I guess kfree_rcu() for priv is the
natural fix here. The timer handler runs in softirq context, which is an
RCU read-side section, so priv would stay valid until the handler
returns.
If kfree_rcu() works here, could you send it as a separate patch in
the same series, before this one, also with Cc: stable? Then each step
stays safe for bisecting, and stable does not pick up this patch
without it.
Please also say in the commit message how you tested the fix.
maintainer-netdev.rst asks for this in every fix.
If you have a reproducer, could you send it separately? It would help
me to write a selftest for it.
Regards,
Oleksij
next prev parent reply other threads:[~2026-11-29 10:34 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 15:56 [PATCH v15 0/3] can: j1939: make module more robust Tetsuo Handa
2026-11-17 15:56 ` [PATCH v15 1/3] can: j1939: fix possibility of UAF Tetsuo Handa
2026-11-17 15:57 ` [PATCH v15 2/3] can: j1939: fix "struct j1939_ecu" refcount leak Tetsuo Handa
2026-11-27 11:12 ` Dmitry Antipov
2026-11-29 10:34 ` Oleksij Rempel [this message]
2026-11-29 10:49 ` Tetsuo Handa
2026-11-29 15:28 ` Tetsuo Handa
2026-11-17 15:57 ` [PATCH v15 3/3] can: j1939: fix possibility of hard-lockup/deadlock in j1939_ecu_timer_cancel() Tetsuo Handa
2026-11-29 11:29 ` Oleksij Rempel
2026-11-20 11:35 ` [PATCH v15 0/3] can: j1939: make module more robust Tetsuo Handa
2026-11-27 8:32 ` Oleksij Rempel
2026-11-27 12:01 ` 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=awv_tkJZbviq3RBT@pengutronix.de \
--to=o.rempel@pengutronix.de \
--cc=kernel@pengutronix.de \
--cc=linux-can@vger.kernel.org \
--cc=mkl@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