Skip to contentSkip to conversation

net, sk_msg: Don't check if sock is locked when tearing down psock

PATCH Applied Jakub Sitnicki 4 participants 4 messages Jan 21, 2020 – Jan 22, 2020

Subsystems (3)
lore
Share & tools
lore

Jakub Sitnicki

author maintainer
#0 lore raw

PATCH 1/1 net, sk_msg: Don't check if sock is locked when tearing down psock

As John Fastabend reports [0], psock state tear-down can happen on receive path *after* unlocking the socket, if the only other psock user, that is sockmap or sockhash, releases its psock reference before tcp_bpf_recvmsg does so:

tcp_bpf_recvmsg()
psock = sk_psock_get(sk) <- refcnt 2
lock_sock(sk);
...
sock_map_free() <- refcnt 1
release_sock(sk)
sk_psock_put() <- refcnt 0

Remove the lockdep check for socket lock in psock tear-down that got introduced in 7e81a3530206 ("bpf: Sockmap, ensure sock lock held during tear down").

[0] https://lore.kernel.org/netdev/[email protected]/

Fixes 7e81a3530206 ("bpf: Sockmap, ensure sock lock held during tear down")
Reported-by [email protected]
---
 net/core/skmsg.c | 2 --
 1 file changed, 2 deletions(-)
net/core/skmsg.c +0 -2
index 3866d7e20c07..ded2d5227678 100644
@@ -594,8 +594,6 @@ EXPORT_SYMBOL_GPL(sk_psock_destroy);
 
 void sk_psock_drop(struct sock *sk, struct sk_psock *psock)
 {
-	sock_owned_by_me(sk);
-
 	sk_psock_cork_free(psock);
 	sk_psock_zap_ingress(psock);
 
Signature · 1 line
2.24.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 19 lines · Jakub Sitnicki

As John Fastabend reports [0], psock state tear-down can happen on receive path *after* unlocking the socket, if the only other psock user, that is sockmap or sockhash, releases its psock reference before tcp_bpf_recvmsg does so:

tcp_bpf_recvmsg()
psock = sk_psock_get(sk) <- refcnt 2
lock_sock(sk);
...
sock_map_free() <- refcnt 1
release_sock(sk)
sk_psock_put() <- refcnt 0

Remove the lockdep check for socket lock in psock tear-down that got introduced in 7e81a3530206 ("bpf: Sockmap, ensure sock lock held during tear down").

[0] https://lore.kernel.org/netdev/[email protected]/

Quoted 7 lines
Fixes 7e81a3530206 ("bpf: Sockmap, ensure sock lock held during tear down")
Reported-by [email protected]
---
 net/core/skmsg.c | 2 --
 1 file changed, 2 deletions(-)

Thanks Jakub, this was not needed I got a bit carried away. I'll add a selftest to catch this case by duplicating the reproducer into test_sockmap.c

Acked-by on v1 1/1
#2 lore raw
In reply to Jakub Sitnicki
Quoted 17 lines · Jakub Sitnicki

As John Fastabend reports [0], psock state tear-down can happen on receive path *after* unlocking the socket, if the only other psock user, that is sockmap or sockhash, releases its psock reference before tcp_bpf_recvmsg does so:

  tcp_bpf_recvmsg()
   psock = sk_psock_get(sk)                         <- refcnt 2
   lock_sock(sk);
   ...
                                   sock_map_free()  <- refcnt 1
   release_sock(sk)
   sk_psock_put()                                   <- refcnt 0

Remove the lockdep check for socket lock in psock tear-down that got introduced in 7e81a3530206 ("bpf: Sockmap, ensure sock lock held during tear down").

Quoted 6 lines

[0] https://lore.kernel.org/netdev/[email protected]/

Fixes 7e81a3530206 ("bpf: Sockmap, ensure sock lock held during tear down")
Reported-by [email protected]

Given it's assigned to you right now, David, feel free to take directly to net:

Thanks,
Daniel

maintainer Applied
#3 lore raw
In reply to Jakub Sitnicki

From: Jakub Sitnicki <[email protected]>
Date: Tue, 21 Jan 2020 13:31:47 +0100

Quoted 17 lines

As John Fastabend reports [0], psock state tear-down can happen on receive path *after* unlocking the socket, if the only other psock user, that is sockmap or sockhash, releases its psock reference before tcp_bpf_recvmsg does so:

tcp_bpf_recvmsg()
psock = sk_psock_get(sk) <- refcnt 2
lock_sock(sk);
...
sock_map_free() <- refcnt 1
release_sock(sk)
sk_psock_put() <- refcnt 0

Remove the lockdep check for socket lock in psock tear-down that got introduced in 7e81a3530206 ("bpf: Sockmap, ensure sock lock held during tear down").

Quoted 6 lines

[0] https://lore.kernel.org/netdev/[email protected]/

Fixes 7e81a3530206 ("bpf: Sockmap, ensure sock lock held during tear down")
Reported-by [email protected]

Applied, thank you.