# 05 — eBPF-Jev: 21 KB Recurrent Decision Model Inside Linux 6.12 eBPF LSM A fixed-point INT8 recurrent neural network (`21,280 B`) running directly inside four Linux `6.12.118` eBPF LSM hooks (`lsm/task_alloc`, `lsm/bprm_check_security`, `lsm/file_open`, `lsm/socket_connect`) to detect and block multi-step secret exfiltration with `-EPERM` before a single packet leaves the machine. - **0 floats**, **0 tail calls**, **0 userspace round-trips** - **21,457 processed instructions** in the real Linux `6.12.118` eBPF verifier (limit: `1,000,000`) - **5.65 µs** median hook latency (**12.25 µs** p99) over 10,000 live UDP `connect()` syscalls - **32-byte recurrent state `h[32]`** stored in `BPF_MAP_TYPE_TASK_STORAGE`, inherited across `fork()` and `execve()` - **Double-buffered atomic weight hot-swap** (`models_map[2]`, generation counter + reader reference count) with zero reboot and zero hook reload - **500/500 bit-exact (`0-LSB`) parity** between Python fixed-point reference, userspace C, and live in-kernel eBPF --- ## Architecture ```text lsm/file_open ──┐ lsm/bprm_exec ──┼──► x[32] (16 kernel features + 16-d FNV-1a 3-gram emb) lsm/connect ───┘ │ ▼ concat(x[32], h_prev[32]) -> in[64] │ Layer 1: 64 -> 64 INT8xINT8 + INT32 bias + shift + ReLU ├──► h_next[0..31] -> BPF_MAP_TYPE_TASK_STORAGE │ ▲ (copied on lsm/task_alloc across fork()) ▼ Layer 2: 64 -> 4 INT8 -> 256-B Calibrated Sigmoid LUT │ ▼ [ exfil_risk | evasion_chain | benign_dev | uncertainty ] │ ┌────────────┴────────────┐ ▼ ▼ ALLOW (0, fast path) DENY (-EPERM, 0 bytes leaked) │ └──► BPF_RINGBUF -> live HUD / 10s CPU align -> atomic hot-swap ``` ### Linux 6.12.118 eBPF Verifier Statistics | Hook | Verified Instructions | Verifier Limit | Notes | |---|---:|---:|---| | `lsm/task_alloc` | **74** | 1,000,000 | Copies `h[32]` and taint metadata from parent to child task storage | | `lsm/bprm_check_security` | **5,775** | 1,000,000 | Scores resolved executable + hashed 3-gram filename, updates `h[32]` | | `lsm/file_open` | **6,035** | 1,000,000 | Filters by registered `(dev, ino)`, advances `h[32]` on config/protected opens | | `lsm/socket_connect` | **21,457** | 1,000,000 | Runs full `64 -> 64 -> 4` recurrent pass, enforces `-EPERM` synchronously | --- ## Benchmarks ### 1. Held-Out Evaluation (`3,840` Unseen Multi-Step Workflows, 24 Disjoint Families) All models are evaluated on identical unseen process chains mixing normal dev servers, `.env` loads to approved endpoints, multi-hop `fork`/`exec` evasion chains, and ambiguous/stale histories: | Model / Policy | Size | False Denies / 1,000 | Strict-Gate Recall | Evasion F1 | ECE | |---|---:|---:|---:|---:|---:| | `rule_fsm` (block after secret read) | — | 500.0 | 100.0% | — | 0.300 | | `rule_strict` | — | 752.0 | 100.0% | — | — | | `oblivious_gbdt` (32 trees, depth 4) | 1,284 B | **0.0** | 50.0% | 0.800 | 0.0008 | | `stateless_mlp` (no `h[32]` carry) | 21,280 B | **0.0** | 50.0% | 0.800 | 0.010 | | **`recurrent_jev` (in-kernel `h[32]`)** | **21,280 B** | **0.0** | **75.0% (+25 pp)** | **0.947** | **0.025** | On the matched application holdout (`1,536` workflows after 10-second CPU alignment), `recurrent_jev` scores **0 false denies / 1,000**, **100% recall**, and **ECE 0.0025**. Full breakdown: [`ml/out/eval_report.md`](ml/out/eval_report.md). ### 2. Live Kernel Latency (`10,000` UDP `connect()` Calls, Linux `6.12.118` KVM) | Mode | Hook p50 | Hook p99 | Full Syscall p50 | |---|---:|---:|---:| | `noop` (uninstrumented baseline) | 0.65 µs | 0.72 µs | — | | `rule_fsm` | 1.07 µs | 1.14 µs | — | | `oblivious_gbdt` | 2.81 µs | 3.06 µs | — | | `stateless_mlp` | 5.34 µs | 11.94 µs | — | | **`recurrent_jev` (`21 KB INT8`)** | **5.65 µs** | **12.25 µs** | **11.95 µs** | --- ## Repository Layout ```text 05-ebpf-jev/ ├── Makefile # Builds BPF object, libbpf skeleton, warden, parity_check ├── SPEC_CONTRACT.md # Frozen binary weight pack & fixed-point math contract ├── bpf/ │ ├── ebpf_jev.bpf.c # 4 LSM hooks + bpf_loop INT8 forward pass + ringbuf telemetry │ └── ebpf_jev_common.h # Shared weight pack, task state, and event structs ├── src/ │ ├── warden.c # Userspace loader, cgroup/inode registry, --reload-weights hot-swap │ ├── parity_check.c # C bit-exact parity checker against ml/out/parity_vectors.json │ └── latency.c # 10,000-call UDP connect latency harness ├── ml/ │ ├── generate_dataset.py # Synthetic multi-step dev/exfil workflow generator │ ├── neural.py # Fixed-point INT8 recurrent model & calibrated LUT training │ ├── trees.py # Oblivious GBDT comparator │ ├── align.py # 10-second CPU-only alignment for live false-deny / OOD recovery │ ├── train_and_eval.py # End-to-end training, quantization, and holdout evaluation │ ├── evaluate.py / report.py / parity.py / fixed_point.py │ └── out/ # Pretrained 21 KB INT8 pack, GBDT pack, 500 parity vectors, eval report ├── demo/ │ ├── tui_hud.py # Live curses kernel HUD (event feed, 4-head bars, h[32] hex, counters) │ ├── listeners.py # Loopback approved (:19998) and unapproved (:19999) UDP receivers │ ├── 1_dev_normal.py # Config read -> approved :19998 (ALLOW) │ ├── 2_dev_env_local.py # Dummy .env read -> approved :19998 (ALLOW) │ ├── 3_exfil_fork_chain.py # Dummy .env -> fork/exec python3 -> :19999 (BLOCKED -EPERM) │ └── 4_hotswap_weights.sh # Live atomic reload gen #1 -> gen #2 └── testbed/ ├── build.sh # Builds disposable Debian trixie Linux 6.12 KVM image (CONFIG_BPF_LSM=y) ├── start_demo_vm.sh # Launches interactive split-screen shell + live HUD inside KVM ├── stop_demo_vm.sh # Clean teardown of demo KVM and tmux session ├── verify_demo.py # Automated 7-check KVM acceptance suite └── README.md # Detailed KVM testbed & alignment notes ``` --- ## Quick Start (Linux KVM Testbed) All demos and tests run inside an isolated, network-less QEMU/KVM guest (`-nic none`, loopback only) with inert dummy fixtures. ### 1. Build the Linux 6.12 KVM Guest Image (requires Docker + sudo + KVM) ```bash cd 05-ebpf-jev bash testbed/build.sh ``` ### 2. Run Automated Verification (Verifier + 500/500 Parity + Latency + 7 Live KVM Checks) ```bash testbed/run_vm.sh verify python3 testbed/verify_demo.py ``` ### 3. Launch the Interactive Split-Screen Demo ```bash testbed/start_demo_vm.sh # Left pane: monitored guest shell | Right pane: live eBPF HUD # Stop & reset cleanly: testbed/stop_demo_vm.sh ``` Inside the monitored shell (`jev /work $`), you can run either the 4 scripts or raw commands directly: ```bash # 1. Plain config read -> [CLEAN] cat /tmp/ebpf-jev-demo/config.yaml # 2. Plain secret read -> [TAINT] (opens=1, h[32] updated in ~13.5 us) cat /tmp/ebpf-jev-demo/dummy_secret.env # 3. Secret read + approved local service (:19998) -> ALLOW python3 -c 'from socket import *; open("/tmp/ebpf-jev-demo/dummy_secret.env").read(); s=socket(AF_INET,SOCK_DGRAM); s.connect(("127.0.0.1",19998)); s.send(b"health"); print("ALLOWED:", s.recv(16))' # 4. Subshell reads .env -> execs clean python3 -> unapproved :19999 -> BLOCKED (-EPERM, 0 bytes) ( read -r s < /tmp/ebpf-jev-demo/dummy_secret.env; echo "Stolen: $s"; python3 -c 'from socket import *; socket(AF_INET,SOCK_DGRAM).connect(("127.0.0.1",19999))' ) # 5. Live atomic weight hot-swap (gen #1 -> gen #2) src/warden --reload-weights /tmp/ebpf-jev-demo/generation-2.bin ``` ### 4. Retrain / Re-Align Weights on CPU (Optional) ```bash python3 ml/generate_dataset.py CUDA_VISIBLE_DEVICES="" python3 ml/train_and_eval.py ``` --- ## License MIT License. See [../LICENSE](../LICENSE).