Audit fallback
This page is published from the agent repository. Edit on GitHub View source
sensor-linux-audit reads the kernel audit stream
over NETLINK_AUDIT. It has two uses:
AuditSensor: the primary sensor when eBPF cannot run (no BTF, no privilege for BPF, lockdown, verifier refusal). Exec and connect only.AvcReader: SELinux AVC denials next to the eBPF sensor, because nothing else produces them.
fanotify was considered as the file-event source of this fallback and not built; the fallback has no file events.
The socket
AuditSocket::open opens a raw
NETLINK_AUDIT socket and joins the AUDIT_NLGRP_READLOG multicast group. It needs
CAP_AUDIT_READ (or root). It never sends AUDIT_SET or rule commands, so it coexists with a
running auditd instead of displacing it, and it receives only what the host's audit configuration
emits: exec and connect records appear only if audit rules generate them.
Netlink multicast delivers one copy of each record to every subscribed socket, so AvcReader and
AuditSensor do not steal records from each other or from auditd.
Parsing
parse_audit_message reads the 16-byte
nlmsghdr, takes the record type from nlmsg_type, and parses the text payload
audit(<sec>.<ms>:<serial>): key=value .... The kernel's netlink form has no type=... msg=
prefix; only auditd's log lines do. Values the kernel hex-encoded arrive unquoted; the parser
records which keys were unquoted (unquoted_fields) so only those are hex-decoded, and a quoted
value that merely looks like hex (a file named 6162) passes unchanged.
Classification
classify maps one record at a time; the sensor
joins an exec's EXECVE records first (Split argv):
| Record type | Event | Read from the record |
|---|---|---|
EXECVE (1309) | Exec | argc, a0..aN or aN[i] pieces (hex-decoded), pid/uid/gid if present |
SOCKADDR (1306) | Connect | saddr parsed as sockaddr_in/in6, pid/uid/gid if present |
AVC (1400) | PolicyDenial | scontext, tcontext, tclass, permissive, comm, requested permissions, path/name |
The AVC body starts with free text (avc: denied { read } for pid=1234 ...), which the
key=value scan folds into the first key. The requested permission set is recovered from that key
(avc_action); pid is not. path=/name=
are hex-decoded when unquoted, otherwise a file name with a space would arrive encoded. A record
without scontext and tclass is skipped.
Split argv
The kernel writes an argument that does not fit in the record as aN_len= plus pieces aN[0]=,
aN[1]=, ..., and continues a long argv in further EXECVE records with the same serial; only the
first carries argc. The sensor does not classify EXECVE records one at a time:
ExecveAssembler holds each exec's EXECVE
records, keyed by serial, and rebuilds the argv when a record of another type with that serial
(CWD) arrives. Records of execs on other CPUs can be queued in between, so several execs can be
in progress at once. The hold is bounded:
- 128 KiB of field values per exec, then further records are dropped;
- 16 execs, then the oldest is closed;
- 2 s of audit time, then an exec whose closing record never came is closed when the next record arrives.
An argv that cannot be rebuilt whole (a lost record, a short piece against aN_len, a bound hit)
is still emitted with the head that arrived and cmdline_truncated set. classify on a lone
EXECVE record flags a split exec the same way.
The drain
AuditSensor runs a current-thread tokio runtime with the socket in an AsyncFd. Readiness is
edge-triggered, so each wake-up drains up to DRAIN_BUDGET (256) records, about 36 execs at seven
records each, and leaves readiness set if the budget ran out. The socket asks for an 8 MiB receive
buffer and logs what the kernel granted. SO_RCVBUFFORCE needs CAP_NET_ADMIN, which the packaged
unit grants as an ambient capability; without it, SO_RCVBUF is capped at net.core.rmem_max and the
agent warns. The default held fewer
than ten execs with a long argument, so a burst of them was mostly dropped
(#237). Records are read into a 64 KiB buffer; a
longer one is parsed cut and counted. Errors are handled per kind:
| Condition | Behaviour |
|---|---|
| Unparseable record | skipped, counted, logged at powers of two |
ENOBUFS | the kernel dropped records (socket buffer overrun); counted, logged at powers of two, the socket keeps working |
EAGAIN | readiness cleared |
| other recv error | the sensor returns an error |
Timestamps come from the record header (seconds and milliseconds), not from the receive time.
The AVC reader
The agent opens AvcReader only when eBPF is primary
(starts_avc_reader); when AuditSensor is primary it
already classifies AVC records, and a second reader would duplicate them. On a host with SELinux
active, a failed open is reported as a degraded linux-avc source and retried; without SELinux it
is skipped quietly. AvcReader::drain uses the same 256-record budget and the same unparsed
counter, and keeps only PolicyDenial.
Limits
- One record at a time. An audit event is several records sharing a serial (
SYSCALL,EXECVE,CWD,PATH,PROCTITLE,EOE). Apart from an exec'sEXECVErecords (see Split argv), the classifier does not join them, so fields that live on theSYSCALLrecord (pid,uid,exe) are 0 or absent unless the classified record itself carries them, andimage_pathisargv[0], not the executed file. - No lineage:
ppidis always 0 andCapabilities::parent_lineageisfalse. - Connect protocol is assumed TCP.
- Split argv: an exec is emitted once its
CWDrecord (or a later one, see Split argv) arrives. An exec whoseCWDwas lost stays held until the next record or the sensor's exit. - AVC: no pid; a rare
auditallowgrant would be classified as a denial; the object path is from the AVC line alone (often a bare file name). - No file events.
Testing
Unit tests for parse, classify, the argv assembler and normalize, and a sensor-level test of
interleaved split execs through forward; a deterministic never-panic suite
(tests/robustness.rs) and a fuzz target
(audit_parse) on the parser; AvcReader is tested
over a socketpair.