Skip to content

Commit e89688e

Browse files
menglongdongdavem330
authored andcommitted
net: tcp: fix unexcepted socket die when snd_wnd is 0
In tcp_retransmit_timer(), a window shrunk connection will be regarded as timeout if 'tcp_jiffies32 - tp->rcv_tstamp > TCP_RTO_MAX'. This is not right all the time. The retransmits will become zero-window probes in tcp_retransmit_timer() if the 'snd_wnd==0'. Therefore, the icsk->icsk_rto will come up to TCP_RTO_MAX sooner or later. However, the timer can be delayed and be triggered after 122877ms, not TCP_RTO_MAX, as I tested. Therefore, 'tcp_jiffies32 - tp->rcv_tstamp > TCP_RTO_MAX' is always true once the RTO come up to TCP_RTO_MAX, and the socket will die. Fix this by replacing the 'tcp_jiffies32' with '(u32)icsk->icsk_timeout', which is exact the timestamp of the timeout. However, "tp->rcv_tstamp" can restart from idle, then tp->rcv_tstamp could already be a long time (minutes or hours) in the past even on the first RTO. So we double check the timeout with the duration of the retransmission. Meanwhile, making "2 * TCP_RTO_MAX" as the timeout to avoid the socket dying too soon. Fixes: 1da177e ("Linux-2.6.12-rc2") Link: https://lore.kernel.org/netdev/CADxym3YyMiO+zMD4zj03YPM3FBi-1LHi6gSD2XT8pyAMM096pg@mail.gmail.com/ Signed-off-by: Menglong Dong <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 800a666 commit e89688e

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

net/ipv4/tcp_timer.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,22 @@ static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock *req)
454454
req->timeout << req->num_timeout, TCP_RTO_MAX);
455455
}
456456

457+
static bool tcp_rtx_probe0_timed_out(const struct sock *sk,
458+
const struct sk_buff *skb)
459+
{
460+
const struct tcp_sock *tp = tcp_sk(sk);
461+
const int timeout = TCP_RTO_MAX * 2;
462+
u32 rcv_delta, rtx_delta;
463+
464+
rcv_delta = inet_csk(sk)->icsk_timeout - tp->rcv_tstamp;
465+
if (rcv_delta <= timeout)
466+
return false;
467+
468+
rtx_delta = (u32)msecs_to_jiffies(tcp_time_stamp(tp) -
469+
(tp->retrans_stamp ?: tcp_skb_timestamp(skb)));
470+
471+
return rtx_delta > timeout;
472+
}
457473

458474
/**
459475
* tcp_retransmit_timer() - The TCP retransmit timeout handler
@@ -519,7 +535,7 @@ void tcp_retransmit_timer(struct sock *sk)
519535
tp->snd_una, tp->snd_nxt);
520536
}
521537
#endif
522-
if (tcp_jiffies32 - tp->rcv_tstamp > TCP_RTO_MAX) {
538+
if (tcp_rtx_probe0_timed_out(sk, skb)) {
523539
tcp_write_err(sk);
524540
goto out;
525541
}

0 commit comments

Comments
 (0)