tcp: fix icsk_ack.ato bitfield overflow
Subsystems (3)
PATCH 1/1 tcp: fix icsk_ack.ato bitfield overflow
On cross-region connections we observed delayed ACKs suddenly turning into immediate ACKs plus a TCP_MAX_QUICKACKS burst, as if the connection had just received its first data segment.
Commit 95b9a87c6a6b ("tcp: record last received ipv6 flowlabel") squeezed icsk_ack.ato into 8 bits, sized for TCP_DELACK_MAX. But both writers still bound ato by icsk_rto, which can be well above 255 jiffies, so the bitfield assignment silently wraps mod 256: repeated delack timer misses double ato up to icsk_rto, storing 320 as 64 and 256 as 0, and ato == 0 is the "first data packet" sentinel in tcp_event_data_recv().
Clamp both writers to TCP_DELACK_MAX, which the static_assert already guarantees to fit and tcp_send_delayed_ack() effectively caps ato at anyway.
--- net/ipv4/tcp_input.c | 6 +++--- net/ipv4/tcp_timer.c | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-)
net/ipv4/tcp_input.c +3 -3
@@ -1039,9 +1039,9 @@ static void tcp_event_data_recv(struct sock *sk, struct sk_buff *skb)/* The fastest case is the first. */ icsk->icsk_ack.ato = (icsk->icsk_ack.ato >>1 ) +TCP_ATO_MIN /2 ; }else if (m < icsk->icsk_ack.ato) { - icsk->icsk_ack.ato = (icsk->icsk_ack.ato >>1 ) + m; -if (icsk->icsk_ack.ato > icsk->icsk_rto) - icsk->icsk_ack.ato = icsk->icsk_rto; + icsk->icsk_ack.ato =min3 ((icsk->icsk_ack.ato >>1 ) + (u32 )m, + icsk->icsk_rto, + (u32 )TCP_DELACK_MAX ); }else if (m > icsk->icsk_rto) {/* Too long gap. Apparently sender failed to * restart window, so that we send ACKs quickly.
net/ipv4/tcp_timer.c +3 -1
@@ -334,7 +334,9 @@ void tcp_delack_timer_handler(struct sock *sk)if (inet_csk_ack_scheduled (sk)) {if (!inet_csk_in_pingpong_mode (sk)) {/* Delayed ACK missed: inflate ATO. */ - icsk->icsk_ack.ato =min_t (u32, icsk->icsk_ack.ato <<1 , icsk->icsk_rto); + icsk->icsk_ack.ato =min3 ((u32 )icsk->icsk_ack.ato <<1 , + icsk->icsk_rto, + (u32 )TCP_DELACK_MAX ); }else {/* Delayed ACK missed: leave pingpong mode and * deflate ATO.
Signature · 1 line
2.43.0
Quoted 13 lines · Jiayuan Chen
On cross-region connections we observed delayed ACKs suddenly turning into immediate ACKs plus a
TCP_MAX_QUICKACKSburst, as if the connection had just received its first data segment.Commit
95b9a87c6a6b("tcp: record last received ipv6 flowlabel") squeezed icsk_ack.ato into 8 bits, sized forTCP_DELACK_MAX. But both writers still bound ato byicsk_rto, which can be well above 255 jiffies, so the bitfield assignment silently wraps mod 256: repeated delack timer misses double ato up toicsk_rto, storing 320 as 64 and 256 as 0, and ato == 0 is the "first data packet" sentinel intcp_event_data_recv().
Quoted 6 lines
Clamp both writers to
TCP_DELACK_MAX, which thestatic_assertalready guarantees to fit andtcp_send_delayed_ack()effectively caps ato at anyway.Fixes 95b9a87c6a6b ("tcp: record last received ipv6 flowlabel")Signed-off-by Jiayuan Chen <[email protected]>
Thanks for the fix!
neal
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 12 lines · On Fri, 7 Aug 2026 09:44:36 +0800 you wrote:
On cross-region connections we observed delayed ACKs suddenly turning into immediate ACKs plus a
TCP_MAX_QUICKACKSburst, as if the connection had just received its first data segment.Commit
95b9a87c6a6b("tcp: record last received ipv6 flowlabel") squeezed icsk_ack.ato into 8 bits, sized forTCP_DELACK_MAX. But both writers still bound ato byicsk_rto, which can be well above 255 jiffies, so the bitfield assignment silently wraps mod 256: repeated delack timer misses double ato up toicsk_rto, storing 320 as 64 and 256 as 0, and ato == 0 is the "first data packet" sentinel intcp_event_data_recv().
Quoted 1 line
[...]
Here is the summary with links:
- [net] tcp: fix icsk_ack.ato bitfield overflow
https://git.kernel.org/netdev/net/c/60837e4b840a
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html