Re: [PATCH] net: rds: acquire refcount on TCP sockets
From: Eric Dumazet <edumazet@google.com>
Date: 2022-05-01 16:14:20
Also in:
linux-rdma
On Sun, May 1, 2022 at 8:29 AM Tetsuo Handa [off-list ref] wrote:
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.
Please add a Fixes: tag
quoted hunk ↗ jump to hunk
Link: https://syzkaller.appspot.com/bug?extid=694120e1002c117747ed [1] Reported-by: syzbot <redacted> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Tested-by: syzbot <redacted> --- net/rds/tcp.c | 9 +++++++++ 1 file changed, 9 insertions(+)diff --git a/net/rds/tcp.c b/net/rds/tcp.c index 5327d130c4b5..8015d2695784 100644 --- a/net/rds/tcp.c +++ b/net/rds/tcp.c@@ -493,6 +493,15 @@ void rds_tcp_tune(struct socket *sock) struct net *net = sock_net(sk); struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid); + /* TCP timer functions might access net namespace even after + * a process which created this net namespace terminated. + */
Please move this after the lock_sock(sk) [1], so that we are protected correctly ?
+ if (!sk->sk_net_refcnt) {
+ sk->sk_net_refcnt = 1;
+ get_net_track(net, &sk->ns_tracker, GFP_KERNEL);
+ sock_inuse_add(net, 1);
+ }
+
tcp_sock_set_nodelay(sock->sk);lock_sock(sk);
[1] Here.
if (rtn->sndbuf_size > 0) {
--
2.34.1