Docs menu ▾
Enforcer · Daemon / updated 2026-11-09

The daemon

genos-daemon: verifies the baseline, loads the hooks for this kernel and proves they block, fills the maps, reports blocks and applies signed decisions. It never decides anything; the kernel does.

Start-up (main.rs: main)

sequenceDiagram
  participant M as main
  participant K as Kernel
  participant FS as Fleet server
  M->>M: baseline::load_baseline (baseline.json + enforcement.json)
  M->>M: additions::Approver::load, additions::load_verified
  M->>M: layout::from_kernel (offsets from /sys/kernel/btf/vmlinux)
  M->>K: load BPF program with LAYOUT, reusing maps pinned in /sys/fs/bpf/genos
  M->>M: drain EVENTS: blocks made while no daemon ran
  M->>K: CONTROL, OUR_MAPS ← its executable, the pin folder, PID 1's mount namespace, each rule's mode, map ids
  M->>K: NOEXEC, MODULES, SETTINGS ← the writable places, the module tree, the settings list
  M->>K: ALLOWED, LOCKED, ANCHORS, PORTS ← synced to the baseline and the approvals in force
  M->>K: attach and pin 28 LSM hooks (or keep the pinned ones)
  M->>K: selftest::run (scratch folders: 53 tries refused, what must work allowed)
  M->>K: PROTECTED ← the plan's folders
  M->>FS: reporter::Reporter::start (enroll once if no agent_id)
  M->>M: spawn sender thread, spawn stream thread
  M->>M: systemd-notify --ready
  loop forever
    K-->>M: poll wakes on EVENTS
    M->>M: describe each block, batch it
    M->>M: hand batch to the sender thread
  end

Any error before --ready stops the daemon; systemd restarts it. Reporting and the stream are optional: the hooks block without them. The unit starts before sysinit.target, cron, ssh and systemd-user-sessions.

main.rs

