mirror of
https://github.com/torvalds/linux.git
synced 2026-11-20 13:03:48 +00:00
tcp: don't let __tcp_set_rto() return 0
tcp_retransmit_timer() backs off by doubling icsk_rto, so the backoff
only works if icsk_rto is nonzero.
__tcp_set_rto() adds srtt_us >> 3 and rttvar_us with no lower bound, and
relies on tcp_rtt_estimator() to keep rttvar_us at tcp_rto_min() or
above. But tcp_rto_min() returns 0 for a route with a locked
RTAX_RTO_MIN of 0. A first RTT sample of 0 usec, which usec TS allows,
then gives:
srtt_us = max(1U, 0 << 3) = 1
rttvar_us = max(mdev_us, tcp_rto_min_us(sk)) = 0
__tcp_set_rto() = usecs_to_jiffies((1 >> 3) + 0) = 0
Keep the result from 0, so that the backoff recovers from any state of
the RTT estimator.
Do it in __tcp_set_rto() and not in tcp_set_rto(), since
tcp_ld_RTO_revert() uses the same sum. The third caller, the linear
timeouts of thin streams in tcp_retransmit_timer(), already clamps the
result to tcp_rto_min().
Found by code inspection (Eric Dumazet), not reproduced. Fixed by LLM,
and tested with existing kernel selftests.
Fixes: 05bb1fad1c ("[TCP]: Allow minimum RTO to be configurable via routing metrics.")
Suggested-by: Eric Dumazet <[email protected]>
Signed-off-by: Chris Mason <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Paolo Abeni <[email protected]>
This commit is contained in:
+3
-1
@@ -910,7 +910,9 @@ static inline void tcp_bound_rto(struct sock *sk)
|
||||
|
||||
static inline u32 __tcp_set_rto(const struct tcp_sock *tp)
|
||||
{
|
||||
return usecs_to_jiffies((tp->srtt_us >> 3) + tp->rttvar_us);
|
||||
u32 rto = usecs_to_jiffies((tp->srtt_us >> 3) + tp->rttvar_us);
|
||||
|
||||
return max(rto, 1U);
|
||||
}
|
||||
|
||||
static inline unsigned long tcp_reqsk_timeout(struct request_sock *req)
|
||||
|
||||
@@ -1221,8 +1221,9 @@ void tcp_set_rto(struct sock *sk)
|
||||
* with correct one. It is exactly, which we pretend to do.
|
||||
*/
|
||||
|
||||
/* NOTE: clamping at TCP_RTO_MIN is not required, current algo
|
||||
* guarantees that rto is higher.
|
||||
/* NOTE: clamping at tcp_rto_min() is not required, tcp_rtt_estimator()
|
||||
* applies it to rttvar_us. But rto must never be 0, which exponential
|
||||
* backoff could not leave: __tcp_set_rto() takes care of that.
|
||||
*/
|
||||
tcp_bound_rto(sk);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user