netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net, sk_msg: Don't check if sock is locked when tearing down psock
@ 2020-01-21 12:31 Jakub Sitnicki
  2020-01-22 17:53 ` John Fastabend
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jakub Sitnicki @ 2020-01-21 12:31 UTC (permalink / raw)
  To: netdev; +Cc: John Fastabend, syzbot+d73682fcf7fee6982fe3

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/5e25dc995d7d_74082aaee6e465b441@john-XPS-13-9370.notmuch/

Fixes: 7e81a3530206 ("bpf: Sockmap, ensure sock lock held during tear down")
Reported-by: syzbot+d73682fcf7fee6982fe3@syzkaller.appspotmail.com
Suggested-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
---
 net/core/skmsg.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/net/core/skmsg.c b/net/core/skmsg.c
index 3866d7e20c07..ded2d5227678 100644
--- a/net/core/skmsg.c
+++ b/net/core/skmsg.c
@@ -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);
 
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH net] net, sk_msg: Don't check if sock is locked when tearing down psock
  2020-01-21 12:31 [PATCH net] net, sk_msg: Don't check if sock is locked when tearing down psock Jakub Sitnicki
@ 2020-01-22 17:53 ` John Fastabend
  2020-01-22 17:59 ` Daniel Borkmann
  2020-01-22 19:30 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: John Fastabend @ 2020-01-22 17:53 UTC (permalink / raw)
  To: Jakub Sitnicki, netdev; +Cc: John Fastabend, syzbot+d73682fcf7fee6982fe3

Jakub Sitnicki wrote:
> 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/5e25dc995d7d_74082aaee6e465b441@john-XPS-13-9370.notmuch/
> 
> Fixes: 7e81a3530206 ("bpf: Sockmap, ensure sock lock held during tear down")
> Reported-by: syzbot+d73682fcf7fee6982fe3@syzkaller.appspotmail.com
> Suggested-by: John Fastabend <john.fastabend@gmail.com>
> Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
> ---
>  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: John Fastabend <john.fastabend@gmail.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net, sk_msg: Don't check if sock is locked when tearing down psock
  2020-01-21 12:31 [PATCH net] net, sk_msg: Don't check if sock is locked when tearing down psock Jakub Sitnicki
  2020-01-22 17:53 ` John Fastabend
@ 2020-01-22 17:59 ` Daniel Borkmann
  2020-01-22 19:30 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2020-01-22 17:59 UTC (permalink / raw)
  To: Jakub Sitnicki, netdev; +Cc: John Fastabend, syzbot+d73682fcf7fee6982fe3

On 1/21/20 1:31 PM, Jakub Sitnicki wrote:
> 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/5e25dc995d7d_74082aaee6e465b441@john-XPS-13-9370.notmuch/
> 
> Fixes: 7e81a3530206 ("bpf: Sockmap, ensure sock lock held during tear down")
> Reported-by: syzbot+d73682fcf7fee6982fe3@syzkaller.appspotmail.com
> Suggested-by: John Fastabend <john.fastabend@gmail.com>
> Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>

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

Acked-by: Daniel Borkmann <daniel@iogearbox.net>

Thanks,
Daniel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net, sk_msg: Don't check if sock is locked when tearing down psock
  2020-01-21 12:31 [PATCH net] net, sk_msg: Don't check if sock is locked when tearing down psock Jakub Sitnicki
  2020-01-22 17:53 ` John Fastabend
  2020-01-22 17:59 ` Daniel Borkmann
@ 2020-01-22 19:30 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2020-01-22 19:30 UTC (permalink / raw)
  To: jakub; +Cc: netdev, john.fastabend, syzbot+d73682fcf7fee6982fe3

From: Jakub Sitnicki <jakub@cloudflare.com>
Date: Tue, 21 Jan 2020 13:31:47 +0100

> 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/5e25dc995d7d_74082aaee6e465b441@john-XPS-13-9370.notmuch/
> 
> Fixes: 7e81a3530206 ("bpf: Sockmap, ensure sock lock held during tear down")
> Reported-by: syzbot+d73682fcf7fee6982fe3@syzkaller.appspotmail.com
> Suggested-by: John Fastabend <john.fastabend@gmail.com>
> Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>

Applied, thank you.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-01-22 19:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-21 12:31 [PATCH net] net, sk_msg: Don't check if sock is locked when tearing down psock Jakub Sitnicki
2020-01-22 17:53 ` John Fastabend
2020-01-22 17:59 ` Daniel Borkmann
2020-01-22 19:30 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).