Function Does
main Start-up above, then the event loop: drains EVENTS (with ring::Ring), validates each event (name length, UTF-8, DENY or WATCH), names its folder (a protected one or one inside a tree; any folder by file handle for a grant; memfd, memory and listen for the special ones; a setting's folder from its name; for folder, the folder above a protected one; genos for Genos itself), logs it, calls actor::describe, sends the batch to the sender thread, then poll()s the ring fd. No timer
sync Makes a map hold exactly what it should: adds first, then removes the rest, so nothing that should be there is ever missing
anchors_of Each protected folder and every folder above it (but /), with how a block on it is reported
file_key stat → FileKey, converting st_dev to the kernel's device encoding
key_for (folder path, name) → NameKey using the folder's inode from the manifest
remember Stores ticket refs the server returned for reported blocks in raised-tickets.json (max 4096)
StreamNode::apply Stream callback for an addition → apply_update
StreamNode::remove Stream callback for a removal → apply_removal
StreamNode::status Health check answer: hooks attached, baseline version, additions in force, uptime, version
apply_update additions::check; on New: record first (additions::append), then ALLOWED ← NAME_APPROVED and the file out of LOCKED; logs BASELINE vN: added; drops the ticket from raised
apply_removal additions::check_removal; on Remove: a scan name goes back to NAME_SCANNED and into LOCKED, any other name out of ALLOWED (an approved port out of PORTS); then additions::remove; if recording fails, re-inserts the key. Logs BASELINE vN: removed
apply_mode modes::check; records the rule's new mode (rule-modes.json), then flips its CONTROL slot (a host-wide rule) or re-syncs PROTECTED with the WATCH flag (a place). Logs RULE MODE vN: … is now …

ring.rs

Function Does
Ring::new, Ring::next Reads EVENTS directly from its mmapped pages, loading both the consumer and producer positions from the ring. aya's RingBuf assumes it is the ring's first reader, and loops forever on a ring reused from bpffs

baseline.rs

Function Does Refuses when
load_baseline Reads baseline.json and enforcement.json (then baseline-state.json, the daemon's own record since, if it fits the plan); record types must match; canonical_hash and entities_digest must be equal in both; each folder unique and still at the recorded device and inode; names valid and unique; at most 16,384 names and 2,048 folders; the scan's ports and actors Any check fails
verify_programs Keeps an actor rule's program in force only while its path holds the file recorded: the same device and inode, a regular ELF file Never: a program that fails goes out of force, logged, and the daemon starts
resolve_programs After an approved package transaction, re-reads each program's path: an unchanged file stays, a new one is taken only if dpkg owns it —
valid_name Not empty, . or ..; ≤ 255 bytes; no /, NUL, newline —

layout.rs

Function Does
from_kernel Reads /sys/kernel/btf/vmlinux and resolves every field in FIELDS
resolve For each field: offset and size from BTF. A required field (the inode, dentry, file, path, mount, super block, bpf_map and mm fields the hooks decide on) that is missing or the wrong size stops the daemon; an optional one (the task and cred fields that only describe the actor) is left absent and logged
hook_args How many arguments a hook takes, from its bpf_lsm_<hook> prototype: inode_setattr gained an idmap argument (3 on 7.3, 2 on 6.8), and bpf a kernel flag (4 on 7.3)
shared_flag Where a mount says it's shared: mount.mnt_t_flags & T_SHARED on 7.3, vfsmount.mnt_flags & MNT_SHARED on 6.8
Btf::parse, field, member, strip, size Minimal BTF reader: types section, struct/union members (through anonymous unions), typedef/const stripping, sizes. Anything unknown is an error

This is what makes one build run on 6.8 and 7.3: inode.i_ino is at offset 80 on 6.8 and 64 on 7.3.

selftest.rs

Function Does
run Creates /var/lib/genos-selftest (a tree with a scan file base, locked, and an approved one, free), a names folder, an exec folder in /tmp and an unprotected folder beside them. Tries: create, a FIFO, symlink, link, rename and mkdir in; a write through a descriptor opened before the lock; write, truncate, replace, chmod, backdate base, its attributes and ACL; delete it and move it out; link it elsewhere; move and mount over the folder; a watched name and an absent one; setuid, setgid, a setuid create and a capability in the unguarded folder; run, map, map-then-mprotect and run from memory from /tmp, and run and map an unpackaged copy; a kernel setting opened for writing; a module from memory and from a file; a remount of a read-only tmpfs of its own; a listen on a port the kernel picked, and on a bound port as another program; a connect, as root, to a socket owned by the first login uid; ALLOWED and the hooks' scratch keys opened for writing as a stranger; another file named as the program the daemon runs; the scan file written once the daemon's own actor entry is gone; unpackaged code mapped into a strict program with exec on watch; a strict program attached to, and one started under a tracer; a program in an approved package transaction attached to; an unpackaged program run in a private mount namespace; a setuid file made with O_TMPFILE linked into place; a kernel booted with kexec from memory and from an unpackaged file. 53 tries; each must fail with EPERM and produce an event with the right action and name. Then what must work: writing free, a touch to now, a setgid folder, names the names folder doesn't watch, mounts in a private namespace, the daemon opening its own map, a packaged program running and mapping, reading the setting, listening on a port in PORTS and on a bound port as its program, root's own socket, a program with an actor entry writing and replacing its file (the new file must take the lock), and a package window letting changes through. Otherwise the daemon exits: it will not run on a kernel where the hooks don't block, or block what they shouldn't

actor.rs

Function Does
describe Turns an Event into an Actor: login user (from loginuid), effective user, comm, exe and tty (if the same process is still running: same pid and start time), systemd unit, parent chain
ancestry Walks /proc/<pid>/stat parent links up to the session's first process
observed_at Converts the kernel's boot-clock timestamp to wall-clock epoch seconds
Users::name uid → name from /etc/passwd, reloaded on a miss

reporter.rs and pinned_transport.rs

Function Does
Reporter::start Reads agent.toml and the key; enrolls if agent_state.json doesn't exist
enroll POST /v1/enroll with the one-time token, the public key and hostname; stores the returned agent_id
Reporter::send_events Sends blocks in chunks; returns the ticket refs the server opened
Reporter::post Builds a signed envelope (agent_id, seq, nonce, sent_at, kind, body), persists the new seq before sending (no replay after a crash), POSTs it
Reporter::sign_hello Signs the stream challenge with the host key
pinned_client_config / build_pinned_agent TLS with normal certificate validation and the server's SPKI pin; redirects refused

stream.rs

Function Does
run Holds the stream for the life of the daemon: connect, session, on any error log and reconnect with backoff 1 s → 5 min plus jitter. Never returns, never panics
connect TCP + pinned TLS + WebSocket handshake to wss://<server>/v1/stream; 90 s read timeout
session Answers the challenge with a signed hello, waits for welcome, then serves messages: addition → Node::apply → applied/rejected; removal → Node::remove → removed/rejected; mode → Node::set_mode → mode_set/mode_rejected; health → status. Anything else is ignored

additions.rs

Function Does
Approver::load Reads the 32-byte approver public key
Approver::verify / verify_removal Ed25519 strict verify over genos.baseline_addition/1 \n agent \n ticket \n dir \n name (or ..._removal/1)
check An addition is New only if: addition record, this host, signature valid, and the ticket is in raised with the same folder and name. Already applied → Already(version). Else rejected
check_removal A removal is accepted only if: removal record, this host, signature valid, and the ticket's addition in force has the same folder and name → Remove(i). No addition of that ticket → Absent(version) (nothing to do)
Record::version 1 + every change: the highest version among additions and removals, or 1
load_verified Loads the record; drops (and logs) any addition whose signature doesn't verify or whose folder isn't protected
append / remove Write the new record atomically (temp file, fsync, rename, fsync dir), 0600

guard.rs, pkg.rs, modes.rs, kernelstate.rs

Module Does
guard.rs Works out what the maps should hold from the plan, the actor rules and the approvals (Guard::want): an approval in a folder with helpers becomes ACTORS entries for them, not an approved name; each allowed program is locked; a scan port with listeners is bound to them. Locks what an allowed program left in place (relock), re-lists the plan's folders after a package transaction or when a watched folder is made (refresh), and names a folder a block reports: a plan folder, one inside a tree, a writable place, a mount point, or any folder by file handle (dir_by_handle)
pkg.rs The package gate: dpkg's pre-invoke hook asks on a local socket, the daemon raises a ticket named after the top process, and once approved puts that process in PKG_WINDOWS until it exits, then lists the baseline again and records the next version
modes.rs Rule modes: a signed, versioned watch or block per protected place or named rule, recorded before it reaches the kernel; exec, settings, listen and sockets watch until told to block, the rest block until told to watch
kernelstate.rs The module tree, the nine checked settings (keyed by folder and file name, since procfs inode numbers aren't stable), listening ports from /proc/net/tcp after a transaction, the first login uid from login.defs

Changing the baseline after install

sequenceDiagram
  participant A as Admin
  participant FS as Fleet server
  participant D as Daemon
  participant K as Kernel
  Note over K: tee /etc/cron.d/job → EPERM, event
  K-->>D: Event
  D->>FS: POST /v1/events (signed)
  FS-->>D: ticket ref → raised-tickets.json
  A->>FS: Approve
  FS->>D: addition, signed by approver key
  D->>D: check, append (vN)
  D->>K: ALLOWED.insert(cron.d inode, "job")
  D->>FS: applied vN
  A->>FS: Revoke (or Restore install baseline = revoke all)
  FS->>D: removal, signed by approver key
  D->>K: ALLOWED.remove(cron.d inode, "job")
  D->>D: remove from record (vN+1)
  D->>FS: removed vN+1

View this page on GitHub ↗