Skip to content

Commit f214744

Browse files
Tetsuo Handamarckleinebudde
authored andcommitted
can: j1939: j1939_sk_bind(): call j1939_priv_put() immediately when j1939_local_ecu_get() failed
Commit 25fe97c ("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: 25fe97c ("can: j1939: move j1939_priv_put() into sk_destruct callback") Signed-off-by: Tetsuo Handa <[email protected]> Tested-by: Oleksij Rempel <[email protected]> Acked-by: Oleksij Rempel <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 7fcbe5b commit f214744

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

net/can/j1939/socket.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,9 @@ static int j1939_sk_bind(struct socket *sock, struct sockaddr *uaddr, int len)
521521
ret = j1939_local_ecu_get(priv, jsk->addr.src_name, jsk->addr.sa);
522522
if (ret) {
523523
j1939_netdev_stop(priv);
524+
jsk->priv = NULL;
525+
synchronize_rcu();
526+
j1939_priv_put(priv);
524527
goto out_release_sock;
525528
}
526529

0 commit comments

Comments
 (0)