roadmap BUILT

649. Every client of a network stack shares its socket numbers

Title and slug are drafts. Raised by milestone 590 (the booted system starts its network stack), whose number is provisional, which gave programs at the prompt a WRITE view of one net_stack endpoint and had to say in caps what that view does not narrow.

The fix changes crates/socket_contract, which two programs agree on, so it is a wire format and calef's call.

The finding

socket_protocol::req(op, sid) names a socket by sid, an integer below MAX_SOCKETS (6), and net_stack keeps one table of them for every caller of its endpoint. Nothing ties a sid to the client that opened it. So two programs holding the network capability at once can each send, read and close the other's sockets, and one that attaches a page to a sid another is using redirects that socket's bytes into its own page. Under the kernel harness this never mattered, because every stack had one client. At the prompt it is the difference between "may reach the network" and "may reach every connection any other program on this machine has open", and caps now prints the second sentence because it is the true one.

Options

  1. A badge per client. The progenitor mints each declaring child its own badged view of the stack's endpoint, and net_stack keys its socket table by badge. Needs endpoint badges, which is a question about §10 (process model: capability-based, microkernel) before it is one about sockets.
  2. An endpoint per socket. OPEN answers with a fresh endpoint capability for that socket, the fs_subtree_caretaker shape; the sid disappears from the wire. The larger change and the one that matches how this tree already narrows files.
  3. A stack per client. One net_stack per declaring job. No wire change, but a NIC can back one stack, so this only works behind a multiplexer that does not exist.

Recommendation, from reading rather than measurement: option 2, because it is the shape the tree already uses for the analogous file case (a narrowed endpoint per grant), and a wire change is owed either way. What each costs has not been measured.

Option 1 is now buildable without its own §10 fork. calef ruled the analogous filesystem question on 2026-09-26 (milestone 599 (a frame per filesystem client channel), a frame per filesystem client channel) in favor of badged endpoint capabilities, which is exactly the "endpoint badges" option 1 says it needs. Milestone 599 builds the badge machinery on the shared INVOKE surface (a BADGE method to mint a badged endpoint, and the badge as a fourth RECEIVE_CAP return value). So option 1's prerequisite is being built, and its cost here is net_stack keying its socket table by the badge the kernel already delivers, with no socket_protocol change. Whether to take option 1 (reuse the badge) or option 2 (an endpoint per socket) is still open and still a wire decision, but the badge no longer has to be argued for from scratch.

Ruled and built (2026-10-07 UTC)

calef ruled the shape on 2026-10-07 (UTC), recorded on PR #1798 at 15:04Z: each socket is its own capability. The stack mints a badged endpoint per socket on open, and every later call is made on it. The stack names the socket by the kernel-stamped badge, so socket_protocol drops the sid. Close unbinds the badge, and a socket moves to another program by passing the capability. It refuses this block's option 1 as written ((badge, sid) keying) and its option 3.

A reply cannot carry the minted capability through a plain REPLY, and SEND_CAP would park the one-threaded stack on any client that never receives, so calef ruled (2026-10-07, PR #1817): option A, a new Reply method that carries one capability. §255 (each socket is its own capability), number provisional, records both rulings, the method's semantics and the contract.

Reuse: none exists to take. The contract and the stack are this tree's own; the method follows seL4's reply-carries-a-capability and Fuchsia's zx_channel_call, read for §255 and not code.

Result

Built on aarch64, riscv64 and x86_64 (PR #1817).

The exit criteria from the review of #1798 (finding 8) are met. The test runs in the default suite with no opt-in skip. Each test starts its own stack and gives every region back, so the aarch64 suite gains no held region. A replayable record that brings the shared namespace back turns it red.

Follow-on

Index row

Built: each socket is its own capability (§255), handed over by a new REPLY_CAPABILITY, so a network program reaches only the sockets it holds.