C01 - Network and DNS
Purpose: The test cases for the guest’s network path: the link endpoint, addressing, and the DNS gateway with its hold, quiet refusals, and negative answers.
Verifies: S07-02-packet-pathS07-02-packet-path: Packet PathHow wb-netd carries the guest's frames: the packet transport, the stack, the link filter, its caps, addressing, the MTU and connections. (“Addressing”), 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., 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. (“Messages”, “Order of checks”, “Name form”, “Synthetic pool”, “Local answers”, “Negative answers”, “Wildcard budget”), S07-04-dns-refusalsS07-04-dns-refusals: DNS RefusalsHow wb-netd refuses a name: approval events, the hold before each refusal, quiet refusals, and the answer that is the same for every reason. (“Hold”, “Widening during the hold”), 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”)
Fuzzing
Section titled “Fuzzing”- Ethernet, IP and TCP handling at the link endpoint, and DHCP.
FuzzLinkEndpoint(internal/netd/stack) feeds frames through the link endpoint into the stack with the TCP rules and no hooks. The stack must send frames only to the guest’s MAC or broadcast, answer ARP only for the gateway, and send no SYN-ACK. A DHCP reply goes to the guest’s MAC, with the leased address or zero asyiaddr.FuzzLinkEndpointBuildfeeds frames to the build VM’s stack while its connection to the guest’s port 22 is opening, with frames to port 0 sent to the connection’s port. It must send a SYN-ACK only on that connection’s addresses and ports. - The DHCP server.
FuzzDHCP(internal/netd/dhcp) feeds messages through the parser, the reply and the server loop, with seeds from the macOS client’s DISCOVER and REQUEST. The parser must fail only with a form error, which the server drops withdhcp-form. A reply must go only to the guest’s MAC, hold the leased address or zero asyiaddr, and hold only the message type and the six options of S07-02-packet-pathS07-02-packet-path: Packet PathHow wb-netd carries the guest's frames: the packet transport, the stack, the link filter, its caps, addressing, the MTU and connections., “Addressing”. Every string in a log record must be printable and cut to its length. - The link filter of S07-egress-gatewayS07-egress-gateway: Egress GatewayThe only path from a guest to any network: a userspace network stack (wb-netd) and a policy-enforcing proxy (wb-proxyd) on the host. and its ARP branch, with a
corpus of frames from 0 to 65535 + 14 bytes, and seeds of truncated
reads that fill the MTU + 15 byte buffer, which must be dropped.
FuzzLinkFilter(internal/netd/link) checks that the filter agrees with a second check written with gVisor’s header package on every frame, and never passes one longer than MTU + 14 bytes. - The DNS name form, with a corpus that holds a dot byte inside a wire
label, a label of 0 and of 64 bytes, and a name of 254 bytes
(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., “Name form”).
FuzzNameForm(internal/dnsname) feeds lists of labels of 0 to 255 bytes. An accepted name must be in canonical form and pass the check again unchanged as a host. The wire and host checks must agree on every list a host can hold, and a refusal message must be printable ASCII. - The synthetic pool (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., “Synthetic pool”).
FuzzPoolOps(internal/netd/synth) runs a sequence of answers for names the fuzzer picks, connection opens and closes, clock steps, sweeps, and failing writes and sends, on a pool of 8 addresses. Each address maps to one name at a time, and goes to another name only after its release was recorded and reported. The pool never releases a pinned entry, and holds at most 8 live entries. - The DNS server (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., “Messages”, “Order of checks”).
FuzzDNSQuery(internal/netd/dns) feeds message bytes through the parser, the decision and the hold, with a fake policy that allows one name. The corpus holds a dot byte inside a wire label, a label of 0 and of 64 bytes, a name of 254 bytes and one over 255, a compression pointer in the question, and the queries an idle macOS guest sent in 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 and without an OPT record. A message that fails the form gets no response. A response’s question must be the query’s wire bytes, anArecord must be for the allowed name and in 198.18.0.0/15, and everyNXDOMAINmust hold the zero SOA. A held refusal and a local answer must be the same bytes for one query whatever the rule.
Conformance
Section titled “Conformance”Interfaces and the link
Section titled “Interfaces and the link”- List the guest’s network interfaces and routes, and see exactly one
Ethernet interface, its lease from
wb-netd, and no address or route in a vmnet subnet, which a NAT device would add (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?). - Connect to a raw IP address, to the host, to the LAN, and over IPv6. Ping them and a synthetic address, and see that nothing answers.
- See that nothing answers the guest’s ARP probes for its own address, and that the lease holds only the options in S07-egress-gatewayS07-egress-gateway: Egress GatewayThe only path from a guest to any network: a userspace network stack (wb-netd) and a policy-enforcing proxy (wb-proxyd) on the host.’s list (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.).
- Send a forged ARP reply, a fragment, an IPv4 packet with options, and a frame to another destination MAC, and see each dropped with its rule.
Lookups
Section titled “Lookups”- With the gateway’s empty answers to
HTTPSandSVCB, see the macOS resolver still connect to an allowlisted name as fast as it did when they were refused (B17-network-pathB17-network-path: Does a macOS guest work on our userspace network stack, reaching only the proxy, and how fast?Yes, with conditions.). - Resolve a name on the guest OS’s background list, and see
NXDOMAIN, an audit entry and no approval event, also when it is sent in mixed case and with a trailing dot. Resolve a name one label longer under it, and see an approval event. - See the same answer bytes for a name that isn’t allowlisted, one that is denied, one on the background list, and one in a part that is off (S07-04-dns-refusalsS07-04-dns-refusals: DNS RefusalsHow wb-netd refuses a name: approval events, the hold before each refusal, quiet refusals, and the answer that is the same for every reason., “Quiet refusals”).
- Send UDP other than DNS, resolve a name that isn’t allowlisted, exceed the wildcard budget, and use a DNS server other than the gateway.
Negative answers and approvals during a lookup
Section titled “Negative answers and approvals during a lookup”- Resolve a name that isn’t allowlisted, approve it within 4 seconds, and see the same lookup answered with an address.
- Resolve another, leave it unanswered, and see
NXDOMAINafter 4 seconds with an SOA record of TTL 0 andMINIMUM0. Then approve it, resolve it again within 1 second of the approval, and see it succeed, so the guest didn’t cache the refusal. A guest resolver that keeps a minimum negative cache time despite the zero TTL fails this check, and the delay it adds after a late approval is then written into 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., “Negative answers”. - See that an empty
AAAAanswer for an allowed name has the TTL of itsAanswer.
- Time the refusals of a denied name, a name on the background list, a
name that isn’t allowlisted, and a name refused with
audit-budget, once with the accounting channel answering at once and once with it blocking for just under its 100 ms limit. See the same hold for each. - See the guest’s resolver (
mDNSResponderon macOS) wait for a held answer and not fail the lookup sooner (S07-04-dns-refusalsS07-04-dns-refusals: DNS RefusalsHow wb-netd refuses a name: approval events, the hold before each refusal, quiet refusals, and the answer that is the same for every reason., “Hold”, B51-approval-flowB51-approval-flow: What happens between a blocked lookup and the user's answer?Hold the DNS answer for a few seconds while the notification is open, answer a refusal with a negative TTL of zero, and keep guest OS names out of notifications.). - With the VM over its audit budget, resolve a name that isn’t
allowlisted, approve it during the hold, and see the lookup still
refused at the end of the hold with
audit-budget(S07-04-dns-refusalsS07-04-dns-refusals: DNS RefusalsHow wb-netd refuses a name: approval events, the hold before each refusal, quiet refusals, and the answer that is the same for every reason., “Widening during the hold”). - Send more refused queries at once than the hold limit, and see the
rest dropped and counted with
dns-hold-full, with no approval event for them. Send one over DNS over TCP, and see the connection closed. - Send queries for a whole hold at many times the query rate, and see
those over the rate dropped at once with
dns-query-rate, no answer sent for them, and none dropped withdns-hold-full. See a name that isn’t allowlisted, looked up during the flood, still raise an approval event once the rate has a token for it. Over DNS over TCP, send one over the rate on a connection with a held query, and see the connection stay open and the held query answered at the end of its hold. On a connection without one, see the connection closed. - With queries held, approve a name, so that more held queries are run
again at once than the query rate allows. See the excess refused with
dns-query-rateat the end of their holds, with no new requests, learn entries or lookup counts. - Close a DNS-over-TCP connection for
dns-hold-fullwhile it has held queries, and see their timers not fire (S07-04-dns-refusalsS07-04-dns-refusals: DNS RefusalsHow wb-netd refuses a name: approval events, the hold before each refusal, quiet refusals, and the answer that is the same for every reason., “Hold”).
Host-side DNS tests
Section titled “Host-side DNS tests”The host-side parts of “Lookups”, “Negative answers and approvals
during a lookup” and “Hold” run as Go tests in internal/netd/dns,
with fakes and testing/synctest as the clock:
TestAllowedA,TestOtherTypesandTestPoolFull: the answers to an allowed name, andREFUSEDat once forTXT.TestLocalAnswers: the local answers, at once with the zero SOA.TestRefusalsAreAlike: every refusal reason gives the same bytes, sent at 4 seconds and not before, also with each accounting write taking 99 ms.TestBackgroundandTestBackgroundPastBudget: quiet refusals in mixed case and past the budget, and an approval event for a name one label longer.TestBudgetDebits,TestBudgetSpentandTestKeptBudget: which lookups debit the wildcard budget, and what is refused once it is used up.TestHoldFullandTestClose: the hold limit, and no held refusal sent after the server closes.TestFormFloodSpendsRate: a name that fails the form spends a rate token.TestRateDropsandTestRateFloodLeavesHoldRoom: a query over the rate is dropped at once, logged and counted withdns-query-rate, and a flood over the rate leaves room in the held-query table for a name that raises an approval event, at the smallest cap.TestHeldQueriesMinimum: a held-query cap the rate could fill in one hold is refused.TestParseQueryRefuses: everydns-message-formcase is dropped without an answer.
TestDNSOverUDP (internal/netd/stack) sends real UDP queries
through the stack: an allowed name resolves at the gateway, and a
query to another server is dropped with udp-not-dns.
The build VM’s network
Section titled “The build VM’s network”- Start
wb-netdwith no mode, and with an unknown one, and ask each for the connection to the guest’s port 22. See each refused and logged withbuild-connect-refusedand the check, with no SYN sent to the guest. - Send a build VM’s
wb-netda control message that names a mode, and see it refused withbuild-mode-refusedand the mode unchanged. - Ask the build VM’s
wb-netdwith another VM’s name, with an older generation, and twice at once, and see each refused withbuild-connect-refused. After it has handed a socket, ask again and see that refused too. - With nothing listening on the guest’s port 22 at first, see
wb-netdtry again, then hand one socket and logbuild-connectoncesshdanswers. With nothing listening at all, seebuild-connect-timeoutat the deadline and no socket. - From the build guest, open TCP to a raw IP address, the gateway and
a synthetic address, and send a DNS query. See each reset or
dropped and logged with
build-egress-refused, and no stream handed towb-proxyd.
These run as Go tests:
TestDecodeBuildMode(internal/egressmsg): a start whose mode is missing or unknown makes a session VM’swb-netd, and a build start must name the VMbuild.FuzzControlMessagecovers the new messages.TestBuildConnectRefused(internal/netd/hostlink): a session VM’swb-netd, another VM, an older and a newer generation, and a second connect while one runs are each refused withbuild-connect-refused, and none of them tries to connect.TestBuildConnectends with the refusal after a socket was handed.TestBuildModeRefusesandTestSecondStartMode: a hand-off socket, policy change, active period start or second start in build mode is refused withbuild-mode-refused.FuzzNetdControlchecks that a session VM’swb-netdnever tries the connection.TestBuildConnectandTestBuildConnectTimeout: tries until the guest answers, thenbuild-connectand one socket, orbuild-connect-timeoutand no socket at the deadline.TestDialGuest,TestDialGuestRefusedByGuest,TestDialGuestNoAnswerandTestDialGuestSessionRefused(internal/netd/stack): the connection to the guest’s port 22.TestBuildRelay(internal/netd/handoff) relays it over the socketpair.TestBuildEgressRefused(internal/netd/stack) andTestFilterBuild(internal/netd/link): TCP from the build guest is reset and UDP from it dropped, DNS included, withbuild-egress-refused.TestChildSessionRefusesBuild(cmd/wb-netd) runs the confined process with no mode and with an unknown one. Its refusal of the connection, withbuild-connect-refused, reaches the event channel, andwb-netddoesn’t send the guest a SYN.TestStrayBuildSocketRefused(internal/hostd/netdproc):wb-hostdrefuses aBuildSocketfrom a session VM’swb-netdand closes its descriptor.TestChildBuild(cmd/wb-netd) runs the confined process in build mode through a refused connect, a reset, and a SYN to port 22.
Status: Draft