Peios Learn
Documentation

Peios

Peios Peios Kernel Universal Directory Project

Developer Tools

Trail Acta Provium clackatoo CAF GCSL Pekit

Applications

Framewright

Standards and Conventions

Standards and Conventions Peios Specifications
Peios Kernel

Network objects

Single-page view · as markdown

Network objects

Peios Kernel / Internals / KACS / Network objects

Use these articles to understand network objects in the Peios kernel.

  • Port Reservations
  • Socket Identity

Port Reservations

Peios Kernel / Internals / KACS / Network objects

Ports are a shared, unowned namespace. Linux protects it with one rule: bind(2) below port 1024 needs CAP_NET_BIND_SERVICE, and everything above is anyone's. That is too coarse in one direction — any privileged process gets every low port — and absent in the other: nothing protects 8080, 3306 or 5432 from whichever process asks first.

On Peios the only thing worth authorising about a port is the claim — binding a non-zero port — and it is authorised the way everything else is: by a security descriptor. CAP_NET_BIND_SERVICE is in the always-allow set (DAC Neutralisation), so the Linux floor never refuses first, and every claim reaches security_socket_bind(), where KACS decides.

The precedent is not Linux but HTTP.sys's URL reservations on Windows: a sparse table of namespace prefixes, each carrying a descriptor, consulted when a name is claimed, default-permissive where nothing is reserved. This chapter moves that model down to the port layer.

The object #

A reservation is a selector mapped to a descriptor. The selector names a set of protocols and an inclusive port range:

<proto>[,<proto>]:<lo>[-<hi>]      proto ∈ tcp | udp | *

tcp:80, udp:53, tcp,udp:1-1023, *:8080. Ports are decimal, 1–65535, no leading zeros, lo <= hi; a protocol may not repeat, so every selector has one spelling. The address family is deliberately not part of the selector: a reservation covers IPv4 and IPv6 alike, or dual-stack squatting — claiming the v6 side of a port reserved on v4 — would bypass it.

The rights are those of <pkm/net.h>:

RightGrants
KACS_PORT_BIND (0x00000001)bind(2) to any port the selector contains
READ_CONTROLreading the descriptor

That is the whole mask. Editing a reservation is a registry write, governed by the registry key's own descriptor — one edit policy for the table — so WRITE_DAC and WRITE_OWNER inside a port descriptor mean nothing and are never honoured. The generic mapping is GENERIC_EXECUTE → PORT_BIND, GENERIC_READ → READ_CONTROL, GENERIC_WRITE → nothing, GENERIC_ALL → both.

The table #

Reservations live as values under one registry key:

Machine\System\Network\TcpIp\PortReservations\
    @                 REG_BINARY   SD     the default reservation
    tcp,udp:1-1023    REG_BINARY   SD
    tcp:80            REG_BINARY   SD

Each value's name is its selector and its data a self-relative descriptor. The key's unnamed default value, @, is the default reservation: the descriptor for every port no selector contains. The shipped seed grants PORT_BIND to Everyone on @ — an unreserved port is anyone's, as on Windows — and to SYSTEM and the bind-low-ports capability SID on tcp,udp:1-1023, which is the Linux convention restated as policy. Services then carry their own entries: tcp:80,443 → NT SERVICE\httpd: PORT_BIND, which composes with per-service SIDs so that a compromised sshd cannot take 443 even though both are "privileged".

The kernel reads the key whole and rejects it whole. Every name must parse, every descriptor must parse, exactly one @ must exist, and no two selectors of equal width may overlap — the most specific match would be ambiguous, and the kernel refuses to guess. On any failure the load is audited and the previous table stays in force. The rejection is recorded as kacs.config.value.rejected (Audit Event Schemas): config.key.path names the key, config.name the value at fault where one is, and outcome.reason why — empty, too-large, bad-selector, bad-descriptor, duplicate-default, missing-default or overlap — with policy.previous-retained true and policy.fallback saying whether what stayed in force is the compiled-in table. Nested overlap, and overlap between selectors of different widths, is how specificity works and is accepted.

The decision #

At bind(2) on an AF_INET or AF_INET6 socket whose protocol is TCP, UDP or UDP-Lite:

  1. If the requested port is 0 — ephemeral allocation — nothing is checked. Protocols no reservation covers (SCTP, raw) pass untouched.
  2. The most specific reservation containing (protocol, port) is selected: the one covering the fewest ports, regardless of how many protocols it names. None → the default reservation.
  3. The caller's effective token is evaluated against that descriptor for PORT_BIND, through the ordinary AccessCheck pipeline (AccessCheck Overview) with PIP context, privilege-use marking and audit events — a port descriptor may carry a SACL, and its decisions surface through the same KMES stream as any other object's, with object.kind socket.
  4. Deny → -EACCES. Grant → the bind proceeds, and the caller's token is recorded on the socket as its binder.

