Re: [PATCH] can: j1939: call j1939_priv_put() immediately when j1939_local_ecu_get() failed

From: Oleksij Rempel
Date: Mon Aug 25 2025 - 05:20:15 EST


Hi Tetsuo,

On Sun, Aug 24, 2025 at 07:30:09PM +0900, Tetsuo Handa wrote:
> Commit 25fe97cb7620 ("can: j1939: move j1939_priv_put() into sk_destruct
> callback") expects that a call to j1939_priv_put() can be unconditionally
> delayed until j1939_sk_sock_destruct() is called. But a refcount leak will
> happen when j1939_sk_bind() is called again after j1939_local_ecu_get()
> from previous j1939_sk_bind() call returned an error. We need to call
> j1939_priv_put() before j1939_sk_bind() returns an error.
>
> Fixes: 25fe97cb7620 ("can: j1939: move j1939_priv_put() into sk_destruct callback")
> Signed-off-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx>
> ---
> The change made by commit 25fe97cb7620 might be relevant to my result
>
> As far as I tested, the only way that can drop the refcount to 1 is to
> call j1939_sk_release() (which involves sock_put()) on all j1939 sockets
>
> in https://lkml.kernel.org/r/bb595640-0597-4d18-a9e1-f6eb8e6bb50e@xxxxxxxxxxxxxxxxxxx .

Thank you for your work!
Right now I'm on open source summit and can't quickly respond/test your
patches. I'll try to do my best ASAP next week.

Best Regards,
Oleksij
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |