Skip to content

S07-06 - Name Mapping

Purpose: How wb-proxyd keeps its own checked copy of the names wb-netd gave synthetic addresses: name reports, releases, replay, lifetime, the second count of the wildcard budget, and the copy wb-hostd keeps.

Each VM’s copy of the name mapping arrives over the VM’s hand-off socket, in the messages of 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.. A stream to an address the copy doesn’t hold is refused there.

For each A answer with a synthetic address, wb-netd sends the name and the address on the VM’s hand-off socket before the answer leaves. With the ordering property of 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. (“Transport”), the report arrives before any stream to that address. A report doesn’t hold a descriptor.

wb-proxyd adds the pair to its copy of the VM’s mapping only when all of these hold:

Otherwise it drops the report. It logs it with the rule name-report-refused and the check that failed: message-form, name-form, not-allowed, synthetic-range, address-conflict or wildcard-budget.

A report or release that fails the message form, the name form or the synthetic range is malformed, and so is a stream message of the wrong form (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., “Streams”). An honest wb-netd never sends one, because wb-hostd checks the same entry first. For a malformed message, wb-proxyd also:

  1. closes the VM’s hand-off socket, and every stream that came on it;
  2. tells wb-hostd with a HandoffSocketClosed that names the socket, the rule name-report-malformed, and the check that failed: message-form, name-form or synthetic-range.

wb-hostd then ends that wb-netd, and counts the exit toward the restart limit, as for a malformed accounting record (S04-08-records-and-boundsS04-08-records-and-bounds: Records, Versions and BoundsThe records daemons send wb-hostd, the build version rules between processes, the bounds on host work a guest can cause, and logs., “Accounting and event channels”). S07-20-handoff-socketsS07-20-handoff-sockets: Hand-off SocketsThe life of one VM's hand-off socket: its identity, the acknowledgments of both ends, how it closes, who a failure is charged to, what each restart does to it, and which of its decisions reach the audit log. (“Closing a socket”) has this for every rule, and how a notice for another socket is ignored.

A report whose address the copy holds for another name means wb-netd gave out an address it hadn’t released. wb-proxyd then:

  • removes the old entry too;
  • closes every open stream to that address.

Streams to it are then refused until a later report is accepted.

A report that repeats an entry the copy holds, such as a replay, doesn’t change the copy.

An entry stays in the copy until wb-netd releases its address. wb-netd sends the release when the entry expires: once its TTL plus the guard interval has passed since its last answer and no connection to it is open. It doesn’t wait until another name needs the address (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”).

So wb-netd’s clock governs. wb-proxyd doesn’t expire entries on a clock of its own. A stream already open keeps the name it got at hand-off.

  • A release for an address the copy doesn’t hold is logged and ignored.
  • If a release can’t be sent, wb-netd keeps the address out of the pool. It sends the release again, in order, before any later report.

The copy holds at most the 131,072 addresses of the pool (SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.).

On each new hand-off socket, wb-netd first sends a name report for every live entry of its mapping. It sends them in order, and before any other message. A replay send that fails with ENOBUFS is retried in order, so no later message overtakes it.

wb-proxyd checks each report as in “Name reports”, with the bounds that wb-hostd puts on mapping entries:

  • at most one entry per address of the pool;
  • the name in canonical form;
  • the address in the synthetic range.

After a wb-proxyd restart the replay rebuilds its copy.

After a wb-netd restart, the new wb-netd holds the mapping that wb-hostd kept from its accounting records (S04-08-records-and-boundsS04-08-records-and-bounds: Records, Versions and BoundsThe records daemons send wb-hostd, the build version rules between processes, the bounds on host work a guest can cause, and logs., “Accounting and event channels”, and S04-07-supervisionS04-07-supervision: SupervisionWho starts and restarts each host process, what happens when wb-hostd stops or the bundle is upgraded, and daemon outages., “Restarting a daemon”). Its replay matches the copy wb-proxyd kept.

The copy belongs to the VM. wb-proxyd keeps it across a save and restore, as wb-netd’s mapping is kept (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves.). Time while the VM is saved counts as it does for that mapping.

The copy and wb-netd’s mapping are both cleared only at a start that isn’t a restore. Otherwise releases alone remove entries. So a VM that idles and is saved and restored keeps the answers its guest cached.

wb-proxyd learns of such a start from a fresh HandoffSocket (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., “From wb-hostd”). wb-hostd sets its fresh field on each HandoffSocket after such a start until wb-proxyd acknowledges one. So the first socket wb-proxyd acknowledges after the start is fresh, also when an earlier one failed or wb-proxyd restarted in between. It sends that message before the run’s first PolicyChange. wb-netd refuses a HandoffSocket that sets fresh with message-form, since its own start clears its mapping.

wb-proxyd checks a fresh message like any other. It then closes the VM’s old socket and every stream that came on it, so no message of the previous run reaches the cleared state. Then it clears the copy and the wildcard names, and drops the VM’s effective policy and sequence. It keeps the generation, and logs the clear with the rule vm-fresh-start.

Until the run’s first PolicyChange, wb-proxyd doesn’t hold a policy for the VM, so every report and stream is refused (SEC05-default-denySEC05-default-deny: Default-deny egress, enforced on the hostOnly allowlisted hostnames are reachable.). That PolicyChange may start at sequence 1 again. A new wb-netd gives out addresses the previous run held, and none of them conflicts with an entry of that run.

wb-netd debits the wildcard budget before it answers (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.). wb-proxyd keeps a second count against the same budget: the distinct names it accepted only under a wildcard entry, per VM and active period. A replayed or repeated name isn’t counted again.

