eBPF has become the Swiss Army knife of modern Linux observability, networking, and security. But every bytecode verifier bypass, map leak, or helper misuse hands attackers a direct line into kernel memory. Hardening eBPF programs isn't optional anymore—it's the price of running privileged bytecode in production.
Why the Verifier Isn't Enough
The kernel's eBPF verifier is a masterpiece of static analysis. It proves memory safety, bounds checking, and termination. Yet it operates on a model of the program, not the running reality. JIT compilation, speculative execution side-channels, and race conditions in map access can all invalidate verifier assumptions after load time.
"The verifier checks what your code *says* it does. bpftool shows what it *actually* does in the running kernel.
— Brendan Gregg
Inspect Loaded Programs With bpftool
Start by auditing every program currently resident. bpftool prog list gives you IDs, types, and tags. Drill into each with bpftool prog show id to see the verifier log, JIT status, and attached maps. Pay attention to jited:1 without xlated inspection—JIT bugs have historically been a fertile exploit class.
Map Hardening: Least Privilege for Data
Maps are the shared memory between eBPF and user space. A single writable map exposed to an unprivileged process can become an arbitrary kernel read/write primitive. Use bpftool map show to enumerate flags: BPF_F_RDONLY_PROG, BPF_F_WRONLY_PROG, and pinning permissions.
Runtime Anomaly Detection
Static hardening is half the battle. Monitor run_time_ns and run_cnt spikes—they signal infinite loops or logic bombs. Correlate with bpftool prog tracelog for per-instruction timing. Sudden map value mutations without corresponding user-space API calls indicate a compromised helper or race exploit.
| Metric | Healthy Baseline | Alert Threshold |
|---|---|---|
| run_time_ns / run_cnt | < 10 µs | > 100 µs |
| map value churn | matches deploy rate | > 10x deploy rate |
| verifier log warnings | zero | any |
Sign and Enforce Program Provenance
Linux 6.6+ supports BPF_F_SIGNED and BPF_F_TEST_RND_HI32. Sign your bytecode with a kernel-trusted key. Reject unsigned loads via bpftool prog load policy or LSM hooks. This kills the "load arbitrary bytecode" attack vector used by rootkits like Reptile and BPFDoor.
✦
Actionable Checklist for This Week
1. Run bpftool prog list --json on every production node. Export to SIEM. 2. Audit map permissions: chmod 600 on all pinned maps, ownership to dedicated group. 3. Enable JIT hardening kernel params; reboot if needed. 4. Deploy signed eBPF artifacts only; block unsigned loads via auditd rule on bpf syscall. 5. Add run_time_ns/run_cnt alerts to your observability stack.








