gvisor icon indicating copy to clipboard operation
gvisor copied to clipboard

forwarded TCP packets larger than the outgoing MTU are dropped instead of segmented

Open milantracy opened this issue 3 months ago • 3 comments

Description

When netstack forwards a TCP packet larger than the outgoing route's MTU with DF set, it drops the packet and increments Forwarding.PacketTooBig, with no ICMP frag-needed. ipv6.go does the same for all forwarded oversized packets.

This is not an edge case. A host that coalesces on receive (GRO/TSO) routinely hands the sandbox frames far larger than any MTU — I saw 2868, 5736, 7170, 11472 and 20076 bytes against a 1466-byte outgoing MTU. Every one is dropped, so the sender only advances via single-MSS RTO retransmits: a flat ~35 KB/s.

Linux forwards these. ip_forward() exempts GSO skbs whose per-segment length fits the MTU (skb_gso_validate_network_len()), and segments at transmit. netstack asks "is this buffer bigger than the MTU" instead of "would the segments fit", and drops.

Affected code: the IsForwardedPacket branch in writePacketPostRouting (pkg/tcpip/network/ipv4/ipv4.go) and the equivalent in pkg/tcpip/network/ipv6/ipv6.go. Fragmenting is not allowed here, but re-segmenting is.

Impact: any workload where the sentry forwards between an external interface and an internal bridge. Docker-in-gVisor is the common case.

Steps to reproduce

  1. Start a privileged container under runsc, and inside it run dockerd --iptables=false --ip6tables=false with the SNAT rules from images/basic/docker/start-dockerd.sh.
  2. Serve a large blob from outside the sandbox: nc -l -p 8099 < /blob
  3. From a container on the inner bridge: timeout 10 nc 8099 | wc -c

Result: ~365 KB in 10s. Fetching to the sandbox itself, and the outbound direction, both run at full speed — only the forwarded direction is affected.

runsc version

runsc release-20260727.0-85-g28cbfc7aa188

docker version (if using docker)


uname

No response

kubectl (if using Kubernetes)


repo state (if built from source)

No response

runsc debug logs (if available)


milantracy avatar Aug 06 '26 07:08 milantracy

Hi! I'd like to work on this. I'll first reproduce the forwarded GSO/MTU case and study the IPv4/IPv6 forwarding and segmentation paths in netstack. Then I'll make a focused fix so valid forwarded GSO TCP packets are segmented to the outgoing MTU instead of being dropped, with regression coverage for the reported behavior.

abdeltaehass avatar Aug 17 '26 20:08 abdeltaehass

Took a look, https://github.com/google/gvisor/pull/14579 should address it.

anishesg avatar Sep 03 '26 01:09 anishesg

We hit what looks like this bug in production-style Docker-in-gVisor use, with a side effect not mentioned above: under load, the sentry's own memory balloons by tens of GB.

Setup

  • runsc release-20261026.0, default platform, rootless Docker 27.5.1 on Linux 6.18 (host)
  • runsc flags: --ignore-cgroups --network=sandbox --net-raw --allow-packet-socket-write
  • Nested dockerd 29.1.3 started as in images/basic/docker/start-dockerd.sh: --iptables=false --ip6tables=false --mtu=<eth0 mtu>, ip_forward=1, SNAT for tcp/udp via iptables-legacy, overlay2 on tmpfs
  • eth0 mtu 1500; docker0 reports mtu 1486 even with --mtu=1500

Symptoms

  • pnpm install inside docker build intermittently fails with ERR_SOCKET_TIMEOUT and then getaddrinfo EAI_AGAIN, while the same fetches from the sandbox itself succeed.
  • Amplified ingress: one nested curl received 0.73 GB, while eth0 rx grew by 7.48 GB and all of it went out on docker0. After a nested download stalls, inbound traffic for it keeps arriving at ~100–150 MB/s with nothing on the receiving end. Over ~30 minutes of builds, eth0 received 71 GB.
  • The stack's /proc/net/snmp showed OutRsts in the hundreds of thousands after a few such downloads.
  • Sentry memory growth: the host-side gvisor_sentry process grew to ~41 GB RssAnon, while /proc/meminfo inside the sandbox showed ~15 GB used. Process memory doesn't show up in the sentry's RSS: a 2 GB allocation inside left it unchanged. So this looks like internal netstack memory. It drains slowly once the traffic stops (41 GB → 9 GB over about an hour). Earlier, it reached 51 GB RssAnon and the host OOM killer killed the sandbox.

Reproduction (fresh sandbox, nested dockerd set up as above): 6 nested containers, each running 8 parallel curls of an npm tarball in a loop for 20 s:

for i in 1 2 3 4 5 6; do
  docker run --rm $NET curlimages/curl sh -c 'end=$(($(date +%s)+20)); while [ $(date +%s) -lt $end ]; do
    for j in 1 2 3 4 5 6 7 8; do curl -s -o /dev/null --max-time 15 https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz & done; wait; done' &
done; wait
variant result sentry RssAnon
bridge (default), nested --mtu=1500 had to kill it within the first 20 s round > 6 GB
bridge, nested --mtu=1400 (docker0 1386) same > 6 GB
bridge, sandbox eth0 lowered to 1486 to match docker0 same > 6 GB
--network host for the nested containers 6.5 GB delivered over 3 rounds, 0 failures 245 MB
same loop run directly in the sandbox 2.1 GB delivered, 0 failures 102 MB
bridge, but through an HTTPS CONNECT proxy (tinyproxy) in the sandbox listening on the docker0 gateway 5.7 GB delivered, 0 failures 224 MB

At ~15 MB/s aggregate throughput, the bridge case was clean. The problem needs high-throughput forwarding. Changing the MTU makes no difference, which fits re-segmentation of GRO/GSO aggregates rather than a plain MTU mismatch.

Workaround we're using: tinyproxy on the docker0 gateway, plus proxies.default.httpsProxy in the nested Docker client config, so every nested build and container gets HTTPS_PROXY. Nested containers' connections then end in the sandbox instead of being forwarded.

floodedcodeboy avatar Nov 15 '26 17:11 floodedcodeboy