Before it accepts a name that adds to the count, wb-proxyd writes the name to wb-hostd as an accounting record, ProxydWildcardName (S04-08-records-and-boundsS04-08-records-and-bounds: Records, Versions and BoundsThe records daemons send wb-hostd, the build version rules between processes, the bounds on host work a guest can cause, and logs., “Accounting and event channels”). A write that fails, or that blocks for more than 100 ms, counts as failed. The report is then refused with the rule name-report-refused and the check wildcard-budget.

wb-hostd keeps the set per VM and active period, and gives it to a new wb-proxyd at start, in the payload of its ProxydStart message. A wb-proxyd restart thus keeps the count.

At the start of a new active period (S07-01-per-vm-policyS07-01-per-vm-policy: Enforced per VMWhy the VM is the unit the gateway enforces, how the policies of its projects combine, and what happens when they conflict or change.), wb-hostd clears its set for the VM, then sends wb-proxyd an ActivePeriodStart that names the VM and doesn’t hold a descriptor. wb-proxyd clears its count for the VM and logs it with the rule active-period-start. The copy keeps its entries, as wb-netd’s mapping does. wb-proxyd doesn’t acknowledge the message. It decides the control messages about a VM in order (S07-21-vm-endS07-21-vm-end: A VM's End in wb-proxydHow wb-hostd ends a VM's hand-off sockets in the one wb-proxyd, and how the VM's last event records reach its stop record without one VM's stop or backlog taking the other VM's network down.), so the acknowledgment of a later message about the VM says this one applied. A fresh HandoffSocket clears the count too (“Lifetime”).

Once wb-hostd has read wb-proxyd’s records, its set for the active period holds every name wb-proxyd counts in it. A restart thus never seeds a count lower than the one wb-proxyd held. A write may be in flight when a period starts: wb-hostd may count the name in the period that ended and clear it with that period.

So wb-proxyd counts a name only when no ActivePeriodStart for the VM applied during its write. Otherwise it writes the name again and decides the report once more, and logs each write after the first with the rule wildcard-name-rewritten. After 3 writes that a period start crossed, it refuses the report with name-report-refused and the check wildcard-budget. A fresh HandoffSocket during the write closes the socket the report came on, and the report is dropped: the name is neither counted nor mapped.

A name in wb-hostd’s set that wb-proxyd then refuses fails closed for egress: the second layer only admits fewer names. It doesn’t for availability when the budget is at its maximum, 65,535 names. One such name in a full set is then the 65,536th, which wb-hostd refuses as a malformed record with wildcard-count (“Kept by wb-hostd”), and that ends wb-proxyd for every VM.

Refused lookups never reach wb-proxyd, so its count is at most wb-netd’s.

wb-hostd builds a copy of each VM’s mapping from wb-netd’s accounting records, with the checks of S04-08-records-and-boundsS04-08-records-and-bounds: Records, Versions and BoundsThe records daemons send wb-hostd, the build version rules between processes, the bounds on host work a guest can cause, and logs. (“Mapping entries are checked”). It also refuses an entry whose name or address the VM holds for another, with mapping-entry-invalid and the check mapping-conflict. An entry the VM holds already is a renewal, which moves its receipt time. A new entry past the count of 131,072 has the check entry-count.

A release of an address the VM doesn’t hold is logged with mapping-release-unheld, rate-limited, and leaves the copy unchanged.

The other records are malformed (accounting-record-malformed) when:

  • the VM is one wb-hostd never started (vm-not-served). Records a stopped VM’s daemons left in the channel are still kept;
  • a mapping entry comes from wb-proxyd;
  • a debit or a ProxydWildcardName goes past 65,535 names per VM (wildcard-count). A repeated one counts once.

wb-proxyd can write a ProxydWildcardName just before a VM stops or restarts, and wb-hostd reads it after. Ending wb-proxyd for it would stop the other VMs too (SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another.). So a name for a VM that is stopped, or whose hand-off socket wb-proxyd hasn’t acknowledged since its start, is logged with proxyd-name-unserved, rate-limited. wb-hostd keeps the name while the VM is stopped and after a restore, because it counts against the period the VM goes on with. After a start that cleared the VM’s counts, wb-hostd drops it. The name came from the previous run, and wb-proxyd’s count for the new run doesn’t hold it.

A channel that fails ends its sender with accounting-channel-failed, but a sender that closes its own channel isn’t ended.

Once wb-netd has exited, wb-hostd reads what is left in its accounting channel until the socket is empty, and then stops reading (S04-08-records-and-boundsS04-08-records-and-bounds: Records, Versions and BoundsThe records daemons send wb-hostd, the build version rules between processes, the bounds on host work a guest can cause, and logs., “Accounting records”). A copy of wb-netd’s end that is still open doesn’t keep the read going, such as one wb-netd sent over another socket that nobody reads. So a VM stop doesn’t wait for it (SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.).

Each record read then is checked and kept as one read before the exit. The read after the exit is bounded at more records than the socket’s buffer holds, so only a writer other than the exited wb-netd can reach the bound. The records past it, and every write after the stop, are refused unread. Each stop of the read after the exit is logged with accounting-sender-gone, whether the socket was empty, the sender’s end was closed, or the bound was reached.

The decision behind this design, I68I68 (closed): wb-proxyd must bind stream identity to the connection, not to wb-netd's tagsFound in the security review of #65 (X23-sandboxed-daemons result)., is on 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..

Status: Draft