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
6 From: Eric Dumazet <edumazet@google.com>
9 [ Upstream commit 02b2faaf0af1d85585f6d6980e286d53612acfc2 ]
11 Dmitry Vyukov reported a divide by 0 triggered by syzkaller, exploiting
12 tcp_disconnect() path that was never really considered and/or used
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
19 1) tcp_write_timer_handler
20 2) tcp_delack_timer_handler
23 Only IPv6 MTU reduction was properly testing TCP_CLOSE and TCP_LISTEN
24 states from tcp_v6_mtu_reduced()
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>
31 net/ipv4/tcp_ipv4.c | 7 +++++--
32 net/ipv4/tcp_timer.c | 6 ++++--
33 2 files changed, 9 insertions(+), 4 deletions(-)
35 --- a/net/ipv4/tcp_ipv4.c
36 +++ b/net/ipv4/tcp_ipv4.c
37 @@ -269,10 +269,13 @@ EXPORT_SYMBOL(tcp_v4_connect);
39 void tcp_v4_mtu_reduced(struct sock *sk)
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;
47 + if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE))
49 + mtu = tcp_sk(sk)->mtu_info;
50 dst = inet_csk_update_pmtu(sk, mtu);
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
57 sk_mem_reclaim_partial(sk);
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))
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);
69 - if (sk->sk_state == TCP_CLOSE || !icsk->icsk_pending)
70 + if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) ||
71 + !icsk->icsk_pending)
74 if (time_after(icsk->icsk_timeout, jiffies)) {