Skip to content

Commit 01bfe5e

Browse files
lxindavem330
authored andcommitted
Revert "net/sctp: fix race condition in sctp_destroy_sock"
This reverts commit b166a20. This one has to be reverted as it introduced a dead lock, as syzbot reported: CPU0 CPU1 ---- ---- lock(&net->sctp.addr_wq_lock); lock(slock-AF_INET6); lock(&net->sctp.addr_wq_lock); lock(slock-AF_INET6); CPU0 is the thread of sctp_addr_wq_timeout_handler(), and CPU1 is that of sctp_close(). The original issue this commit fixed will be fixed in the next patch. Reported-by: [email protected] Signed-off-by: Xin Long <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2e9f609 commit 01bfe5e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

net/sctp/socket.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,9 +1520,11 @@ static void sctp_close(struct sock *sk, long timeout)
15201520

15211521
/* Supposedly, no process has access to the socket, but
15221522
* the net layers still may.
1523+
* Also, sctp_destroy_sock() needs to be called with addr_wq_lock
1524+
* held and that should be grabbed before socket lock.
15231525
*/
1524-
local_bh_disable();
1525-
bh_lock_sock(sk);
1526+
spin_lock_bh(&net->sctp.addr_wq_lock);
1527+
bh_lock_sock_nested(sk);
15261528

15271529
/* Hold the sock, since sk_common_release() will put sock_put()
15281530
* and we have just a little more cleanup.
@@ -1531,7 +1533,7 @@ static void sctp_close(struct sock *sk, long timeout)
15311533
sk_common_release(sk);
15321534

15331535
bh_unlock_sock(sk);
1534-
local_bh_enable();
1536+
spin_unlock_bh(&net->sctp.addr_wq_lock);
15351537

15361538
sock_put(sk);
15371539

@@ -4991,6 +4993,9 @@ static int sctp_init_sock(struct sock *sk)
49914993
sk_sockets_allocated_inc(sk);
49924994
sock_prot_inuse_add(net, sk->sk_prot, 1);
49934995

4996+
/* Nothing can fail after this block, otherwise
4997+
* sctp_destroy_sock() will be called without addr_wq_lock held
4998+
*/
49944999
if (net->sctp.default_auto_asconf) {
49955000
spin_lock(&sock_net(sk)->sctp.addr_wq_lock);
49965001
list_add_tail(&sp->auto_asconf_list,
@@ -5025,9 +5030,7 @@ static void sctp_destroy_sock(struct sock *sk)
50255030

50265031
if (sp->do_auto_asconf) {
50275032
sp->do_auto_asconf = 0;
5028-
spin_lock_bh(&sock_net(sk)->sctp.addr_wq_lock);
50295033
list_del(&sp->auto_asconf_list);
5030-
spin_unlock_bh(&sock_net(sk)->sctp.addr_wq_lock);
50315034
}
50325035
sctp_endpoint_free(sp->ep);
50335036
local_bh_disable();

0 commit comments

Comments
 (0)