Skip to content

Commit b9fb10d

Browse files
edumazetdavem330
authored andcommitted
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: 0b2c597 ("l2tp: close all race conditions in l2tp_tunnel_register()") Reported-by: [email protected] Signed-off-by: Eric Dumazet <[email protected]> Link: https://lore.kernel.org/netdev/[email protected]/T/#m1164ff20628671b0f326a24cb106ab3239c70ce3 Cc: Cong Wang <[email protected]> Cc: Guillaume Nault <[email protected]> Reviewed-by: Guillaume Nault <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d71ebe8 commit b9fb10d

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

net/l2tp/l2tp_core.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,10 +1483,8 @@ int l2tp_tunnel_register(struct l2tp_tunnel *tunnel, struct net *net,
14831483
lock_sock(sk);
14841484
write_lock_bh(&sk->sk_callback_lock);
14851485
ret = l2tp_validate_socket(sk, net, tunnel->encap);
1486-
if (ret < 0) {
1487-
release_sock(sk);
1486+
if (ret < 0)
14881487
goto err_inval_sock;
1489-
}
14901488
rcu_assign_sk_user_data(sk, tunnel);
14911489
write_unlock_bh(&sk->sk_callback_lock);
14921490

@@ -1523,6 +1521,7 @@ int l2tp_tunnel_register(struct l2tp_tunnel *tunnel, struct net *net,
15231521

15241522
err_inval_sock:
15251523
write_unlock_bh(&sk->sk_callback_lock);
1524+
release_sock(sk);
15261525

15271526
if (tunnel->fd < 0)
15281527
sock_release(sock);

0 commit comments

Comments
 (0)