On Tue, May 3, 2022 at 2:17 PM Eric Dumazet <edumazet@xxxxxxxxxx> wrote: > > On Tue, May 3, 2022 at 4:40 AM <patchwork-bot+netdevbpf@xxxxxxxxxx> wrote: > > > > Hello: > > > > This patch was applied to netdev/net.git (master) > > by Paolo Abeni <pabeni@xxxxxxxxxx>: > > > > On Mon, 2 May 2022 10:40:18 +0900 you 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. > > > > > > Link: https://syzkaller.appspot.com/bug?extid=694120e1002c117747ed [1] > > > Reported-by: syzbot <syzbot+694120e1002c117747ed@xxxxxxxxxxxxxxxxxxxxxxxxx> > > > Fixes: 26abe14379f8e2fa ("net: Modify sk_alloc to not reference count the netns of kernel sockets.") > > > Fixes: 8a68173691f03661 ("net: sk_clone_lock() should only do get_net() if the parent is not a kernel socket") > > > Signed-off-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx> > > > Tested-by: syzbot <syzbot+694120e1002c117747ed@xxxxxxxxxxxxxxxxxxxxxxxxx> > > > > > > [...] > > > > Here is the summary with links: > > - [v2] net: rds: acquire refcount on TCP sockets > > https://git.kernel.org/netdev/net/c/3a58f13a881e > > > > You are awesome, thank you! > > -- > > Deet-doot-dot, I am a bot. > > https://korg.docs.kernel.org/patchwork/pwbot.html > > > > > > I think we merged this patch too soon. > > My question is : What prevents rds_tcp_conn_path_connect(), and thus > rds_tcp_tune() to be called > after the netns refcount already reached 0 ? > > I guess we can wait for next syzbot report, but I think that get_net() > should be replaced > by maybe_get_net() Yes, syzbot was fast to trigger this exact issue: HEAD commit: 3a58f13a net: rds: acquire refcount on TCP sockets git tree: git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git master ------------[ cut here ]------------ refcount_t: addition on 0; use-after-free. WARNING: CPU: 1 PID: 6934 at lib/refcount.c:25 refcount_warn_saturate+0x169/0x1e0 lib/refcount.c:25 Modules linked in: CPU: 1 PID: 6934 Comm: kworker/u4:17 Not tainted 5.18.0-rc4-syzkaller-00209-g3a58f13a881e #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: krdsd rds_connect_worker RIP: 0010:refcount_warn_saturate+0x169/0x1e0 lib/refcount.c:25 Code: 09 31 ff 89 de e8 f7 b9 81 fd 84 db 0f 85 36 ff ff ff e8 0a b6 81 fd 48 c7 c7 40 eb 26 8a c6 05 75 1f ac 09 01 e8 56 75 2d 05 <0f> 0b e9 17 ff ff ff e8 eb b5 81 fd 0f b6 1d 5a 1f ac 09 31 ff 89 RSP: 0018:ffffc9000b5e7b80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000 RDX: ffff88807a948000 RSI: ffffffff81600c08 RDI: fffff520016bcf62 RBP: 0000000000000002 R08: 0000000000000000 R09: 0000000000000000 R10: ffffffff815fb5de R11: 0000000000000000 R12: ffff888021e69b80 R13: ffff88805bc82a00 R14: ffff888021e69ccc R15: ffff8880741a2900 FS: 0000000000000000(0000) GS:ffff8880b9d00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000001b2cb5c000 CR3: 000000005688f000 CR4: 00000000003506e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <TASK> __refcount_add include/linux/refcount.h:199 [inline] __refcount_inc include/linux/refcount.h:250 [inline] refcount_inc include/linux/refcount.h:267 [inline] get_net include/net/net_namespace.h:248 [inline] get_net_track include/net/net_namespace.h:334 [inline] rds_tcp_tune+0x5a0/0x5f0 net/rds/tcp.c:503 rds_tcp_conn_path_connect+0x489/0x880 net/rds/tcp_connect.c:127 rds_connect_worker+0x1a5/0x2c0 net/rds/threads.c:176 process_one_work+0x996/0x1610 kernel/workqueue.c:2289 worker_thread+0x665/0x1080 kernel/workqueue.c:2436 kthread+0x2e9/0x3a0 kernel/kthread.c:376 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298 </TASK>