]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.10.5/tcp-fix-various-issues-for-sockets-morphing-to-listen-state.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.10.5 / tcp-fix-various-issues-for-sockets-morphing-to-listen-state.patch
1 From foo@baz Sat Mar 18 22:03:53 CST 2017
2 From: Eric Dumazet <edumazet@google.com>
3 Date: Fri, 3 Mar 2017 14:08:21 -0800
4 Subject: tcp: fix various issues for sockets morphing to listen state
5
6 From: Eric Dumazet <edumazet@google.com>
7
8
9 [ Upstream commit 02b2faaf0af1d85585f6d6980e286d53612acfc2 ]
10
11 Dmitry Vyukov reported a divide by 0 triggered by syzkaller, exploiting
12 tcp_disconnect() path that was never really considered and/or used
13 before syzkaller ;)
14
15 I was not able to reproduce the bug, but it seems issues here are the
16 three possible actions that assumed they would never trigger on a
17 listener.
18
19 1) tcp_write_timer_handler
20 2) tcp_delack_timer_handler
21 3) MTU reduction
22
23 Only IPv6 MTU reduction was properly testing TCP_CLOSE and TCP_LISTEN
24 states from tcp_v6_mtu_reduced()
25
26 Signed-off-by: Eric Dumazet <edumazet@google.com>
27 Reported-by: Dmitry Vyukov <dvyukov@google.com>
28 Signed-off-by: David S. Miller <davem@davemloft.net>
29 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
30 ---
31 net/ipv4/tcp_ipv4.c | 7 +++++--
32 net/ipv4/tcp_timer.c | 6 ++++--
33 2 files changed, 9 insertions(+), 4 deletions(-)
34
35 --- a/net/ipv4/tcp_ipv4.c
36 +++ b/net/ipv4/tcp_ipv4.c
37 @@ -269,10 +269,13 @@ EXPORT_SYMBOL(tcp_v4_connect);
38 */
39 void tcp_v4_mtu_reduced(struct sock *sk)
40 {
41 - struct dst_entry *dst;
42 struct inet_sock *inet = inet_sk(sk);
43 - u32 mtu = tcp_sk(sk)->mtu_info;
44 + struct dst_entry *dst;
45 + u32 mtu;
46
47 + if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE))
48 + return;
49 + mtu = tcp_sk(sk)->mtu_info;
50 dst = inet_csk_update_pmtu(sk, mtu);
51 if (!dst)
52 return;
53 --- a/net/ipv4/tcp_timer.c
54 +++ b/net/ipv4/tcp_timer.c
55 @@ -249,7 +249,8 @@ void tcp_delack_timer_handler(struct soc
56
57 sk_mem_reclaim_partial(sk);
58
59 - if (sk->sk_state == TCP_CLOSE || !(icsk->icsk_ack.pending & ICSK_ACK_TIMER))
60 + if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) ||
61 + !(icsk->icsk_ack.pending & ICSK_ACK_TIMER))
62 goto out;
63
64 if (time_after(icsk->icsk_ack.timeout, jiffies)) {
65 @@ -552,7 +553,8 @@ void tcp_write_timer_handler(struct sock
66 struct inet_connection_sock *icsk = inet_csk(sk);
67 int event;
68
69 - if (sk->sk_state == TCP_CLOSE || !icsk->icsk_pending)
70 + if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) ||
71 + !icsk->icsk_pending)
72 goto out;
73
74 if (time_after(icsk->icsk_timeout, jiffies)) {