Skip to content

tun: segment GSO packets that arrive without checksum offsets - #129

Merged
illotum merged 1 commit into
tailscale:tailscalefrom
SLoeuillet:sloeuillet/sre-2492-gso-missing-csum-start
Nov 25, 2026
Merged

illotum merged 1 commit into
tailscale:tailscalefrom
SLoeuillet:sloeuillet/sre-2492-gso-missing-csum-start

Conversation

@SLoeuillet

@SLoeuillet SLoeuillet commented Nov 10, 2026 •

Copy link
Copy Markdown

Updates tailscale/tailscale#22298

With hardware GRO on the receiving NIC, a forwarded GSO packet is CHECKSUM_UNNECESSARY, so the kernel hands it to the TUN device without VIRTIO_NET_HDR_F_NEEDS_CSUM and with csum_start/csum_offset = 0. handleVirtioRead then reads the TCP data offset from the IPv4 source address (tcp header len is invalid: 0 for 10/8), and RoutineReadFromTUN closes the device on that error. gve (Google Cloud gVNIC) enables hardware GRO by default since Linux 7.1, also backported to Ubuntu linux-gcp 7.0.0-1017, so a subnet router on such a VM loses its tunnel seconds after starting. The gve fix (netdev/net bda3c8381653, queued for 7.4 and stable) marks these packets CHECKSUM_PARTIAL.

When CsumStart is 0 on a GSO packet, take CsumStart/CsumOffset from the packet's own IP header (protocol checked against the GSO type). GSOSplit already recomputes every segment's checksums. A packet the fixup cannot handle (e.g. IPv6 extension headers) is dropped instead of closing the device.

Tests: new handleVirtioRead cases, which fail without the change (the TCP ones with the exact production error); go test ./... passes on Linux. On a GCE router (linux-gcp 7.0.0-1017), tailscale v1.104.7 with this commit vs stock, rx-gro-hw toggled on 6 times under load: 0/6 crashes vs 6/6.

@SLoeuillet

Copy link
Copy Markdown
Author

@jwhited could you take a look please ?

@nbeirne
nbeirne requested review from a team, illotum and nbeirne November 17, 2026 19:36
@nbeirne

nbeirne commented Nov 17, 2026

Copy link
Copy Markdown

I am going to look at this either today or tomorrow. Thanks for the PR!

@sfllaw
sfllaw requested a review from jwhited November 17, 2026 19:48

@illotum illotum left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the submission! We try to be intentional with every change in this repo, so I encourage you to think how this can be made into a small surgical fix.

Comment thread device/send.go Resolved
Comment thread tun/tun_linux.go Resolved
@SLoeuillet
SLoeuillet force-pushed the sloeuillet/sre-2492-gso-missing-csum-start branch from d174a7a to f3d5899 Compare November 18, 2026 09:42
@SLoeuillet
SLoeuillet requested a review from illotum November 18, 2026 09:49
@SLoeuillet

Copy link
Copy Markdown
Author

Re-tested the reworked commit on a GCE subnet router (linux-gcp 7.0.0-1017, gve): tailscale v1.104.7 with this commit cherry-picked onto its wireguard-go (9e0ab45), vs stock v1.104.7. Under ~15 MB k8s API fetches through the router, ethtool -K ens3 rx-gro-hw on toggled 6 times per binary (15 s on, 3 s off):

Binary Crashes Traffic
patched 0/6, same PID throughout, 0 tx drops 959 MB
stock 6/6, tcp header len is invalid: 0 on every toggle -

The bad packets show up within seconds of enabling hardware GRO; steady state with GRO on stayed clean for both binaries over 180 s (1.6-1.7 GB each).

@illotum

illotum commented Nov 18, 2026

Copy link
Copy Markdown

thinking: Is your case covered if we take the error handling change out? No new sentinel, no handleVirtioRead split to join errs, only the csum fixup on L804 and the rest handled by GSOSplit as before.

We do need to improve tun error resiliency, but ideally in a dedicated issue.

This might also reduce your testing suite.

@SLoeuillet
SLoeuillet force-pushed the sloeuillet/sre-2492-gso-missing-csum-start branch from f3d5899 to 6f7bb54 Compare November 18, 2026 18:01
@SLoeuillet SLoeuillet changed the title tun, device: segment GSO packets that arrive without checksum offsets tun: segment GSO packets that arrive without checksum offsets Nov 18, 2026
@SLoeuillet

Copy link
Copy Markdown
Author

Yes, the fixup alone covers it. Dropped the sentinel, the handleVirtioRead split and the send.go change, plus their tests; the commit is now tun/tun_linux.go + the hardware-GRO test cases.

Re-ran on the GCE router with this exact commit on v1.104.7, rx-gro-hw toggled on 6 times under load: patched 0/6 crashes (same PID throughout, 1 GB, 0 tx drops), stock 6/6 tcp header len is invalid: 0.

What is left uncovered, for the resiliency issue: a hardware-GRO packet the fixup cannot parse (IPv6 extension headers, protocol not matching the GSO type) still closes the device, as today.

@SLoeuillet

Copy link
Copy Markdown
Author

@illotum gentle ping: the rework you suggested is pushed (6f7bb54, csum fixup only, retested 0/6 vs 6/6). Could you take another look when you have a moment?

Comment thread tun/tun_linux.go Resolved
Comment thread tun/tun_linux.go Resolved
A GSO packet aggregated by NIC hardware GRO and forwarded into the TUN
device is CHECKSUM_UNNECESSARY, not CHECKSUM_PARTIAL, so the kernel hands
it over without VIRTIO_NET_HDR_F_NEEDS_CSUM and with csum_start and
csum_offset left at zero. handleVirtioRead then read the TCP data offset
from the IPv4 source address ("tcp header len is invalid: 0" for 10/8)
and RoutineReadFromTUN closed the device on that error. gve (Google Cloud
gVNIC) enables hardware GRO by default since Linux 7.1, also backported
to Ubuntu linux-gcp 7.0.0-1017, so every subnet router on such a VM lost
its tunnel seconds after starting. The gve fix (netdev/net bda3c8381653,
queued for 7.4 and stable) marks these packets CHECKSUM_PARTIAL.

When CsumStart is zero, take CsumStart and CsumOffset from the packet's
own IP header; GSOSplit already recomputes every segment's checksums.
Drop a packet whose offsets cannot be repaired this way, such as IPv6
with extension headers, instead of closing the device.

Updates tailscale/tailscale#22298

Signed-off-by: Stephane Loeuillet <stephane.loeuillet@kaiko.com>
@SLoeuillet
SLoeuillet force-pushed the sloeuillet/sre-2492-gso-missing-csum-start branch from 6f7bb54 to 5149eb0 Compare November 25, 2026 06:33
@SLoeuillet
SLoeuillet requested a review from illotum November 25, 2026 12:34

@illotum illotum left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks again!

@nbeirne nbeirne left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been following this PR's progression too. Looks good to me! Thanks.

@illotum
illotum merged commit d74d4ff into tailscale:tailscale Nov 25, 2026
15 checks passed
@SLoeuillet
SLoeuillet deleted the sloeuillet/sre-2492-gso-missing-csum-start branch November 25, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants