tcp: correct timestamp echo for accepted old ACKs
Subsystems (4)
v2 cover tcp: correct timestamp echo for accepted old ACKs
Linux can acknowledge newly received data while echoing an outdated TCP timestamp. This happens when a reordered packet fills a receive gap but carries an older acknowledgment for traffic in the other direction. If the sender uses this echo to measure round-trip time after a long idle period, the stale timestamp can inflate its estimate and slow its sending.
Changes in v2, following Eric Dumazet's review:
- Remove the redundant SYN_RECV condition and unused flag accumulation.
- Replace the log-parsing wrapper with a plain packetdrill test that checks the timestamp echo directly, using the existing selftest runner.
- Rebase on net fc6d80eb5044.
v1: https://lore.kernel.org/netdev/[email protected]/
In this example, S sends the reordered data and R is the Linux receiver being patched. All packets shown belong to the same TCP connection, with overlapping requests in both directions. Each illustrated request fits in one TCP packet; request/response names describe application messages, while ACK numbers acknowledge TCP bytes. The numbers are
illustrative: TS and echo use S's millisecond clock, and byte numbers are relative to the first post-idle byte in each direction. ACK=N acknowledges bytes before N.
Before idle:
S -> R: sender request 1, TS=999
R -> S: response to sender request 1, echo=999
S -> R: TCP ACK, TS=1000 (R saves timestamp 1000)
... 300 seconds idle ...After idle (byte ranges include both ends):
S -> R: sender request 2, bytes 1-17, ACK=1, TS=301000
(delayed in the network)
R -> S: receiver request 1, bytes 1-17, ACK=1
(initiated by R while sender request 2 is still in flight)
S -> R: sender request 3, bytes 18-34, ACK=18, TS=301005
(arrives before sender request 2)
R -> S: TCP ACK=1, SACK for sender request 3, echo=1000
S -> R: original sender request 2 arrives, still ACK=1, TS=301000
R -> S: TCP ACK=35, echo=1000 (bug) or echo=301000 (fixed)R initiates receiver request 1 while sender request 2 is still in flight; its ACK=1 means it has not received sender request 2. S receives R's request before sending sender request 3, so that packet carries ACK=18. Sender request 3 reaches R first, making sender request 2's ACK=1 old. The earlier ACK with SACK correctly echoes 1000 while the gap is open. The bug is retaining 1000 in ACK=35 after the gap closes, instead of echoing sender request 2's timestamp, 301000.
If S falls back to timestamp-based RTT measurement for ACK=35, subtracting echo=1000 from its current timestamp (about 301000) produces a roughly 300-second RTT sample, mistakenly counting the idle period. The inflated smoothed RTT lowers the sender's calculated pacing rate and, when pacing is enforced, unnecessarily delays outgoing packets and slows the transfer.
Patch 1 refreshes the saved timestamp while preserving existing validation. Patch 2 checks that the ACK closing the receive gap echoes timestamp 301000, in IPv4, IPv6 and IPv4-mapped IPv6. It requires packetdrill's merged TSecr verification fix, commit 83f72d3f9085, linked below. Once CI uses a packetdrill version containing that fix, the timestamp assertion will reject the stale echo on an unfixed kernel and pass with this kernel fix. Older packetdrill versions ignore the comparison and incorrectly pass both.
https://github.com/google/packetdrill/commit/83f72d3f9085d0e26eb4d206fe4d7cfab5b6d872
V1 passed 68 focused/control cases on normal and KASAN/UBSAN/lockdep ARM64 kernels, with no new diagnostics from W=1 allyesconfig/allmodconfig builds or Sparse. V2 passed the same checks with equivalent results.
Earlier C-socket repro on net 46bc52d13594: after 300 seconds idle, with controlled reordering, retransmission and fq pacing, a 1 MiB transfer takes 22.02 seconds without the fix versus 0.38 seconds with it (one run per arm).
AI assistance: Codex generated and revised the fix, reproducers, selftest, analysis and patch messages. The user directed the investigation, asked for real-socket and upstream-kernel comparisons, and requested broader testing. A separate Codex reviewer challenged the v1 code and evidence. Sparse supplied static analysis.
Jeff Jo (2):
tcp: refresh TS.Recent for accepted old ACKs
selftests: net: check timestamp echo after an old ACK
net/ipv4/tcp_input.c | 6 +++++ .../net/packetdrill/tcp_old_ack_ts.pkt | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tools/testing/selftests/net/packetdrill/tcp_old_ack_ts.pkt
base-commit: fc6d80eb504458d6416b75a94188b268c95c6533
Signature · 1 line
2.55.0
PATCH v2 1/2 tcp: refresh TS.Recent for accepted old ACKs
A TCP packet can carry new data while acknowledging traffic in the opposite direction. With overlapping traffic in both directions, a delayed packet's acknowledgment can be older than one Linux has already accepted, even when that packet fills a gap in the received data.
Linux accepts the data, but tcp_ack() takes the old_ack path and skips updating TS.Recent, the timestamp saved for outgoing acknowledgments. The reply therefore echoes an older timestamp. If the sender uses this echo to measure round-trip time after a long idle period, its estimate includes the idle time and can reduce its sending rate.
Update TS.Recent in old_ack using tcp_replace_ts_recent(), before SACK processing can trigger a transmission. This reuses the existing timestamp and sequence checks, including PAWS protection against old duplicate packets. ACK validation already rejects old ACKs in SYN_RECV before this path, so no additional state check is needed.
Echoing the timestamp of the packet that fills the receive gap follows RFC 7323 section 4.3. In a socket reproduction with 300 seconds idle, controlled reordering and retransmission to exercise timestamp-based RTT sampling, the sender's smoothed round-trip time was 37.5 seconds without the fix and 15.5 ms with it.
--- net/ipv4/tcp_input.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/ipv4/tcp_input.c +6 -0
@@ -4465,6 +4465,12 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)return 1 ; old_ack: +/* An old ACK can carry new data. Update TS.Recent before SACK +* processing can trigger a retransmission. +*/ +if (flag &FLAG_UPDATE_TS_RECENT ) +tcp_replace_ts_recent (tp,TCP_SKB_CB (skb)->seq); +/* If data was SACKed, tag it and see if we should send more data. * If data was DSACKed, see if we can undo a cwnd reduction. */
Signature · 1 line
2.55.0
Re: [PATCH net v2 1/2] tcp: refresh TS.Recent for accepted old ACKs
Quoted 36 lines · Jeff Jo
A TCP packet can carry new data while acknowledging traffic in the opposite direction. With overlapping traffic in both directions, a delayed packet's acknowledgment can be older than one Linux has already accepted, even when that packet fills a gap in the received data.
Linux accepts the data, but
tcp_ack()takes theold_ackpath and skips updating TS.Recent, the timestamp saved for outgoing acknowledgments. The reply therefore echoes an older timestamp. If the sender uses this echo to measure round-trip time after a long idle period, its estimate includes the idle time and can reduce its sending rate.Update TS.Recent in
old_ackusingtcp_replace_ts_recent(), before SACK processing can trigger a transmission. This reuses the existing timestamp and sequence checks, including PAWS protection against old duplicate packets. ACK validation already rejects old ACKs inSYN_RECVbefore this path, so no additional state check is needed.Echoing the timestamp of the packet that fills the receive gap follows RFC 7323 section 4.3. In a socket reproduction with 300 seconds idle, controlled reordering and retransmission to exercise timestamp-based RTT sampling, the sender's smoothed round-trip time was 37.5 seconds without the fix and 15.5 ms with it.
Fixes 12fb3dd9dc3c ("tcp: call tcp_replace_ts_recent() from tcp_ack()")Assisted-by LLM sparseSigned-off-by Jeff Jo <[email protected]>--- net/ipv4/tcp_input.c | 6 ++++++ 1 file changed, 6 insertions(+)net/ipv4/tcp_input.c +0
-0
net/ipv4/tcp_input.c static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) · line 4473
Quoted 9 lines
net/ipv4/tcp_input.c +6
-0@@ -4465,6 +4465,12 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)return 1 ; old_ack: +/* An old ACK can carry new data. Update TS.Recent before SACK +* processing can trigger a retransmission. +*/ +if (flag &FLAG_UPDATE_TS_RECENT ) +tcp_replace_ts_recent (tp,TCP_SKB_CB (skb)->seq); +
PATCH v2 2/2 selftests: net: check timestamp echo after an old ACK
In reply to Jeff JoAdd a regression test for a gap-filling packet whose acknowledgment has become old. Linux first sends data to the peer. Deliver two peer data packets out of order: the later packet acknowledges Linux's data, while the delayed packet still carries the earlier acknowledgment.
Require the ACK that closes the receive gap to echo the delayed packet's timestamp, 301000. Without the fix, Linux accepts the data but still echoes the previously saved timestamp, 1000. Also check that the application can read all 34 bytes.
Use a large jump in peer timestamps to represent the idle interval, with no real wait, loss or retransmission. The test directly checks the outgoing timestamp echo. It requires packetdrill's merged TSecr verification fix (linked below); older tools incorrectly pass on an unfixed kernel.
Use the existing packetdrill selftest runner for IPv4, IPv6 and IPv4-mapped IPv6.
--- .../net/packetdrill/tcp_old_ack_ts.pkt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tools/testing/selftests/net/packetdrill/tcp_old_ack_ts.pkt
tools/testing/selftests/net/packetdrill/tcp_old_ack_ts.pkt new file +22 -0
@@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0 +// An out-of-order segment advances SND.UNA. The gap filler still carries +// its original, older ACK. The reply must echo the gap filler's timestamp. +--tcp_ts_tick_usecs=1000 + +`./defaults.sh` + +0.000 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 ++0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 ++0 bind(3, ..., ...) = 0 ++0 listen(3, 1) = 0 +0.100 < S 0:0(0) win 20000 <mss 1000,sackOK,TS val 900 ecr 0> ++0 > S. 0:0(0) ack 1 <mss 1460,sackOK,TS val 100 ecr 900> +0.200 < . 1:1(0) ack 1 win 20000 <nop,nop,TS val 1000 ecr 100> ++0 accept(3, ..., ...) = 4 +0.300 write(4, ..., 17) = 17 ++0 > P. 1:18(17) ack 1 <nop,nop,TS val 300 ecr 1000> +0.310 < P. 18:35(17) ack 18 win 20000 <nop,nop,TS val 301001 ecr 300> ++0 > . 18:18(0) ack 1 <nop,nop,TS val 310 ecr 1000,nop,nop,sack 18:35> +0.320 < P. 1:18(17) ack 1 win 20000 <nop,nop,TS val 301000 ecr 100> ++0 > . 18:18(0) ack 35 <nop,nop,TS val 320 ecr 301000> ++0 read(4, ..., 34) = 34
Signature · 1 line
2.55.0
Re: [PATCH net v2 2/2] selftests: net: check timestamp echo after an old ACK
Quoted 16 lines · Jeff Jo
Add a regression test for a gap-filling packet whose acknowledgment has become old. Linux first sends data to the peer. Deliver two peer data packets out of order: the later packet acknowledges Linux's data, while the delayed packet still carries the earlier acknowledgment.
Require the ACK that closes the receive gap to echo the delayed packet's timestamp, 301000. Without the fix, Linux accepts the data but still echoes the previously saved timestamp, 1000. Also check that the application can read all 34 bytes.
Use a large jump in peer timestamps to represent the idle interval, with no real wait, loss or retransmission. The test directly checks the outgoing timestamp echo. It requires packetdrill's merged TSecr verification fix (linked below); older tools incorrectly pass on an unfixed kernel.
Quoted 6 lines
Use the existing packetdrill selftest runner for IPv4, IPv6 and IPv4-mapped IPv6.
Assisted-by LLMSigned-off-by Jeff Jo <[email protected]>
Thanks!
[email protected]
AI reviewRe: [PATCH net v2 2/2] selftests: net: check timestamp echo after an old ACK
In reply to Jeff JoThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The new selftest tools/testing/selftests/net/packetdrill/tcp_old_ack_ts.pkt checks for…
--
selftests: net: check timestamp echo after an old ACK
This adds a packetdrill regression test for a gap-filling segment that carries an old ACK. Two peer data segments arrive out of order. The test then requires the ACK that closes the gap to echo the delayed segment's timestamp (301000) and not the stale saved value (1000).
Quoted 6 lines
tools/testing/selftests/net/packetdrill/tcp_old_ack_ts.pkt new file +0
-0@@ -0,0 +1,22 @@
[ ... ]
Quoted 6 lines
+0.300
write(4, ..., 17)= 17
++0 > P. 1:18(17) ack 1 <nop,nop,TS val 300 ecr 1000>
+0.310 < P. 18:35(17) ack 18 win 20000 <nop,nop,TS val 301001 ecr 300> ++0 > . 18:18(0) ack 1 <nop,nop,TS val 310 ecr 1000,nop,nop,sack 18:35> +0.320 < P. 1:18(17) ack 1 win 20000 <nop,nop,TS val 301000 ecr 100> ++0 > . 18:18(0) ack 35 <nop,nop,TS val 320 ecr 301000>
^^^^^^^^^^^
[Severity: Medium]
Can this test report PASS on a kernel that doesn't have the fix?
The commit message says packetdrill versions older than 83f72d3f9085 do not check the outgoing TSecr:
older tools incorrectly pass on an unfixed kernel
This ecr 301000 check is the only line in the script that depends on the fix. The seq, ack and SACK checks give the same result with or without it, and so does the read() of 34 bytes below.
The runner only checks that some packetdrill is in PATH. It then reports PASS whenever packetdrill exits 0:
tools/testing/selftests/net/packetdrill/ksft_runner.sh:
if [ -z "$(which packetdrill)" ]; then
ktap_skip_all "packetdrill not found in PATH"
exit "$KSFT_SKIP"
fi
...
unshare -n packetdrill ${ip_args[$ip_version]} ${optargs[@]} $script > /dev/null \
&& ktap_test_pass $ip_version || $failfunc $ip_versionOn a kernel without the fix, tcp_ack() sends the gap filler down the old_ack path, since ack 1 is before snd_una 18. That kernel does not have this update:
net/ipv4/tcp_input.c:tcp_ack() {
...
old_ack:
...
if (flag & FLAG_UPDATE_TS_RECENT)
tcp_replace_ts_recent(tp, TCP_SKB_CB(skb)->seq);
...
}As a result, ts_recent stays at 1000. With an older packetdrill, such as a distro package, wouldn't ipv4, ipv6 and ipv4-mapped-ipv6 all still pass?
Could the script add a check that doesn't rely on packetdrill's TSecr handling? For example, after the gap-closing ACK, inject:
< P. 35:36(1) ack 18 win 20000 <nop,nop,TS val 2000 ecr 320>
With the fix, ts_recent is 301000, so the PAWS check in tcp_validate_incoming() drops the segment. The segment carries data, so tcp_oow_rate_limited() does not suppress the dup-ACK, and the reply is ack 35.
Without the fix, ts_recent is 1000. The segment is accepted and the reply is ack 36. That difference would show up whichever packetdrill version is used.
Quoted 1 line
++0
read(4, ..., 34)= 34
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260924224456.55690-4-jeffjo%40openai.com
Re: [PATCH net v2 2/2] selftests: net: check timestamp echo after an old ACK
Quoted 92 lines · On Fri, Sep 25, 2026 at 10:47:14PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The new selftest
tools/testing/selftests/net/packetdrill/tcp_old_ack_ts.pktchecks for...--
selftests: net: check timestamp echo after an old ACK
This adds a packetdrill regression test for a gap-filling segment that carries an old ACK. Two peer data segments arrive out of order. The test then requires the ACK that closes the gap to echo the delayed segment's timestamp (301000) and not the stale saved value (1000).
Quoted 6 lines
tools/testing/selftests/net/packetdrill/tcp_old_ack_ts.pkt new file +0
-0@@ -0,0 +1,22 @@[ ... ]
Quoted 6 lines
+0.300
write(4, ..., 17)= 17
++0 > P. 1:18(17) ack 1 <nop,nop,TS val 300 ecr 1000>
+0.310 < P. 18:35(17) ack 18 win 20000 <nop,nop,TS val 301001 ecr 300> ++0 > . 18:18(0) ack 1 <nop,nop,TS val 310 ecr 1000,nop,nop,sack 18:35> +0.320 < P. 1:18(17) ack 1 win 20000 <nop,nop,TS val 301000 ecr 100> ++0 > . 18:18(0) ack 35 <nop,nop,TS val 320 ecr 301000>^^^^^^^^^^^[Severity: Medium]
Can this test report PASS on a kernel that doesn't have the fix?The commit message says packetdrill versions older than
83f72d3f9085do not check the outgoing TSecr:older tools incorrectly pass on an unfixed kernel
This ecr 301000 check is the only line in the script that depends on the fix. The seq, ack and SACK checks give the same result with or without it, and so does the
read()of 34 bytes below.The runner only checks that some packetdrill is in PATH. It then reports PASS whenever packetdrill exits 0:
tools/testing/selftests/net/packetdrill/ksft_runner.sh:if [ -z "$(which packetdrill)" ]; then ktap_skip_all "packetdrill not found in PATH" exit "$KSFT_SKIP" fi ... unshare -n packetdrill ${ip_args[$ip_version]} ${optargs[@]} $script > /dev/null \ && ktap_test_pass $ip_version || $failfunc $ip_versionOn a kernel without the fix,
tcp_ack()sends the gap filler down theold_ackpath, since ack 1 is beforesnd_una18. That kernel does not have this update:net/ipv4/tcp_input.c:tcp_ack() { ... old_ack: ... if (flag & FLAG_UPDATE_TS_RECENT) tcp_replace_ts_recent(tp, TCP_SKB_CB(skb)->seq); ... }As a result,
ts_recentstays at 1000. With an older packetdrill, such as a distro package, wouldn't ipv4, ipv6 and ipv4-mapped-ipv6 all still pass?Could the script add a check that doesn't rely on packetdrill's TSecr handling? For example, after the gap-closing ACK, inject:
< P. 35:36(1) ack 18 win 20000 <nop,nop,TS val 2000 ecr 320>
With the fix,
ts_recentis 301000, so the PAWS check intcp_validate_incoming()drops the segment. The segment carries data, sotcp_oow_rate_limited()does not suppress the dup-ACK, and the reply is ack 35.
Quoted 8 lines
Without the fix,
ts_recentis 1000. The segment is accepted and the reply is ack 36. That difference would show up whichever packetdrill version is used.Quoted 1 line
++0
read(4, ..., 34)= 34Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260924224456.55690-4-jeffjo%40openai.com
Yes, affected older packetdrill versions can falsely pass this test, as noted in the commit message.
We previously tested a PAWS-based assertion, but Eric requested a direct timestamp-echo check once packetdrill was fixed and the runners updated [1]. Neal has since merged the packetdrill fix [2] and requested the revised test.
With updated packetdrill, we verified that this test fails on the unfixed kernel and passes with the kernel fix. V2 follows that approach and documents the required packetdrill commit.
[1] https://lore.kernel.org/netdev/CANn89i+nY499TfuGMvMq3P=Pxw6vBxe+uYH1zioK=bhU--GXYw@mail.gmail.com/
[2] https://github.com/google/packetdrill/commit/83f72d3f9085d0e26eb4d206fe4d7cfab5b6d872
This series was applied to netdev/net.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:
Quoted 6 lines · On Thu, 24 Sep 2026 15:44:57 -0700 you wrote:
Linux can acknowledge newly received data while echoing an outdated TCP timestamp. This happens when a reordered packet fills a receive gap but carries an older acknowledgment for traffic in the other direction. If the sender uses this echo to measure round-trip time after a long idle period, the stale timestamp can inflate its estimate and slow its sending.
Quoted 7 lines
Changes in v2, following Eric Dumazet's review:
- Remove the redundantSYN_RECVcondition and unused flag accumulation.
- Replace the log-parsing wrapper with a plain packetdrill test that checks the timestamp echo directly, using the existing selftest runner.
- Rebase on netfc6d80eb5044.[...]
Here is the summary with links:
- [net,v2,1/2] tcp: refresh TS.Recent for accepted old ACKs
https://git.kernel.org/netdev/net/c/1b92780ae4fc - [net,v2,2/2] selftests: net: check timestamp echo after an old ACK https://git.kernel.org/netdev/net/c/81fe707ae58e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html