Skip to content

Commit 2681a78

Browse files
edumazetgregkh
authored andcommitted
tcp: fix various issues for sockets morphing to listen state
[ Upstream commit 02b2faaf0af1d85585f6d6980e286d53612acfc2 ] Dmitry Vyukov reported a divide by 0 triggered by syzkaller, exploiting tcp_disconnect() path that was never really considered and/or used before syzkaller ;) I was not able to reproduce the bug, but it seems issues here are the three possible actions that assumed they would never trigger on a listener. 1) tcp_write_timer_handler 2) tcp_delack_timer_handler 3) MTU reduction Only IPv6 MTU reduction was properly testing TCP_CLOSE and TCP_LISTEN states from tcp_v6_mtu_reduced() Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: Dmitry Vyukov <dvyukov@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9216632 commit 2681a78

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

net/ipv4/tcp_ipv4.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,13 @@ EXPORT_SYMBOL(tcp_v4_connect);
271271
*/
272272
void tcp_v4_mtu_reduced(struct sock *sk)
273273
{
274-
struct dst_entry *dst;
275274
struct inet_sock *inet = inet_sk(sk);
276-
u32 mtu = tcp_sk(sk)->mtu_info;
275+
struct dst_entry *dst;
276+
u32 mtu;
277277

278+
if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE))
279+
return;
280+
mtu = tcp_sk(sk)->mtu_info;
278281
dst = inet_csk_update_pmtu(sk, mtu);
279282
if (!dst)
280283
return;

net/ipv4/tcp_timer.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ void tcp_delack_timer_handler(struct sock *sk)
223223

224224
sk_mem_reclaim_partial(sk);
225225

226-
if (sk->sk_state == TCP_CLOSE || !(icsk->icsk_ack.pending & ICSK_ACK_TIMER))
226+
if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) ||
227+
!(icsk->icsk_ack.pending & ICSK_ACK_TIMER))
227228
goto out;
228229

229230
if (time_after(icsk->icsk_ack.timeout, jiffies)) {
@@ -504,7 +505,8 @@ void tcp_write_timer_handler(struct sock *sk)
504505
struct inet_connection_sock *icsk = inet_csk(sk);
505506
int event;
506507

507-
if (sk->sk_state == TCP_CLOSE || !icsk->icsk_pending)
508+
if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) ||
509+
!icsk->icsk_pending)
508510
goto out;
509511

510512
if (time_after(icsk->icsk_timeout, jiffies)) {

0 commit comments

Comments
 (0)