ACK of a zero-window probe echoes a stale timestamp
Description
Hello, a small bug (strictly verified by me personally with real test custom VPN environment):
TS.Recent is not updated for a zero-window probe, so every ACK sent while the receive window is zero echoes the TSval of the last data segment accepted before the window closed, not the probe's (RFC 7323 §4.3, rule 2).
receiver.handleRcvdSegment (pkg/tcpip/transport/tcp/rcv.go) answers a segment that fails acceptable() through maybeSendOutOfWindowAck and returns before sender.handleRcvdSegment, the only place updateRecentTimestamp is called. A window probe (one byte at RCV.NXT, or an empty segment at RCV.NXT-1) always fails acceptable() at `RCV.WND = 0.
RFC 7323 §4.3 rule (2) asks for the update. FreeBSD does it for a one-byte probe at RCV.NXT and echoes the probe's TSval. The EmptyAtRcvNxtMinusOne subtest follows the RFC literally: neither Linux nor FreeBSD updates ts_recent for an empty segment below RCV.NXT, so that subtest can be dropped if kernel parity is preferred.
I find it in my custom VPN solution when testing a FreeBSD sender that dropped a connection to a paused receiver behind gVisor. The drop itself had another cause (FreeBSD does not read the TSecr of a duplicate ACK); the stale echo is wrong in its own right.
Suggested fix:
--- a/pkg/tcpip/transport/tcp/rcv.go
+++ b/pkg/tcpip/transport/tcp/rcv.go
@@ func (r *receiver) handleRcvdSegment(s *segment) (drop bool, err tcpip.Error) {
if !r.acceptable(segSeq, segLen) {
+ // RFC 7323 section 4.3 rule (2): a segment with SEG.SEQ <=
+ // Last.ACK.sent updates TS.Recent even when not acceptable.
+ if r.ep.SendTSOk && s.parsedOptions.TS {
+ r.ep.updateRecentTimestamp(s.parsedOptions.TSVal, r.ep.snd.MaxSentAck, segSeq)
+ }
r.ep.snd.maybeSendOutOfWindowAck(s)
return true, nil
}updateRecentTimestamp already enforces both conditions. The same lines fit handleRcvdSegmentClosing. Verified with a test that drives a stack.Stack through a channel.Endpoint.
Steps to reproduce
For reproduce need any FreeBSD sender or reproducer with small test.
A connection with timestamps, the application not reading, the peer filling the window, then a one-byte segment at RCV.NXT with a new TSval: the ACK's TSecr is the previous data segment's TSval.
Reproducer:
Two subtests, each on a fresh connection with timestamps negotiated and an application that never reads:
- a 4096-byte segment with TSval 100 fills the window; the ACK must carry window 0 and TSecr 100;
- a probe with TSval 200 -- one byte at RCV.NXT, or empty at RCV.NXT-1; the ACK must carry window 0 and TSecr 200 (RFC 7323 section 4.3, rule 2).
The receive buffer is 4096 bytes (the endpoint doubles it), not the tiny one TestFullWindowReceive uses: with a 20-byte buffer the segment overhead alone exceeds the buffer, segmentQueue.enqueue drops the one-byte probe before the receiver sees it, and no ACK is sent at all -- a different path, not this bug:
--- a/pkg/tcpip/transport/tcp/rcv.go
+++ b/pkg/tcpip/transport/tcp/rcv.go
@@ func (r *receiver) handleRcvdSegmentClosing(s *segment, state EndpointState, clo
// fails, we ignore the packet:
// https://github.com/torvalds/linux/blob/v5.8/net/ipv4/tcp_input.c#L5591
if r.ep.snd.SndNxt.LessThan(s.ackNumber) {
+ // RFC 7323 section 4.3 rule (2), as in handleRcvdSegment.
+ if r.ep.SendTSOk && s.parsedOptions.TS {
+ r.ep.updateRecentTimestamp(s.parsedOptions.TSVal, r.ep.snd.MaxSentAck, s.sequenceNumber)
+ }
r.ep.snd.maybeSendOutOfWindowAck(s)
return true, nil
}Code and patches attached as tcp_timestamp_test.tar.gz
Bazel:
bazel test //pkg/tcpip/transport/tcp/test/e2e:tcp_timestamp_test \
--test_filter=TestTimeStampZeroWindowProbePlain:
With plain go test (how it was run here): the go branch strips tests, and in test/e2e every test file is its own package, so copy from master into a go branch checkout: pkg/tcpip/checker, pkg/tcpip/testutil, pkg/tcpip/transport/tcp/testing/context, test/e2e/e2e.go, and put tcp_timestamp_test.go in a directory of its own (test/e2e/tcp_timestamp/). Then run:
go test ./pkg/tcpip/transport/tcp/test/e2e/tcp_timestamp/ -run TestTimeStampZeroWindowProbe -count=1Before the fix (fails):
--- FAIL: TestTimeStampZeroWindowProbe (0.00s)
--- FAIL: TestTimeStampZeroWindowProbe/OneByteAtRcvNxt (0.00s)
tcp_timestamp_test.go:379: Timestamp Echo Reply is incorrect, got = 100, want = 200
--- FAIL: TestTimeStampZeroWindowProbe/EmptyAtRcvNxtMinusOne (0.00s)
tcp_timestamp_test.go:379: Timestamp Echo Reply is incorrect, got = 100, want = 200
FAILSniffer excerpt (one-byte case):
recv ... len:4096 flags: A seqnum:790 ... options:{TS:true TSVal:100 ...}
send ... len:0 flags: A ack:4886 win:0 options:{TS:true ... TSEcr:100}
recv ... len:1 flags: A seqnum:4886 ... options:{TS:true TSVal:200 ...}
send ... len:0 flags: A ack:4886 win:0 options:{TS:true ... TSEcr:100} <- want 200After the fix (passes):
=== RUN TestTimeStampZeroWindowProbe
=== RUN TestTimeStampZeroWindowProbe/OneByteAtRcvNxt
=== RUN TestTimeStampZeroWindowProbe/EmptyAtRcvNxtMinusOne
--- PASS: TestTimeStampZeroWindowProbe (0.00s)
--- PASS: TestTimeStampZeroWindowProbe/OneByteAtRcvNxt (0.00s)
--- PASS: TestTimeStampZeroWindowProbe/EmptyAtRcvNxtMinusOne (0.00s)
PASSWith the fix applied, the other TCP e2e suites from master also pass under
go test: tcp (tcp_test, mark_test, tcp_migration_test), rcv, sack, rack,
acktiming, noracedetector, forwarder, dual_stack.
Notes for the PR:
- The fix's second hunk (
handleRcvdSegmentClosing, an ACK beyond SND.NXT in a closing state) is not covered by this test; only theacceptable()branch is.
Expected result:
The probe's ACK echoes the probe's TSval.
Actual result:
It echoes the TSval of the last accepted data segment, for every probe until the window opens.
Affected versions:
Reproduced with gvisor.dev/gvisor v0.0.0-20260921164205-6b569e77c779 and with the go branch at v0.0.0-20260925204757-f6e2c02e9739, Linux amd64 (test); FreeBSD 15 sender (field), Go 1.27.1.
runsc version
Not applicable: gVisor's netstack used as a Go library (pkg/tcpip), no runscdocker version (if using docker)
uname
FreeBSD evpn-freebsd 15.0-RELEASE-p12 FreeBSD 15.0-RELEASE-p12 releng/15.0-n281099-7b527b9b97ba GENERIC amd64
kubectl (if using Kubernetes)
repo state (if built from source)
No response
runsc debug logs (if available)
Source: google/gvisor