All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
To: Santosh Shilimkar <santosh.shilimkar@oracle.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: syzbot <syzbot+694120e1002c117747ed@syzkaller.appspotmail.com>,
	netdev@vger.kernel.org, syzkaller-bugs@googlegroups.com,
	OFED mailing list <linux-rdma@vger.kernel.org>
Subject: [PATCH] net: rds: acquire refcount on TCP sockets
Date: Mon, 2 May 2022 00:29:14 +0900	[thread overview]
Message-ID: <f8ae5dcd-a5ed-2d8b-dd7a-08385e9c3675@I-love.SAKURA.ne.jp> (raw)
In-Reply-To: <5f90c2b8-283e-6ca5-65f9-3ea96df00984@I-love.SAKURA.ne.jp>

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 <syzbot+694120e1002c117747ed@syzkaller.appspotmail.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Tested-by: syzbot <syzbot+694120e1002c117747ed@syzkaller.appspotmail.com>
---
 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.
+	 */
+	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);
 	if (rtn->sndbuf_size > 0) {
-- 
2.34.1


  reply	other threads:[~2022-05-01 15:29 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-24  7:40 KASAN: use-after-free Read in tcp_retransmit_timer (5) syzbot
2021-12-22 11:00 ` [syzbot] " syzbot
2022-04-09  8:19   ` Tetsuo Handa
2022-04-09 16:46     ` Eric Dumazet
2022-04-09 17:47       ` Eric Dumazet
2022-04-09 17:55         ` Eric Dumazet
2022-04-10  0:38           ` Tetsuo Handa
2022-04-10  5:39             ` Tetsuo Handa
2022-04-10 11:36         ` Tetsuo Handa
2022-04-22 14:40     ` Tetsuo Handa
2022-04-24  3:57       ` Tetsuo Handa
2022-05-01 15:29         ` Tetsuo Handa [this message]
2022-05-01 16:14           ` [PATCH] net: rds: acquire refcount on TCP sockets Eric Dumazet
2022-05-02  1:40             ` [PATCH v2] " Tetsuo Handa
2022-05-02 14:12               ` Haakon Bugge
2022-05-02 14:29                 ` Tetsuo Handa
2022-05-03  9:02               ` Paolo Abeni
2022-05-03  9:56                 ` Tetsuo Handa
2022-05-03 11:10                   ` Paolo Abeni
2022-05-03 13:27                 ` David Laight
2022-05-03 13:43                   ` Eric Dumazet
2022-05-03 14:25                     ` David Laight
2022-05-03 13:45                 ` Eric Dumazet
2022-05-03 14:08                   ` Tetsuo Handa
2022-05-03 11:40               ` patchwork-bot+netdevbpf
2022-05-03 21:17                 ` Eric Dumazet
2022-05-03 22:37                   ` Eric Dumazet
2022-05-04  1:04                     ` Tetsuo Handa
2022-05-04  3:09                       ` Eric Dumazet
2022-05-04  4:58                         ` Tetsuo Handa
2022-05-04 15:15                           ` Tetsuo Handa
2022-05-05  0:45                             ` [PATCH] net: rds: use maybe_get_net() when acquiring " Tetsuo Handa
2022-05-05  0:53                               ` Eric Dumazet
2022-05-05  1:04                               ` Jakub Kicinski
2022-05-05  1:53                               ` [PATCH net v2] " Tetsuo Handa
2022-05-05 19:13                                 ` Eric Dumazet
2022-05-06  1:20                                 ` patchwork-bot+netdevbpf
2022-05-04 13:09                   ` [PATCH v2] net: rds: acquire " Paolo Abeni
2022-05-04 13:25                     ` Eric Dumazet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f8ae5dcd-a5ed-2d8b-dd7a-08385e9c3675@I-love.SAKURA.ne.jp \
    --to=penguin-kernel@i-love.sakura.ne.jp \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=santosh.shilimkar@oracle.com \
    --cc=syzbot+694120e1002c117747ed@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.