Docs menu ▾
The kernel enforcer
genos-ebpf/src/main.rs: thirty BPF LSM programs and the maps they read, pinned in
/sys/fs/bpf/genos. The decision is made here, synchronously, before anything changes; nothing
waits for the daemon or the server.
Maps
All pinned in /sys/fs/bpf/genos with the hooks' links: the hooks keep working after the daemon
stops, and a restarted daemon reuses them.
| Map | Type | Key → value | Filled by |
|---|---|---|---|
PROTECTED |
Hash, 4096 | folder FileKey {dev, ino} → KIND_TREE or KIND_NAMES, with a WATCH flag when the place is set to watch |
Daemon, after the self-test |
ALLOWED |
Hash, 32768 | NameKey {dir: FileKey, name[256]} → NAME_SCANNED (1), NAME_APPROVED (2) or NAME_ABSENT (3) |
Daemon: scan names as 1, approved names as 2, names watched for and not there as 3; a revoke sets a scan name back to 1, removes any other |
LOCKED |
Hash, 32768 | FileKey {dev, ino} → the NameKey to report |
Daemon: every scan file not approved for changes, and the daemon's own executable |
ANCHORS |
Hash, 2048 | FileKey → {parent folder, name} |
Daemon: each protected folder and every folder above it, except / |
PKG_WINDOWS |
Hash, 64 | tgid → start time | Daemon: the top process of each approved package transaction, while it runs |
NOEXEC |
Hash, 64 | folder FileKey → 1 |
Daemon: /tmp, /var/tmp, /dev/shm, /home, /root, /run; any tmpfs counts without an entry |
PACKAGED |
Hash, 262144 | file FileKey → 1 |
Daemon: every regular file in dpkg's lists, at start and after each package transaction |
MODULES |
Hash, 8 | folder FileKey → 1 |
Daemon: /usr/lib/modules, the only place a module may be loaded from |
SETTINGS |
Hash, 64 | {folder name, file name} → 1 |
Daemon: the kernel settings whose write-opens are checked (kernelstate.rs) |
PORTS |
Hash, 4096 | port → NAME_SCANNED, NAME_APPROVED, or NAME_BOUND (4) for a scan port only its scan-time listeners may use |
Daemon: the scan's listening ports, what approved package transactions started, approved listen tickets |
ACTORS |
Hash, 8192 | ActorKey {program: FileKey, target: NameKey} → 1: the program may change that name; a target with an empty name is every guarded name in the folder; under LISTEN, a port |
Daemon: from the manifest's actor rules, an approval in a folder with helpers, and each bound port's listeners |
ACTOR_PROGRAMS |
Hash, 512 | program FileKey → PROGRAM_STRICT (may change files) or PROGRAM_LISTENER (its port only) |
Daemon: every program ACTORS names; looked up first, so other processes never build an ACTORS key |
CONTROL |
Array, 10 | slot → FileKey |
Daemon: its executable (CONTROL_DAEMON), the pin folder (CONTROL_PIN_DIR), PID 1's mount namespace (CONTROL_INIT_MNTNS), a watch flag per host-wide rule (grants, exec, kernel, settings, listen, sockets) and the first login uid (CONTROL_LOGIN_UID_MIN) |
OUR_MAPS |
Hash, 16 | map id → 1 | Daemon: the ids of the maps above |
EVENTS |
Ring buffer, 64 KiB | one Event (360 bytes) per block |
Hooks |
SCRATCH |
Per-CPU array, 1 | one NameKey |
Hooks, to build a key off the 512-byte BPF stack |
ACTOR_SCRATCH |
Per-CPU array, 1 | one ActorKey (288 bytes) |
Hooks, for the same reason |
LAYOUT |
Read-only global | struct field offsets and hook argument counts for this kernel | Daemon, at load (set_global, frozen) |
NameKey holds the full name, zero-padded: exact comparison, no hashing, no collisions. FileKey is
device plus inode, since inode numbers repeat across filesystems.
Hooks
Each hook returns an earlier BPF LSM program's refusal unchanged. A failed kernel read lets that one operation through.
| Hook | Refuses | Action reported |
|---|---|---|
inode_mknod |
A FIFO, socket or device node as a new name in a protected folder (a regular file made with mknod goes through inode_create) |
create |
inode_create, inode_symlink |
A new name in a protected folder that ALLOWED doesn't have |
create, symlink |
inode_link |
The same; and any new link to a LOCKED file, anywhere |
link |
inode_rename |
Moving an ANCHORS folder, or replacing one; touching the pin folder; moving a scan name out; moving anything over a LOCKED file or over a name not approved for changes; a new name not in ALLOWED |
folder, tamper, delete, write, rename |
inode_unlink, inode_rmdir |
Removing an ANCHORS folder, a pin, a LOCKED file, or a scan name |
folder, tamper, delete |
file_open |
An open for writing (FMODE_WRITE) of a LOCKED file, or of a file in a protected folder whose name isn't approved. Read-only opens return at the first check |
write |
file_permission |
A write through a descriptor to a LOCKED file: one opened before the file was locked (before the daemon first ran, or while its name was approved). Reads return at the first check |
write |
inode_setattr |
Truncating (ATTR_SIZE) the same files; chmod or chown of them; explicit times (ATTR_ATIME_SET, ATTR_MTIME_SET) on a LOCKED file. Then, for any regular file anywhere, a mode that adds setuid or setgid-with-group-execute, outside a package window |
write, attr, escalate |
inode_create (mode) |
A regular file created with setuid or setgid already in its mode, anywhere, outside a package window | escalate |
inode_setxattr, inode_removexattr |
An extended attribute set or removed on a LOCKED or guarded file; security.capability set on any regular file anywhere, outside a package window |
attr, escalate |
inode_set_acl, inode_remove_acl |
An ACL set or removed on a LOCKED or guarded file |
attr |
bprm_check_security |
Executing a file under a NOEXEC root (/tmp, /var/tmp, /dev/shm, /home, /root, /run) or on any tmpfs (memfd files included), or any file that is in neither PACKAGED nor LOCKED, outside a package window, unless its name is NAME_APPROVED. Files on overlayfs, squashfs and FUSE, and in another mount namespace than PID 1's, aren't checked against PACKAGED. Watch-only until the exec rule is set to block (CONTROL_WATCH_EXEC) |
exec |
bprm_check_security (traced) |
Starting a PROGRAM_STRICT program while the process is traced (task->ptrace): the tracer would act as it |
trace |
ptrace_access_check |
An access that could change a process running a PROGRAM_STRICT program (PTRACE_MODE_ATTACH): a debugger attaching, /proc/<pid>/mem, process_vm_writev. Reads of /proc return at the first check |
trace |
mmap_file |
The same for a file mapped with PROT_EXEC (a library, a memfd); anonymous mappings aren't checked. In a PROGRAM_STRICT program it blocks whatever the exec rule's mode |
map |
file_mprotect |
A file mapping turned executable after it was made (mprotect with PROT_EXEC): the file is checked as mmap_file would have. Anonymous memory isn't checked |
map |
kernel_read_file |
A module file (finit_module, compressed or not) from anywhere but under a MODULES root (/usr/lib/modules, itself a protected tree), outside a package window. Firmware, kexec images and policies aren't checked. The kernel rule blocks unless set to watch |
module |
kernel_load_data |
A module handed over from memory (init_module), outside a package window; reported as memory/module |
module |
sb_remount |
Any remount of a filesystem that is read-only now (SB_RDONLY): the hook can't see the new flags, and making it writable is what such a remount is for. Reported by mount point and filesystem type. The kernel rule |
remount |
file_open (settings) |
A write-open of a file on procfs, securityfs or selinuxfs whose folder name and own name are in SETTINGS (yama/ptrace_scope, kernel/kptr_restrict, dmesg_restrict, modules_disabled, unprivileged_bpf_disabled, core_pattern, fs/suid_dumpable, selinux/enforce, security/lockdown); inode numbers there aren't stable, so names are the key. The settings rule ships watch-only |
setting |
socket_listen |
A TCP (IPv4 or IPv6) listen on a port not in PORTS: the scan's listening ports, what approved package transactions started, and approved tickets. Port 0 is one the kernel picks at listen. On a NAME_BOUND port, a listen by a program ACTORS doesn't have for it. Reported as listen/<port>; the listen rule ships watch-only |
listen |
unix_stream_connect |
A process with effective uid 0 connecting to a filesystem stream socket owned by a login user (uid at or above CONTROL_LOGIN_UID_MIN, login.defs' UID_MIN): an ssh-agent or control socket. Abstract sockets and sockets owned by root or service accounts aren't checked, nor is the owner's own root: a process whose audit login user is the socket's owner. The sockets rule ships watch-only |
connect |
file_open (login user) |
A write-open of /proc/<pid>/loginuid by a process whose login user is already set: it could then pass for a socket's owner. With the sockets rule |
setting |
sb_mount, move_mount |
Mounting on an ANCHORS folder, a LOCKED file or a name in a protected folder, unless the mount is in another mount namespace than PID 1's and not shared (systemd's sandboxing does this for many services) |
folder, write |
sb_umount |
Unmounting a BPF filesystem (it holds the pins), except by the daemon or in a private mount namespace (systemd's sandboxing unmounts it in many services' own) | tamper |
bpf |
BPF_LINK_DETACH, except by the daemon |
tamper |
bpf_map |
A new writable fd for one of OUR_MAPS, except by the daemon |
tamper |
task_prctl |
prctl(PR_SET_MM, PR_SET_MM_EXE_FILE): naming another file as the program a process runs, which is how the hooks know the daemon and an allowed program. Refused to everyone. The whole-map form (PR_SET_MM_MAP) is refused too, and reported when it names a file |
tamper |
Allowed programs
Every hook that would refuse a change first asks two things: is an approved package transaction
making it, and does ACTORS have the current process's program for this name. The program is
task->mm->exe_file, by device and inode, the way the daemon is recognised. A change let through
this way is written to EVENTS as DEC_ACTOR, and the daemon logs it ALLOW.
- A file an allowed program renames into place takes the
LOCKEDentry as it arrives; the file it replaced, or deleted, loses its entry once it has no name left. - A script is never allowed: its process runs the interpreter.
- An allowed program's own file is
LOCKED, and its folder and those above areANCHORS. It maps no unbaselined code, can't be traced, and no process can relabel itself as it (above), so what acts under its entry is the file the scan recorded.
"The daemon" is any process whose executable is CONTROL_DAEMON (read from task->mm->exe_file).
That file is itself LOCKED, so it can't be changed or replaced while Genos runs.
| Function | Does |
|---|---|
new_name |
A new name: allowed only if ALLOWED has it |
try_rename, try_remove, try_open, try_setattr, try_create_mode, try_attr, try_setxattr, try_exec, try_mount_on |
The checks in the table above |
noexec_place |
True on a tmpfs, or with a NOEXEC root up to 24 folders above the file |
escalate, name_in |
A grant anywhere: the file's own folder (device and inode) and name go in the event, so the daemon can name the folder by file handle |
private_mount |
True if a mount is in another namespace than PID 1's and isn't shared: changing it changes nothing the host sees |
may_change |
A file in a protected folder may change only if its name is NAME_APPROVED |
may_remove |
A name may go if it is approved, or not in the baseline at all (a leftover); a scan name may not |
protected_name |
{folder, name} in this CPU's SCRATCH, if the folder is protected |
daemon |
True if the current process runs the daemon's executable |
refuse |
Writes the event (key, action, actor) and returns -1 (EPERM) |
record_actor |
Fills the event from the current task: pid, tid, ppid, uid/gid, euid/egid (from cred), audit loginuid and session, start time, cgroup, comm, boot-clock time. A field it can't read is left unset; it never changes the decision |
read_at |
Reads a kernel field at base + LAYOUT offset; an absent offset is an error |
The decision is made in the kernel, synchronously, before anything changes. Nothing waits for the daemon or the server.