Commit a41e8a88 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller
Browse files

tcp: better handle TCP_USER_TIMEOUT in SYN_SENT state

Yuchung Cheng and Marek Majkowski independently reported a weird
behavior of TCP_USER_TIMEOUT option when used at connect() time.

When the TCP_USER_TIMEOUT is reached, tcp_write_timeout()
believes the flow should live, and the following condition
in tcp_clamp_rto_to_user_timeout() programs one jiffie timers :

    remaining = icsk->icsk_user_timeout - elapsed;
    if (remaining <= 0)
        return 1; /* user timeout has passed; fire ASAP */

This silly situation ends when the max syn rtx count is reached.

This patch makes sure we honor both TCP_SYNCNT and TCP_USER_TIMEOUT,
avoiding these spurious SYN packets.

Fixes: b701a99e

 ("tcp: Add tcp_clamp_rto_to_user_timeout() helper to improve accuracy")
Signed-off-by: default avatarEric Dumazet <>
Reported-by: default avatarYuchung Cheng <>
Reported-by: default avatarMarek Majkowski <>
Cc: Jon Maxwell <>

Acked-by: default avatarJon Maxwell <>
Tested-by: default avatarMarek Majkowski <>
Signed-off-by: default avatarMarek Majkowski <>
Acked-by: default avatarYuchung Cheng <>
Signed-off-by: default avatarDavid S. Miller <>
parent 174e2381
......@@ -210,7 +210,7 @@ static int tcp_write_timeout(struct sock *sk)
struct inet_connection_sock *icsk = inet_csk(sk);
struct tcp_sock *tp = tcp_sk(sk);
struct net *net = sock_net(sk);
bool expired, do_reset;
bool expired = false, do_reset;
int retry_until;
if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) {
......@@ -242,9 +242,10 @@ static int tcp_write_timeout(struct sock *sk)
if (tcp_out_of_resources(sk, do_reset))
return 1;
if (!expired)
expired = retransmits_timed_out(sk, retry_until,
tcp_fastopen_active_detect_blackhole(sk, expired);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment