mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 12:28:41 +08:00
l2tp: prevent lockdep issue in l2tp_tunnel_register()
lockdep complains with the following lock/unlock sequence:
lock_sock(sk);
write_lock_bh(&sk->sk_callback_lock);
[1] release_sock(sk);
[2] write_unlock_bh(&sk->sk_callback_lock);
We need to swap [1] and [2] to fix this issue.
Fixes: 0b2c59720e
("l2tp: close all race conditions in l2tp_tunnel_register()")
Reported-by: syzbot+bbd35b345c7cab0d9a08@syzkaller.appspotmail.com
Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/netdev/20230114030137.672706-1-xiyou.wangcong@gmail.com/T/#m1164ff20628671b0f326a24cb106ab3239c70ce3
Cc: Cong Wang <cong.wang@bytedance.com>
Cc: Guillaume Nault <gnault@redhat.com>
Reviewed-by: Guillaume Nault <gnault@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
d71ebe8114
commit
b9fb10d131
@ -1483,10 +1483,8 @@ int l2tp_tunnel_register(struct l2tp_tunnel *tunnel, struct net *net,
|
|||||||
lock_sock(sk);
|
lock_sock(sk);
|
||||||
write_lock_bh(&sk->sk_callback_lock);
|
write_lock_bh(&sk->sk_callback_lock);
|
||||||
ret = l2tp_validate_socket(sk, net, tunnel->encap);
|
ret = l2tp_validate_socket(sk, net, tunnel->encap);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
release_sock(sk);
|
|
||||||
goto err_inval_sock;
|
goto err_inval_sock;
|
||||||
}
|
|
||||||
rcu_assign_sk_user_data(sk, tunnel);
|
rcu_assign_sk_user_data(sk, tunnel);
|
||||||
write_unlock_bh(&sk->sk_callback_lock);
|
write_unlock_bh(&sk->sk_callback_lock);
|
||||||
|
|
||||||
@ -1523,6 +1521,7 @@ int l2tp_tunnel_register(struct l2tp_tunnel *tunnel, struct net *net,
|
|||||||
|
|
||||||
err_inval_sock:
|
err_inval_sock:
|
||||||
write_unlock_bh(&sk->sk_callback_lock);
|
write_unlock_bh(&sk->sk_callback_lock);
|
||||||
|
release_sock(sk);
|
||||||
|
|
||||||
if (tunnel->fd < 0)
|
if (tunnel->fd < 0)
|
||||||
sock_release(sock);
|
sock_release(sock);
|
||||||
|
Loading…
Reference in New Issue
Block a user