mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-10 07:00:48 +00:00
can: j1939: j1939_sk_init(): set SOCK_RCU_FREE to call sk_destruct() after RCU is done
Set SOCK_RCU_FREE to let RCU to call sk_destruct() on completion. Without this patch, we will run in to j1939_can_recv() after priv was freed by j1939_sk_release()->j1939_sk_sock_destruct() Fixes: 25fe97cb7620 ("can: j1939: move j1939_priv_put() into sk_destruct callback") Link: https://lore.kernel.org/r/20210617130623.12705-1-o.rempel@pengutronix.de Cc: linux-stable <stable@vger.kernel.org> Reported-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com> Reported-by: syzbot+bdf710cfc41c186fdff3@syzkaller.appspotmail.com Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
This commit is contained in:
parent
14a4696bc3
commit
22c696fed2
@ -193,6 +193,10 @@ static void j1939_can_rx_unregister(struct j1939_priv *priv)
|
||||
can_rx_unregister(dev_net(ndev), ndev, J1939_CAN_ID, J1939_CAN_MASK,
|
||||
j1939_can_recv, priv);
|
||||
|
||||
/* The last reference of priv is dropped by the RCU deferred
|
||||
* j1939_sk_sock_destruct() of the last socket, so we can
|
||||
* safely drop this reference here.
|
||||
*/
|
||||
j1939_priv_put(priv);
|
||||
}
|
||||
|
||||
|
@ -398,6 +398,9 @@ static int j1939_sk_init(struct sock *sk)
|
||||
atomic_set(&jsk->skb_pending, 0);
|
||||
spin_lock_init(&jsk->sk_session_queue_lock);
|
||||
INIT_LIST_HEAD(&jsk->sk_session_queue);
|
||||
|
||||
/* j1939_sk_sock_destruct() depends on SOCK_RCU_FREE flag */
|
||||
sock_set_flag(sk, SOCK_RCU_FREE);
|
||||
sk->sk_destruct = j1939_sk_sock_destruct;
|
||||
sk->sk_protocol = CAN_J1939;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user