Skip to content

Commit c16f949

Browse files
committed
net: tcp: fix unexcepted socket die when snd_wnd is 0
jira LE-3201 Rebuild_History Non-Buildable kernel-rt-4.18.0-553.22.1.rt7.363.el8_10 commit-author Menglong Dong <imagedong@tencent.com> commit e89688e 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 <imagedong@tencent.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit e89688e) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent d94d3b9 commit c16f949

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
@@ -419,6 +419,22 @@ static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock *req)
419419
TCP_TIMEOUT_INIT << req->num_timeout, TCP_RTO_MAX);
420420
}
421421

422+
static bool tcp_rtx_probe0_timed_out(const struct sock *sk,
423+
const struct sk_buff *skb)
424+
{
425+
const struct tcp_sock *tp = tcp_sk(sk);
426+
const int timeout = TCP_RTO_MAX * 2;
427+
u32 rcv_delta, rtx_delta;
428+
429+
rcv_delta = inet_csk(sk)->icsk_timeout - tp->rcv_tstamp;
430+
if (rcv_delta <= timeout)
431+
return false;
432+
433+
rtx_delta = (u32)msecs_to_jiffies(tcp_time_stamp(tp) -
434+
(tp->retrans_stamp ?: tcp_skb_timestamp(skb)));
435+
436+
return rtx_delta > timeout;
437+
}
422438

423439
/**
424440
* tcp_retransmit_timer() - The TCP retransmit timeout handler
@@ -484,7 +500,7 @@ void tcp_retransmit_timer(struct sock *sk)
484500
tp->snd_una, tp->snd_nxt);
485501
}
486502
#endif
487-
if (tcp_jiffies32 - tp->rcv_tstamp > TCP_RTO_MAX) {
503+
if (tcp_rtx_probe0_timed_out(sk, skb)) {
488504
tcp_write_err(sk);
489505
goto out;
490506
}

0 commit comments

Comments
 (0)