BPF LSM program
The daemon enforces through one BPF object, src/bpf/lota_lsm.bpf.c, attached to LSM hooks, tracepoints and function entries. It refuses what the startup policy and Configuration refuse, guards the agent and the protected processes (Protected processes), and records what the agent measures. The definitions it shares with user space are in include/lota.h; the loader is src/agent/bpf_loader.c.
Loading
The loader reads the object and its detached signature,
<object>.sig, checks the signature against the enforcement public key,
and opens the verified bytes from memory, so a file changed after the check
is not what loads. A refused signature or layout ends the start before PCR
14 is touched (Agent lifecycle).
After the load, in this order:
lota_task_authgetsLOTA_TASK_AUTH_ADMINandLOTA_TASK_AUTH_AGENTon the daemon's thread group leader, and the map is frozen. The flags are read on a task's group leader, so every thread of the daemon is the agent and no other process can become it.lota_configgetsLOTA_CFG_LOCK_BPF(The bpf syscall).integrity_cfgrecords whether module signatures are enforced and lockdown is atintegrityor above. When either is off the daemon logsKernel integrity baseline not met (...); module and firmware loads are refused in every mode.guarded_filesgets thecgroup.killandcgroup.freezefiles of the agent's cgroup and its ancestors, and is frozen. With no unified cgroup hierarchy, or no such file, the map is frozen empty.The startup policy writes
lota_config(Mode and switches).Each program is attached. The start fails when one does not attach, or when any of
lota_ptrace_access_check,lota_agent_exit,lota_no_core,lota_agent_moved,lota_stop_enterandlota_stop_leaveis missing from the object.
Mode and switches
lota_config holds the mode, five switches of lota.conf and
LOTA_CFG_LOCK_BPF. The startup policy writes them, and a reload writes
the changed ones:
Key |
|
Effect |
|---|---|---|
|
|
|
|
|
Executable mappings of a protected process; trusted libraries. |
|
|
|
|
|
Anonymous executable memory of a protected process. |
|
|
|
|
|
Modules and firmware outside |
|
none |
LOTA maps and links closed to other processes. |
The five lota.conf switches take effect only in enforce mode; in
monitor mode they change nothing. LOTA_CFG_LOCK_BPF and the rules
that guard the agent, the protected processes and the kernel hold in both
modes.
Hooks
A hook refuses with -EPERM, but lsm/task_alloc when it cannot
store a mark. A kernel path that asks ptrace_access_check returns its
own error: an open of /proc/<pid>/mem fails with EACCES.
Execution and kernel input
lsm/bprm_check_securityReads the fs-verity digest of the file. In
enforcemode withstrict_execit refuses a script starting with#!, an interpreter a binfmt handler hands the exec to, an exec through a descriptor, and a file whose digest is missing or not inallow_verity. EmitsEXECorEXEC_BLOCKED.lsm/kernel_read_file,lsm/kernel_load_dataRule on modules, firmware, kexec images, IMA policy and certificates with
lota_kread_denied()(Verdict functions). EmitMODULE_LOADorMODULE_BLOCKED.lsm/bprm_committed_credsNotes in
born_protectedthat a protected process executed its current image under protection.lsm/task_fix_setuidEmits
SETUIDwhen the real uid changes. Refuses nothing.
Memory mappings
lsm.s/mmap_file,lsm/file_mprotectRecord an executable mapping of a file: in
mapped_seenfor every process, inexec_historyfor a protected one. Memory with no file behind it, a/dev/zeromapping, SysV shared memory, and an unlinked tmpfs or hugetlbfs file count as anonymous; withblock_anon_execa protected process is refused them (ANON_EXEC_BLOCKED). Withstrict_mmapa protected process is refused an executable mapping that is writable, or whose file is neither inallow_veritynor a trusted library (MMAP_EXEC,MMAP_BLOCKED). The last refused object is kept inlota_refusal.
Files and mounts
lsm.s/file_openRefuses, in every mode:
/dev/mem,/dev/kmemand/dev/port;an entry of
/proc/<pid>that reads the memory of the agent, or of a protected process from outside its instance (PTRACE_BLOCKED); the agent's reads and a process's reads of itself pass;a write open of a guarded cgroup file to all but the agent (
KILL_GUARD_BLOCKED);a write open of a file in
mapped_exec(MAPPED_WRITE_BLOCKED).
In
enforcemode withstrict_mmapit refuses a write open of a trusted library.O_WRONLY,O_RDWRandO_TRUNCcount as write.lsm/path_truncateRefuses a truncate of a file in
mapped_exec, and of a trusted library understrict_mmap.lsm/sb_mount,lsm/move_mountIn
enforcemode withstrict_mmap, refuse amount(2)withMS_BINDorMS_MOVEand amove_mount(2)onto a trusted library (MOUNT_BLOCKED).lsm.s/file_post_openAnswers the agent's questions in
exe_hash_slots: the file's IMA hash, or whether a pin holds (Runtime image measurement).
Processes and signals
lsm/ptrace_access_checkRules with
lota_ptrace_denied()and emitsPTRACEorPTRACE_BLOCKED. An access inside one instance is recorded ininstance_actors.lsm/task_killRules with
lota_signal_denied()on a signal at the agent or a protected process, and emitsKILLorKILL_BLOCKED. A signal inside one thread group, from the agent, or a parent-death signal is not judged.lsm/file_send_sigiotaskRules with
lota_sigio_denied()on a signalF_SETOWNaims at the agent or a protected process, with the sender counted as outside the instance and none of the exceptions oflsm/task_kill, and emitsKILL_BLOCKEDwhen it refuses.lsm/task_setrlimitRefuses a change to the limits of the agent, and of a protected process from outside its instance (
KILL_BLOCKED).lsm/task_allocMarks a child of a protected process before it first runs, and refuses the clone when the mark cannot be stored or
lota_clone_refused()says so.tp_btf/signal_deliverEnds a protected process with
SIGKILLwhen a core-dumping signal it does not handle is delivered (KILL_BLOCKED).tp_btf/sched_process_exitWhen the agent's thread group exits, sends
SIGKILLto every protected process.lsm/task_freeRemoves a protected process from
protected_pidswhen its group leader is freed.
Sockets
lsm/socket_post_create,lsm/socket_bind,lsm/socket_listenMark a unix socket a process of an instance created, bound or listens on.
lsm/unix_stream_connect,lsm/unix_may_sendRecord in
instance_actorsa process outside the instance that connects or sends to a marked socket. Refuse nothing.
Cgroups
fentry/cgroup_attach_taskA move of the agent to another cgroup ends every protected process and the agent before the move takes effect (
AGENT_MOVED).fentry/cgroup_enter_frozen,fexit/cgroup_leave_frozenAdd the time a thread of an instance stands stopped to
instance_stopsof the instance root (Protected processes).
The bpf syscall
With LOTA_CFG_LOCK_BPF set, in every mode, lsm/bpf_map refuses a
descriptor of a map the object declares in .maps to all but the agent,
and lsm/bpf refuses BPF_LINK_DETACH. The hook compares the map's
address with those maps, so a map of another program with the same name
stays open, and so does the frozen map of the object's string constants.
Maps
Map |
Type |
Contents |
|---|---|---|
|
ring buffer, 256 KiB |
Events; the agent reads them. |
|
array |
|
|
array |
Mode and switches; written by the agent. |
|
array |
Module signature enforcement and lockdown, written at load. |
|
array |
One emission window per event type (Event budget). |
|
task storage |
The agent's flags, written at load and frozen. |
|
task storage |
The instance root a process inherited. |
|
task storage |
Set by |
|
task storage |
Stopped threads and stopped time of an instance root. |
|
task storage |
The last refused mapping and its time. |
|
per-CPU array |
Scratch space for a digest. |
|
hash, 1024 |
Protected processes: TGID to start time in clock ticks; written by the agent. |
|
hash, 512 |
Trusted libraries by device and inode ( |
|
hash, 64 |
Guarded cgroup files, written at load and frozen. |
|
hash, 16384 |
Files the agent pinned while they are mapped. |
|
LRU hash, 65536 |
Size and change time of each file seen mapped executable. |
|
hash, 65536 |
Executable mappings of protected processes. |
|
socket storage |
The instance a unix socket belongs to. |
|
hash, 4096 |
Actors of each instance. |
|
hash, 1024 |
Allowed fs-verity digests, SHA-256 or SHA-512 ( |
|
hash, 64 |
One question per agent thread for |
Device numbers in the keys of trusted_libs, guarded_files and
mapped_exec use the kernel's layout (include/lota_devt.h).
Events
Each event is a struct lota_exec_event. Every type sets
timestamp_ns, pid, tgid, uid and comm; uid is 0 on
the module types. Beyond those:
Type |
Fields |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Other |
As the base type |
LOTA_EVENT_FLAG_PROTECTED marks a mapping by a protected process,
which the agent measures again; LOTA_EVENT_FLAG_INSIDE_INSTANCE a
ptrace access within one instance.
The agent writes each event to the journal at info, AGENT_MOVED at
warn (src/agent/event.c); most types as:
[TIMESTAMP] TYPE COMM: FILENAME (pid=P, uid=U)
Event budget
In enforce mode each type has a one-second window: 256 events of a
permitted type, 1024 of a refused one. MOUNT_BLOCKED,
KILL_GUARD_BLOCKED, MAPPED_WRITE_BLOCKED and the PTRACE_BLOCKED
of an open take the refused cap in both modes; SETUID and
AGENT_MOVED have none. In monitor mode the other types are emitted
without a cap. Past 75% of the ring, a type under a cap that emitted 8 in
the window yields to quieter ones (include/lota_event_budget.h).
Statistics
stats counts executions, mappings, refusals, ptrace access checks,
events sent, ring-buffer drops, events suppressed or yielded by the budget,
signal-0 probes, and the entries exec_history,
instance_actors and instance_stops could not store. When the daemon
leaves its event loop it logs them on one line that starts Shutdown
statistics: exec=, without the suppressed events, STAT_EXEC_BLOCKED,
STAT_ANON_EXEC and STAT_ANON_EXEC_BLOCKED.
Verdict functions
The decisions of the hooks are plain functions in include/lota.h, compiled into the object and into the unit tests alike.
-
int lota_kread_is_module(unsigned int id)
Whether a purpose names a kernel module.
Parameters
unsigned int idenum kernel_read_file_id, as LOTA_KREAD_*.
finit_module(MODULE_INIT_COMPRESSED_FILE) reads under the compressed purpose, any other module read under the plain one.
Return
1 for a module purpose, 0 otherwise.
-
int lota_kread_is_known(unsigned int id)
Whether a purpose is on the list above.
Parameters
unsigned int idas for
lota_kread_is_module().
One above the list comes from a newer kernel and may be a module load, so
lota_kread_denied()refuses it under strict module loading.Return
1 up to LOTA_KREAD_MAX_KNOWN, 0 above it.
-
int lota_kread_is_watched(unsigned int id, int from_file)
Whether the gate rules on a purpose.
Parameters
unsigned int idas for
lota_kread_is_module().int from_filekernel_read_file, else kernel_load_data. A certificate is watched only in the second.
Return
1 when the gate rules on
id, 0 when it passes unjudged.
-
int lota_kread_denied(unsigned int id, int from_file, int policy_on, int strict_modules, int baseline_ok, int verity_allowed, int foreign_userns)
Verdict on what the kernel takes in on its own behalf.
Parameters
unsigned int idas for
lota_kread_is_module().int from_filekernel_read_file, else kernel_load_data.
int policy_onThe mode is enforce.
int strict_modulesThe strict_modules setting.
int baseline_okModule signature enforcement and lockdown are both on.
int verity_allowedThe file's fs-verity digest is on the allow_verity list.
int foreign_usernsThe caller is outside the initial user namespace.
Integrity holds in every mode:
kexec replaces the measured kernel, and is refused;
a user namespace other than the initial one takes in nothing watched;
a module or firmware load needs module signature enforcement and lockdown.
strict_modules is policy and applies in enforce only:
a module or firmware read from a file needs an allow_verity digest;
one handed over from memory has no file to check, and is refused;
a purpose not on the list is refused.
An IMA policy read from a file is always allowed.
Return
1 to deny, 0 to allow.
-
int lota_ptrace_is_attach(unsigned int ptrace_mode)
Whether an access asks to trace the target.
Parameters
unsigned int ptrace_modePTRACE_MODE_* bits the hook was given.
Return
1 when
ptrace_modecarries PTRACE_MODE_ATTACH, 0 otherwise.
-
int lota_ptrace_agent_read_exempt(unsigned int ptrace_mode, int actor_is_agent)
Whether an access is the agent's own read.
Parameters
unsigned int ptrace_modeas for
lota_ptrace_is_attach().int actor_is_agentThe caller is the agent.
procfs checks the agent's reads of /proc/<pid>/exe and maps with PTRACE_MODE_READ. Refused, they leave a protected process unmeasured.
Return
1 for a read by the agent, 0 otherwise.
-
int lota_ptrace_denied(unsigned int ptrace_mode, unsigned int lota_mode, int block_ptrace, int target_is_agent, int target_is_protected)
Verdict on a ptrace access.
Parameters
unsigned int ptrace_modeas for
lota_ptrace_is_attach().unsigned int lota_modeLOTA_MODE_*.
int block_ptraceThe block_ptrace setting.
int target_is_agentThe target is the agent.
int target_is_protectedProtected, and the actor is outside its instance.
The caller has settled the agent's read exemption.
The agent and a protected process refuse both access modes in every enforcement mode: a token speaks for an isolated process measured by an intact agent.
block_ptrace is policy over any other access: enforce only, and attach only. A read stays with the kernel's permission model, as tools such as lsof read other processes' /proc.
Return
1 to deny, 0 to allow.
-
int lota_proc_entry_reads_mm(const char *name, unsigned int len)
Whether a /proc/<pid> entry reads memory.
Parameters
const char *nameentry name, need not be NUL-terminated.
unsigned int lenbytes in
name.
mm_access()admits CAP_PERFMON past a refused READ ptrace check, so these opens are refused on their own, by the rules of the ptrace verdict. Entries that only name the process stay open.Return
1 for an entry that reads memory, 0 otherwise.
-
int lota_clone_inherits_protection(unsigned long clone_flags, int creator_protected)
Whether a new task becomes protected.
Parameters
unsigned long clone_flagsflags of the clone.
int creator_protectedThe creating task is protected.
The child is marked before it first runs and stays marked across execve. A thread belongs to its leader and takes no mark of its own.
Return
1 when the child takes the mark, 0 otherwise.
-
int lota_clone_refused(int creator_protected, int creator_traced, int tracer_protected)
Whether a traced protected process may not clone.
Parameters
int creator_protectedThe creating task is protected.
int creator_tracedThe creating task has a tracer.
int tracer_protectedThe tracer is inside the creator's instance.
A tracer attached before the process was protected stays attached, and
ptrace_init_task()links it to every child it asked for with no LSM hook.Return
1 to refuse the clone, 0 to allow it.
-
int lota_inside_instance(int actor_protected, unsigned int actor_root, unsigned long long actor_ticks, int target_protected, unsigned int target_root, unsigned long long target_ticks)
Whether an access stays inside one instance.
Parameters
int actor_protectedThe actor is protected.
unsigned int actor_roottgid of the root of the actor's instance.
unsigned long long actor_ticksstart time of that root.
int target_protectedThe target is protected.
unsigned int target_roottgid of the root of the target's instance.
unsigned long long target_ticksstart time of that root.
An instance is the tree one protected process started, named by that root's tgid and start time, so a recycled tgid names another instance. The wineserver ptraces processes it hosts, so being protected refuses no ptrace inside an instance: it is recorded, and only block_ptrace can refuse an attach.
Return
1 when both are protected under the same root, 0 otherwise.
-
int lota_signal_denied(int sig, int target_is_agent, int sender_inside)
Verdict on a signal.
Parameters
int sigsignal number, 0 for a probe.
int target_is_agentThe target is the agent.
int sender_insideThe sender is in the target's instance.
Self-signals, the agent, the admin identity, a parent-death signal and a signal the kernel does not count as sent from user space never reach this.
Only a probe (sig 0) and SIGHUP, its reload, reach the agent. It stops with lota-agent --shutdown.
A protected process can be ended. From outside its instance it takes no stopping signal, nor one whose default writes its memory to a core file. Inside it everything passes: the wineserver drives the processes it hosts with signals.
The mode does not change the verdict: a killed agent stops measuring without a trace.
Return
1 to refuse, 0 to deliver.
-
int lota_sigio_denied(int sig, int target_is_agent)
Verdict on a signal aimed through F_SETOWN.
Parameters
int sigsignal number, 0 for the default SIGIO.
int target_is_agentThe target is the agent.
The sender is unknown and counts as outside.
Return
as for
lota_signal_denied().
-
int lota_signal_event(int sig, int denied)
Event for a signal aimed at a protected target.
Parameters
int sigsignal number, 0 for a probe.
int deniedThe answer of
lota_signal_denied().
A permitted probe (sig 0) is not recorded: launchers poll several times a second.
Return
An enum lota_event_type, or 0 for none.
-
int lota_kill_guard_denied(int write_open, int guarded, int opener_exempt)
Verdict on opening a guarded cgroup file.
Parameters
int write_openThe open is for writing.
int guardedThe file is a guarded one.
int opener_exemptThe opener is the agent or the admin identity.
A write to it ends or stops tasks past the signal hook, so in every mode only the agent and the admin identity may open it for writing.
Return
1 to refuse, 0 to allow.
-
int lota_verity_key_from_digest_buf(const void *buf, struct lota_verity_digest_key *out)
Build an allowlist key from that buffer.
Parameters
const void *bufAt least LOTA_FSVERITY_DIGEST_BUF_SIZE wide and aligned for the header.
struct lota_verity_digest_key *outfilled on success, untouched on failure.
Return
0 on success, -1 when the reported size is not one policy enforces.