]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.177/tcp-dccp-remove-reqsk_put-from-inet_child_forget.patch
Linux 4.4.177
[thirdparty/kernel/stable-queue.git] / releases / 4.4.177 / tcp-dccp-remove-reqsk_put-from-inet_child_forget.patch
1 From da8ab57863ed7e912d10b179b6bdc652f635bd19 Mon Sep 17 00:00:00 2001
2 From: Eric Dumazet <edumazet@google.com>
3 Date: Mon, 11 Sep 2017 15:58:38 -0700
4 Subject: tcp/dccp: remove reqsk_put() from inet_child_forget()
5
6 From: Eric Dumazet <edumazet@google.com>
7
8 commit da8ab57863ed7e912d10b179b6bdc652f635bd19 upstream.
9
10 Back in linux-4.4, I inadvertently put a call to reqsk_put() in
11 inet_child_forget(), forgetting it could be called from two different
12 points.
13
14 In the case it is called from inet_csk_reqsk_queue_add(), we want to
15 keep the reference on the request socket, since it is released later by
16 the caller (tcp_v{4|6}_rcv())
17
18 This bug never showed up because atomic_dec_and_test() was not signaling
19 the underflow, and SLAB_DESTROY_BY RCU semantic for request sockets
20 prevented the request to be put in quarantine.
21
22 Recent conversion of socket refcount from atomic_t to refcount_t finally
23 exposed the bug.
24
25 So move the reqsk_put() to inet_csk_listen_stop() to fix this.
26
27 Thanks to Shankara Pailoor for using syzkaller and providing
28 a nice set of .config and C repro.
29
30 WARNING: CPU: 2 PID: 4277 at lib/refcount.c:186
31 refcount_sub_and_test+0x167/0x1b0 lib/refcount.c:186
32 Kernel panic - not syncing: panic_on_warn set ...
33
34 CPU: 2 PID: 4277 Comm: syz-executor0 Not tainted 4.13.0-rc7 #3
35 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
36 Ubuntu-1.8.2-1ubuntu1 04/01/2014
37 Call Trace:
38 <IRQ>
39 __dump_stack lib/dump_stack.c:16 [inline]
40 dump_stack+0xf7/0x1aa lib/dump_stack.c:52
41 panic+0x1ae/0x3a7 kernel/panic.c:180
42 __warn+0x1c4/0x1d9 kernel/panic.c:541
43 report_bug+0x211/0x2d0 lib/bug.c:183
44 fixup_bug+0x40/0x90 arch/x86/kernel/traps.c:190
45 do_trap_no_signal arch/x86/kernel/traps.c:224 [inline]
46 do_trap+0x260/0x390 arch/x86/kernel/traps.c:273
47 do_error_trap+0x118/0x340 arch/x86/kernel/traps.c:310
48 do_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:323
49 invalid_op+0x18/0x20 arch/x86/entry/entry_64.S:846
50 RIP: 0010:refcount_sub_and_test+0x167/0x1b0 lib/refcount.c:186
51 RSP: 0018:ffff88006e006b60 EFLAGS: 00010286
52 RAX: 0000000000000026 RBX: 0000000000000000 RCX: 0000000000000000
53 RDX: 0000000000000026 RSI: 1ffff1000dc00d2c RDI: ffffed000dc00d60
54 RBP: ffff88006e006bf0 R08: 0000000000000001 R09: 0000000000000000
55 R10: 0000000000000000 R11: 0000000000000000 R12: 1ffff1000dc00d6d
56 R13: 00000000ffffffff R14: 0000000000000001 R15: ffff88006ce9d340
57 refcount_dec_and_test+0x1a/0x20 lib/refcount.c:211
58 reqsk_put+0x71/0x2b0 include/net/request_sock.h:123
59 tcp_v4_rcv+0x259e/0x2e20 net/ipv4/tcp_ipv4.c:1729
60 ip_local_deliver_finish+0x2e2/0xba0 net/ipv4/ip_input.c:216
61 NF_HOOK include/linux/netfilter.h:248 [inline]
62 ip_local_deliver+0x1ce/0x6d0 net/ipv4/ip_input.c:257
63 dst_input include/net/dst.h:477 [inline]
64 ip_rcv_finish+0x8db/0x19c0 net/ipv4/ip_input.c:397
65 NF_HOOK include/linux/netfilter.h:248 [inline]
66 ip_rcv+0xc3f/0x17d0 net/ipv4/ip_input.c:488
67 __netif_receive_skb_core+0x1fb7/0x31f0 net/core/dev.c:4298
68 __netif_receive_skb+0x2c/0x1b0 net/core/dev.c:4336
69 process_backlog+0x1c5/0x6d0 net/core/dev.c:5102
70 napi_poll net/core/dev.c:5499 [inline]
71 net_rx_action+0x6d3/0x14a0 net/core/dev.c:5565
72 __do_softirq+0x2cb/0xb2d kernel/softirq.c:284
73 do_softirq_own_stack+0x1c/0x30 arch/x86/entry/entry_64.S:898
74 </IRQ>
75 do_softirq.part.16+0x63/0x80 kernel/softirq.c:328
76 do_softirq kernel/softirq.c:176 [inline]
77 __local_bh_enable_ip+0x84/0x90 kernel/softirq.c:181
78 local_bh_enable include/linux/bottom_half.h:31 [inline]
79 rcu_read_unlock_bh include/linux/rcupdate.h:705 [inline]
80 ip_finish_output2+0x8ad/0x1360 net/ipv4/ip_output.c:231
81 ip_finish_output+0x74e/0xb80 net/ipv4/ip_output.c:317
82 NF_HOOK_COND include/linux/netfilter.h:237 [inline]
83 ip_output+0x1cc/0x850 net/ipv4/ip_output.c:405
84 dst_output include/net/dst.h:471 [inline]
85 ip_local_out+0x95/0x160 net/ipv4/ip_output.c:124
86 ip_queue_xmit+0x8c6/0x1810 net/ipv4/ip_output.c:504
87 tcp_transmit_skb+0x1963/0x3320 net/ipv4/tcp_output.c:1123
88 tcp_send_ack.part.35+0x38c/0x620 net/ipv4/tcp_output.c:3575
89 tcp_send_ack+0x49/0x60 net/ipv4/tcp_output.c:3545
90 tcp_rcv_synsent_state_process net/ipv4/tcp_input.c:5795 [inline]
91 tcp_rcv_state_process+0x4876/0x4b60 net/ipv4/tcp_input.c:5930
92 tcp_v4_do_rcv+0x58a/0x820 net/ipv4/tcp_ipv4.c:1483
93 sk_backlog_rcv include/net/sock.h:907 [inline]
94 __release_sock+0x124/0x360 net/core/sock.c:2223
95 release_sock+0xa4/0x2a0 net/core/sock.c:2715
96 inet_wait_for_connect net/ipv4/af_inet.c:557 [inline]
97 __inet_stream_connect+0x671/0xf00 net/ipv4/af_inet.c:643
98 inet_stream_connect+0x58/0xa0 net/ipv4/af_inet.c:682
99 SYSC_connect+0x204/0x470 net/socket.c:1628
100 SyS_connect+0x24/0x30 net/socket.c:1609
101 entry_SYSCALL_64_fastpath+0x18/0xad
102 RIP: 0033:0x451e59
103 RSP: 002b:00007f474843fc08 EFLAGS: 00000216 ORIG_RAX: 000000000000002a
104 RAX: ffffffffffffffda RBX: 0000000000718000 RCX: 0000000000451e59
105 RDX: 0000000000000010 RSI: 0000000020002000 RDI: 0000000000000007
106 RBP: 0000000000000046 R08: 0000000000000000 R09: 0000000000000000
107 R10: 0000000000000000 R11: 0000000000000216 R12: 0000000000000000
108 R13: 00007ffc040a0f8f R14: 00007f47484409c0 R15: 0000000000000000
109
110 Fixes: ebb516af60e1 ("tcp/dccp: fix race at listener dismantle phase")
111 Signed-off-by: Eric Dumazet <edumazet@google.com>
112 Reported-by: Shankara Pailoor <sp3485@columbia.edu>
113 Tested-by: Shankara Pailoor <sp3485@columbia.edu>
114 Signed-off-by: David S. Miller <davem@davemloft.net>
115 Cc: Guillaume Nault <gnault@redhat.com>
116 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
117
118 ---
119 net/ipv4/inet_connection_sock.c | 2 +-
120 1 file changed, 1 insertion(+), 1 deletion(-)
121
122 --- a/net/ipv4/inet_connection_sock.c
123 +++ b/net/ipv4/inet_connection_sock.c
124 @@ -787,7 +787,6 @@ static void inet_child_forget(struct soc
125 tcp_sk(child)->fastopen_rsk = NULL;
126 }
127 inet_csk_destroy_sock(child);
128 - reqsk_put(req);
129 }
130
131 struct sock *inet_csk_reqsk_queue_add(struct sock *sk,
132 @@ -858,6 +857,7 @@ void inet_csk_listen_stop(struct sock *s
133 sock_hold(child);
134
135 inet_child_forget(sk, req, child);
136 + reqsk_put(req);
137 bh_unlock_sock(child);
138 local_bh_enable();
139 sock_put(child);