Skip to content

S07-02 - Packet Path

Purpose: How wb-netd carries the guest’s frames: the packet transport, the stack, the link filter, its caps, addressing, the MTU and connections.

Each VM’s virtual NIC is connected to its wb-netd by a platform-specific packet transport (S12-platformsS12-platforms: PlatformsWhich host and guest operating systems Wraith Box targets, how platform-specific code is isolated, what each platform uses, and how wb works inside WSL.). The transport needs no host privileges and no host network device.

On macOS, wb-vmd creates a datagram socketpair per VM:

  • it gives one end to the VM’s network device (file-handle attachment);
  • it passes the other end to that VM’s wb-netd through wb-hostd (SCM_RIGHTS).

Every Ethernet frame the guest sends arrives in wb-netd. The guest has no other network path. A NAT or bridged network device would be one. wb-vmd’s device-set check keeps it out, not its sandbox profile (S04-02-vm-providerS04-02-vm-provider: VM Provider and StreamsHow wb-vmd hands guest connections and the NIC endpoint to other processes, the fixed device set of a VM, and where wb-proxyd takes a stream's identity from., “The device set is fixed and checked”, X25-vmd-sandboxX25-vmd-sandbox: Self-sandboxed `wb-vmd`Can wb-vmd confine itself at start with a Seatbelt profile that allows the Virtualization framework, its VM bundles under <data>/vms and nothing else, and still create, start, save and restore a macOS VM?).

The rest of this spec is the same on every platform.

The stack is gVisor’s userspace TCP/IP stack (pkg/tcpip), used as a Go module from gVisor’s go branch.

Its file-descriptor link endpoint is Linux-only. So Wraith Box provides a small link endpoint that moves frames between the packet transport and the stack, with one transport adapter per platform.

On macOS:

  • each datagram is one Ethernet frame;
  • the host end’s SO_RCVBUF is at least twice its SO_SNDBUF, as Apple’s header for the attachment asks;
  • the adapter reads each datagram into a buffer of MTU + 15 bytes, one more than the largest frame. A datagram that fills the buffer was truncated. It is dropped and logged with the rule frame-truncated, never passed on in part.

The stack runs in promiscuous and spoofing mode. It then accepts and answers connections to every synthetic address (X03-network-pathX03-network-path: Network pathA macOS guest boots on the file-handle attachment with the gVisor stack: gets a DHCP lease, resolves only allowlisted names, reaches only the proxy.).

With spoofing on, gVisor answers ARP for any address. The guest then declines every lease as an address conflict (X03-network-pathX03-network-path: Network pathA macOS guest boots on the file-handle attachment with the gVisor stack: gets a DHCP lease, resolves only allowlisted names, reaches only the proxy.). So wb-netd checks every frame before the stack sees it. It drops the frame unless all of these hold, in this order. The rule a drop is logged with follows each step.

  1. The frame is 14 to MTU + 14 bytes long (frame-size).
  2. Its source MAC is the guest’s. Its destination MAC is the gateway’s or broadcast (frame-mac).
  3. Its EtherType is ARP or IPv4. IPv6 and the rest are dropped (frame-ethertype).
  4. ARP is Ethernet/IPv4: hardware type 1, protocol type 0x0800, address lengths 6 and 4. Its operation is request or reply. The sender hardware address is the guest’s MAC, the sender protocol address is the leased address, and the target protocol address is the gateway (arp-form).
  5. IPv4 has a header of 20 bytes (no options) with a valid checksum, and a total length within the frame. It is not a fragment (MF clear, offset 0), and the reserved flag bit is clear (ipv4-form). Its source is the leased address, or 0.0.0.0 only for DHCP from UDP port 68 to port 67 (ipv4-source). Its destination isn’t the leased address, 0.0.0.0/8 or 127.0.0.0/8 (ipv4-destination).
  6. The protocol is allowed:
    • TCP passes to the stack, which decides under “Connections”.
    • UDP passes only to the gateway’s port 53, or for DHCP from port 68 to port 67. DHCP goes to the gateway, or to limited and subnet-directed broadcast (udp-not-dns).
    • ICMP passes only as an echo request to the gateway (icmp-not-echo).

Other IP protocols are dropped (ip-protocol). Multicast and non-DHCP broadcast are dropped before the protocol check (ip-broadcast).

With the ARP rule the stack doesn’t answer the guest’s probes for its own address, as an answer would tell it the address is taken. And the guest can’t claim another address in the stack’s neighbor table.

gVisor didn’t answer ping to other addresses even without the ICMP rule, which is a second layer.

Each drop is counted and logged with its rule.

Every class of event the guest can trigger is rate-limited per rule. In wb-netd these are:

In wb-proxyd they are:

The record that follows a suppressed run holds the count it suppressed (SEC10-auditSEC10-audit: AuditEvery egress decision, approval, and returned change is recorded on the host in a persisted log the guest cannot alter., SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.).

A string from the guest can go into a log record. Examples are a DHCP option, a DNS name, and a name or label in a hand-off message. Such a string is escaped and cut to a fixed length in code. A cut string ends with a truncation marker.

Packets the stack sends itself, such as its own broadcast DHCP replies, are never counted as guest drops.

Each VM’s wb-netd caps:

Each cap is configuration with a default. A frame or connection over a cap is dropped, and logged with the cap’s rule (SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.).

gVisor has no stack-wide memory limit. The established cap times a cap on each TCP buffer bounds the stack’s buffer memory. A connection holds its place until both its hook and the stack have closed it, so a guest reset doesn’t free it early. Fixed timeouts, not configuration, bound how long the stack keeps a connection its hook closed: 30 s without an acknowledgment, set at the hook’s close, 5 s in FIN-WAIT-2, and 5 s in TIME-WAIT. An outbound frame over the queue’s cap is dropped with link-queue-full, and one the guest’s full buffer still refuses after a bounded number of retries with link-write-failed.

wb-netd listens on nothing on the host. It opens a connection to the guest only for the build VM, and only to its port 22 (S07-18-build-networkS07-18-build-network: Build NetworkThe build VM's network: what its wb-netd serves, the one connection to the guest's port 22, and its refusal for session VMs.). Its only peers are:

Any other path from the host into the guest, such as port forwarding (FR11-port-forwardFR11-port-forward: Port forwardingDev servers listening in the guest are reachable on host loopback.), needs its own spec text. It doesn’t go through wb-netd.

wb-netd runs a DHCP server. It hands the guest a single private IPv4 address, with the gateway as router and DNS server.

  • Only the guest’s own MAC and leased address are accepted.
  • IPv6 is not offered, and all IPv6 frames are dropped.
  • A reply holds only the subnet mask, router, DNS server, lease time, server identifier and interface MTU.

The macOS client also asks for a proxy configuration (WPAD, option 252), static routes, encrypted DNS, IPv6-only preferred, NetBIOS, LDAP and a search domain. The gateway never offers any of it (FR08-no-proxy-configFR08-no-proxy-config: No per-tool proxy settingsAllowlisted network destinations work for every tool without per-tool proxy configuration.).

The server answers each message and logs it with a rule:

Message Answer Rule
DISCOVER OFFER dhcp-offer
REQUEST for the leased address ACK dhcp-ack
any other REQUEST NAK dhcp-nak
INFORM an ACK of the same options but the lease time, with no address dhcp-inform
RELEASE none. The lease stays with the guest’s MAC, because there is only one dhcp-release
DECLINE: something answered for the guest’s address none, logged as a finding dhcp-decline
any other type none, dropped dhcp-type

A message from another MAC (chaddr) is dropped with dhcp-mac. dhcp-form drops one over 1500 bytes, with option overload (52), or not a BOOTREQUEST for a 6-byte Ethernet address with the magic cookie, a message type, and well-formed options, each once, ending in END. Each request gets one log record, rate-limited per rule.

Strings the guest sends are logged escaped and cut to the fixed length (“Events and rate limits”), never raw. Examples are the host name, vendor class and client identifier (options 12, 60, 61 and 81).

The link MTU is 65535, the largest the macOS attachment accepts (1500 to 65535).

  • wb-vmd sets it on the attachment.
  • The DHCP interface-MTU option (26) offers the same value.
  • The guest uses the offered value.

The largest frame is then 65535 + 14 bytes.

DNS is on its own page, S07-03-dnsS07-03-dns: DNSHow wb-netd answers the guest's DNS queries: synthetic addresses, the name form, negative answers and the wildcard budget..

TCP to a synthetic address on an allowed port is accepted by the stack. It is handed to wb-proxyd as a byte stream over the VM’s hand-off socket, with the synthetic address and port (S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach.).

Once X14-flow-attributionX14-flow-attribution: Guest flow attributionA Network Extension transparent proxy in a macOS guest (S13-guest-confinement): can it be approved during the image build without MDM? delivers labels, the hand-off also holds the label the guest reported for the flow, marked untrusted (S13-guest-confinementS13-guest-confinement: Guest ConfinementControls inside the guest that narrow what a project user's processes can do, and tell the host which program opened each connection.). The project and session come only from that label, and it can only narrow.

A port is allowed for a synthetic address when the effective policy names it for that address’s host:

TCP to a synthetic address on any other port is reset at the first SYN. It is audited with the rule port-not-allowed.

Everything else is refused:

  • TCP to any other address is reset (tcp-destination-refused).
  • UDP other than DNS is dropped. Clients fall back from QUIC to TCP. UDP to an unbound port gets no ICMP reply (udp-unbound).
  • ICMP is answered only for the gateway address.
  • TCP to the gateway on any port but 53, or on 53 with no DNS-over-TCP server, is reset too (gateway-port-refused). So is TCP to a synthetic address with no name mapping (synthetic-unmapped).

These resets go out on the goroutine that read the SYN. A SYN a part of wb-netd may take is checked against the established cap (tcp-cap) before that part decides it.

The host, the LAN, and raw IP destinations are therefore unreachable by construction (SEC05-default-denySEC05-default-deny: Default-deny egress, enforced on the hostOnly allowlisted hostnames are reachable.).

The reset is sent for the first SYN. In the spike the guest sent the SYN to the gateway’s port 80 twice before it failed (X03-network-pathX03-network-path: Network pathA macOS guest boots on the file-handle attachment with the gVisor stack: gets a DHCP lease, resolves only allowlisted names, reaches only the proxy.).

NTP is UDP, so it is dropped. The guest clock comes only from wb-guestd (S06-vm-lifecycleS06-vm-lifecycle: VM Lifecycle, Images and the Guest AgentHow guest images are built, how VMs are kept warm, how projects and sessions map onto guests, and what wb-guestd does.).

Packets are processed in userspace, so throughput is lower than kernel networking. S11-verification-and-spikesS11-verification-and-spikesthe filter's fuzz properties, including one that replays the filtered output and the exit reset into a headless emulator and checks it is back in its initial state, and a conformance case that prints every dropped seq… sets a benchmark for large downloads. If throughput misses it, the fix is inside wb-netd (batching, buffer sizes), not a second network path.

X03-network-pathX03-network-path: Network pathA macOS guest boots on the file-handle attachment with the gVisor stack: gets a DHCP lease, resolves only allowlisted names, reaches only the proxy. measured, with a plain HTTP stand-in for wb-proxyd:

Transfer MTU 1500 MTU 9000 MTU 65535
1 GiB download about 350 MB/s about 570 MB/s about 570 MB/s
upload about 300 MB/s not measured about 950 MB/s
  • On downloads at the larger MTUs, the stand-in was the limit.
  • At MTU 1500 the cost per frame dominates. The wb-netd stand-in used about 7 CPU-seconds per GiB downloaded there, and about 4 at the larger MTUs.
  • Those CPU figures include the stand-in for wb-proxyd, which ran in the same process.

Status: Draft