An explicit bind(2) before an outbound connect(2) meets the same rule; it is not special-cased.

Rebinding. Binding onto a port that is already bound — with SO_REUSEADDR or SO_REUSEPORT — is still a bind(2) and still meets the reservation. The rule beyond that is that the new binder's user SID must equal the existing binder's, or the caller must hold SeTcbPrivilege: rebind is a property of the current binding, not of policy, and a right on the reservation that let one principal rebind onto another's port is a thing nothing legitimately needs. The binder recorded on each socket is what makes that comparison local; the comparison itself is applied where the stack resolves bind conflicts, and Linux already applies the same-owner half of it for SO_REUSEPORT by comparing the sockets' projected UIDs.

Before the registry #

The table comes from the registry through the same self-configuration path LCS uses for its own limits (The Bootstrap Problem): read at the first source's registration, then watched, so a change to the key is live without a restart. Until the first successful load — early boot, or a registry that never becomes available — a compiled-in fallback answers: owner and group SYSTEM, one entry granting SYSTEM PORT_BIND, nobody else. It is stricter than the shipped seed on purpose: nothing but system components should be claiming ports before the registry exists.

The fallback is replaced, never merged. The moment the key loads it is the sole authority; if a later load is rejected the last good table stays, not the fallback. Effective policy therefore never depends on boot timing.

What this retired #

SeBindPrivilegedPortPrivilege (bit 63) was the KACS privilege CAP_NET_BIND_SERVICE mapped to before this object existed. A reservation's grant is an ACE, and an ACE names a SID, not a privilege; keeping the privilege would have been a second authorisation path around the descriptor. It is retired and its bit is not reused. Low ports are granted through the capability SID on the 1-1023 reservation, which reaches a token by confinement — peinit for a service, or positive confinement from the authority at logon for a user.

Tracing #

Every decision emits kacs:kacs_socket_bind with reason port-bind: desired carries PORT_BIND, max_imp carries the port, and ret the verdict. Table loads emit reason port-table. See Appendix 3.C for the audit events an evaluated descriptor's SACL can produce.

Socket Identity

Peios Kernel / Internals / KACS / Network objects

Network policy speaks of programs, and a packet carries no program. What carries one is the socket: KACS records on every AF_INET and AF_INET6 socket the identity that governs its traffic, and the network policy engine (Chapter 6, The identity facts) reads it at the first judgment of each flow. AF_UNIX sockets carry the peer-identity machinery of Impersonation Levels instead and are not stamped.

The stamp #

The stamp is the caller's effective token — the impersonation token during impersonation, the primary otherwise — held by a counted reference, together with the process facts of that moment: the process GUID (PSB Fields), the thread-group id, and the task's comm. Choosing the effective token means a service thread acting for a client attributes the socket to the client, exactly as file creation and audit do under impersonation; the service's own identity is then not on the socket for that flow.

It is taken at every act that commits the socket to a role, and the last one governs:

ActWhere
creationsocket_post_create; a kernel socket (sock_create_kern) is stamped as the kernel's, with no token
bind(2)after the port reservation permits it (Port Reservations)
listen(2)socket_listen
connect(2)socket_connect
accept(2)sk_clone_security: the child inherits the listener's stamp, its own reference
KACS_SO_RESTAMPany state: the caller's effective identity replaces the stamp

Restamping is what makes a hand-off well defined. A listener opened by one program and passed to another — socket activation, a descriptor store, a broker — is governed by whichever program last committed it, and a program that receives a socket it did not create can say so explicitly with KACS_SO_RESTAMP, self-gated like every attestation of one's own identity. Sockets that never pass through these hooks (a task with no token in early boot) read as unstamped, which the engine treats as the kernel's and confesses.

Reading it #

The engine reads the stamp with pkm_kacs_socket_owner() (<linux/peios_ntfe.h>): a counted token reference the caller releases with pkm_kacs_socket_owner_put(), and a copy of the kind, GUID, pid and comm. The copy is what makes the facts outlive the process; the reference is what makes them outlive the socket — a flow keeps its identity for its life (The identity facts) even after the socket that started it is gone. The fields live under their own lock, taken with bottom halves disabled, because both the accept path and the engine's read run in softirq context.

Final release #

Once the socket's last user is gone, KACS releases the token references and security descriptor owned by the socket. This also releases any peer, listener, binder and send-cache references; each field owns its own reference even when several refer to the same token. Final cleanup can run from an RCU callback and must not sleep or acquire the locks used to coordinate live socket users. It has exclusive ownership at this point. References already taken by a flow or another reader remain valid until that reader releases them.

Tracing #

Every stamp emits kacs:kacs_socket_token with reason owner; the max_imp field carries the kind (1 program, 2 kernel). See Appendix 3.C.

Peios Learn — documentation for Peios software.

Built with Trail.