Skip to content

Commit 3a58f13

Browse files
Tetsuo HandaPaolo Abeni
authored andcommitted
net: rds: acquire refcount on TCP sockets
syzbot is reporting use-after-free read in tcp_retransmit_timer() [1], for TCP socket used by RDS is accessing sock_net() without acquiring a refcount on net namespace. Since TCP's retransmission can happen after a process which created net namespace terminated, we need to explicitly acquire a refcount. Link: https://syzkaller.appspot.com/bug?extid=694120e1002c117747ed [1] Reported-by: syzbot <[email protected]> Fixes: 26abe14 ("net: Modify sk_alloc to not reference count the netns of kernel sockets.") Fixes: 8a68173 ("net: sk_clone_lock() should only do get_net() if the parent is not a kernel socket") Signed-off-by: Tetsuo Handa <[email protected]> Tested-by: syzbot <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent f5c2174 commit 3a58f13

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

net/rds/tcp.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,14 @@ void rds_tcp_tune(struct socket *sock)
495495

496496
tcp_sock_set_nodelay(sock->sk);
497497
lock_sock(sk);
498+
/* TCP timer functions might access net namespace even after
499+
* a process which created this net namespace terminated.
500+
*/
501+
if (!sk->sk_net_refcnt) {
502+
sk->sk_net_refcnt = 1;
503+
get_net_track(net, &sk->ns_tracker, GFP_KERNEL);
504+
sock_inuse_add(net, 1);
505+
}
498506
if (rtn->sndbuf_size > 0) {
499507
sk->sk_sndbuf = rtn->sndbuf_size;
500508
sk->sk_userlocks |= SOCK_SNDBUF_LOCK;

0 commit comments

Comments
 (0)