Repository navigation
fix: fix overflow in tcp.sender.sendData() for 32-bit architectures. - #3
Conversation
Fixes gvisor#11632 PiperOrigin-RevId: 747977713
|
One thing to say is that the Linux implementation of CUBIC does reset the start of the congestion avoidance when the TCP connection comes back from being idle: |
spikecurtis
left a comment
There was a problem hiding this comment.
This fixes one problem due to the overflow, but if the cubic congestion overflows and sets SndCwnd to a negative number, there will likely be other things that go awry.
We should handle it at the source and ensure the SndCwnd is never negative by clamping it to [0, math.MaxInt]. It might even be safer to clamp it to some big value that you'll never actually need, but we know fits in integer arithmetic. That should ensure we don't see any further bugs like this coming out of the woodwork.
Max TCP throughput goes like Window / Latency. So, if we made the max SndCwnd = 1 billion (segments), that's like 1TB window in bytes. Even with a very long round-trip like a second, that's 1TB/s throughput, which you're just never going to get.
I figured I can just reset
coder-mainto the commit we're tracking in upstream gvisor at the moment but I wanted to make sure I'm not deleting anything we'd want to keep the history on. Given that, this PR merges into new a branch that points to the upstream commit that we're currently tracking in gvisor and cherry-picks the commit that fixes the overflow issue.Bug repro:
gvisor.dev/gvisor/pkg/tcpip/transport/tcp.(*sender).splitSeg(0xc01bc86008, 0xc03d0ac800, 0xfe32de9401bff440)splitSeghas the following signature:func (s *sender) splitSeg(seg *segment, size int) {which means that
0xfe32de9401bff440should be evaluated as an int (-129796711974439872), which is evidence that it overflowed.splitSegis called frommaybeSendSegmentand is passed local variableavailableavailableis optionally set tolimitif it exceeds it, so iflimitis negativeavailablebecomes negative.limitbecome negative?The congestion window controls how many bytes we can have in flight. Every time we receive an ACK, CUBIC's
getCwnd(cubic.go:215) grows the window using:where
wtRtt = 0.4 * t³ + 30(cubic.go:210) andtis the elapsed time since the CUBIC epoch start (c.T).c.Tis set once when entering congestion avoidance (cubic.go:102) and is only reset by loss events (HandleLossDetectedatcubic.go:253,HandleRTOExpiredatcubic.go:264). Assuming no loss or retransmission timeout, this meanstgrows unbounded.Normally the per-ACK increment
(wtRtt - cwnd) / cwndwould growcwndgradually, making the division flatten the curve. However, if a connection has no data segments flowing for longer than RTO, the idle check resetsSndCwndback to its initial value of 10 (snd.go:1015). RTO isSRTT + 4×RTTVarclamped to[200ms, 120s](snd.go:33-36,420-426) — for Tailscale's virtual network with ~2ms RTT, RTO floors at 200ms. Note: TCP keepalives (sendEmptySegmentatconnect.go:1325) keep the connection alive during idle periods but bypasssendDataentirely and don't triggercc.Update, so they don't prevent the idle reset from firing on the next real data write.Critically, the idle reset does NOT reset
c.T. So after the reset, the next ACK computes(0.4 × days³ - 10) / 10 ≈ 0.4 × days³ / 10in a single step, catapultingSndCwndto:After a sufficiently long persistent connection (~7 days) and a period of inactivity that resets
SndCwnd, the next time we try to send a packet we overflow (snd.go:1021):This limit is eventually reassigned to
available(snd.go:895) and then our call on (snd.go:908) triggers a panic when checking the length (snd.go:639).