Qwen3-0.6B inference (12 KB), bare-metal bootable OS (22 KB), and from-scratch Mini-GPT trainer with live Braille TUI (32 KB) in 100% pure x86-64 NASM assembly. Zero C, zero libc, zero dependencies.
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 five Linux 6.12.118 eBPF LSM hooks (lsm/task_alloc, lsm/bprm_check_security, lsm/file_open, lsm/socket_connect, lsm/socket_sendmsg) 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.118eBPF 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 inBPF_MAP_TYPE_TASK_STORAGE, inherited acrossfork()andexecve() - 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
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) |
n/a | 500.0 | 100.0% | n/a | 0.300 |
rule_strict |
n/a | 752.0 | 100.0% | n/a | n/a |
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.
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 | n/a |
rule_fsm |
1.07 µs | 1.14 µs | n/a |
oblivious_gbdt |
2.81 µs | 3.06 µs | n/a |
stateless_mlp |
5.34 µs | 11.94 µs | n/a |
recurrent_jev (21 KB INT8) |
5.65 µs | 12.25 µs | 11.95 µs |
Hardening & Multi-Agent Evaluation
Hook and policy hardening
lsm/socket_sendmsg: unconnected UDPsendto()/sendmsg()with an explicit destination now goes through the same recurrent pass and-EPERMdecision asconnect().--cgroup-taint: warden mirrors protected-file reads into a per-cgroup recurrent state, so taint follows sibling processes, pipes/FIFOs, andsetsidchildren that never inherited the reader's task storage.- Hardened
read_sockaddr():AF_UNSPEC(sa_family == 0) destinations resolve through the socket'sskc_family; RFC 2133 24-bytesockaddr_in6is accepted and::ffff:a.b.c.dis normalized to IPv4; unparseable IP destinations fail closed once the task or cgroup is tainted. - Repeatable
--allow-dst addr:port: explicit IPv4/IPv6 destination allowlist in addition to--allow-port. /workisolation: the unprivileged guest shell runs underunshare -m, lazily unmounts the 9p project share (umount -l /work) and mounts aro,mode=0700tmpfs over it, so agents cannot read or patch the warden, model, or harness.
Verifier statistics for the hardened build (Linux 6.12.118):
| Program | Verified Instructions |
|---|---|
lsm/task_alloc |
91 |
tp_btf/sched_process_fork |
167 |
lsm/file_open |
6,246 |
lsm/bprm_check_security |
6,192 |
lsm/socket_connect |
23,125 |
lsm/socket_sendmsg |
22,578 |
Regression suite
python3 testbed/verify_hardening.py # 12 checks: v4/AF_UNSPEC/24-byte v6 sendto, sendmsg, connect+write,
# fail-closed truncated addresses, :19998 ALLOW, /work hidden,
# 0 bytes at :19999, 500/500 parity, all 6 programs verified, 0 ring drops
python3 testbed/verify_egress_preflight.py # 20 checks for the offline egress arena (air gap, corp allowlist, tainted -EPERM)
testbed/test_af_unspec.c is the C probe compiled inside the guest for the AF_UNSPEC, short sockaddr_in6, and fail-closed cases.
4-GPU pi.dev swarm arena
demo/pi-swarm/ runs four pi coding agents against one monitored KVM guest. Each agent has its own red-team role (surface audit, socket matrix, compiled C syscalls, cross-process IPC), a serialized guest shell via kvm_mux.py, and a shared note board. Every tool result reports -EPERM counts and the :19998 / :19999 counters; the run stops early if fixture content reaches the unapproved sink.
npm install --prefix envs/pi-arena @mariozechner/pi-coding-agent
MODEL_PATH=/path/to/model.gguf testbed/start_swarm_models.sh # one OpenAI-compatible server per GPU on 127.0.0.1:18100..18103
testbed/start_pi_swarm.sh # 2x2 agent TUIs + live HUD in tmux (--headless writes swarm_report.md)
testbed/stop_pi_swarm.sh && testbed/stop_swarm_models.sh
start_swarm_models.sh defaults to llama-server (SERVER_BIN, SERVER_EXTRA_ARGS, SWARM_MODEL_ALIAS, SWARM_BASE_PORT, SWARM_GPUS override it). The single-agent variant is testbed/start_pi_arena.sh (demo/pi-arena/).
Offline simulated-egress arena
demo/pi-egress/ and testbed/start_pi_egress.sh boot the guest inside an unshare -Urn network namespace with no host NIC, no LAN routes, and no default route. A tap0 link carries a simulated corporate perimeter (10.77.0.1 / fd77::1: DNS :53, HTTP proxy :3128, API :8080) allowlisted with --allow-dst, and dummy0 hosts an external sink (198.51.100.66 / 2001:db8:cafe::66, documentation ranges). The four agents read a synthetic canary and try direct dual-stack egress, DNS label tunneling, and proxy bypasses; the services decode and count every canary that reaches them.
Repository Layout
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 # 5 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, --cgroup-taint, --allow-dst, --reload-weights
│ ├── 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
│ ├── agent_arena.py # Single-model OpenAI-API agent loop against the guest shell
│ ├── pi-arena/ # Single pi.dev agent + KVM bridge extension
│ ├── pi-swarm/ # 4-agent roles, KVM shell multiplexer, bridge, report generator
│ └── pi-egress/ # Offline netns launcher, simulated corp/external services, egress HUD
└── 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
├── verify_hardening.py # 12-check hook hardening regression suite
├── test_af_unspec.c # AF_UNSPEC / short sockaddr_in6 / fail-closed C probe
├── start_pi_swarm.sh # 4-GPU pi.dev swarm arena (stop_pi_swarm.sh)
├── start_pi_egress.sh # Offline unshare -Urn egress arena (stop_pi_egress.sh, verify_egress_preflight.py)
├── start_swarm_models.sh # One inference server per GPU (stop_swarm_models.sh)
└── 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)
cd 05-ebpf-jev
bash testbed/build.sh
2. Run Automated Verification (Verifier + 500/500 Parity + Latency + 7 Live KVM Checks)
testbed/run_vm.sh verify
python3 testbed/verify_demo.py
3. Launch the Interactive Split-Screen Demo
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:
# 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)
python3 ml/generate_dataset.py
CUDA_VISIBLE_DEVICES="" python3 ml/train_and_eval.py
License
MIT License. See ../LICENSE.