Hardening eBPF Programs Against Kernel Exploits With bpftool

Cybersecurity
Date:November 20, 2026
Topic:
Hardening eBPF Programs Against Kernel Exploits With bpftool
⏱ 3 min read

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.

bash
bpftool prog list --json | jq '.[] | {id, name, type, tag, jited, run_time_ns, run_cnt}'
bpftool prog show id 42 --pretty
bpftool prog dump xlated id 42  # inspect post-verifier bytecode
💡
TipEnable CONFIG_BPF_JIT_ALWAYS_ON and CONFIG_BPF_JIT_HARDEN in your kernel config. Hardening inserts constant blinding and random offsets, making JIT spraying significantly harder.

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.

bash
bpftool map list --json | jq '.[] | {id, name, type, flags, key_size, value_size, max_entries}'
# Pin maps with restrictive mode
bpftool map pin id 7 /sys/fs/bpf/my_map
chmod 600 /sys/fs/bpf/my_map
chown root:bpf_admins /sys/fs/bpf/my_map
⚠️
WarningNever pin maps world-writable. An attacker with map write access can corrupt kernel pointers, bypass KASLR, or plant ROP chains in JIT regions.

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.

MetricHealthy BaselineAlert Threshold
run_time_ns / run_cnt< 10 µs> 100 µs
map value churnmatches deploy rate> 10x deploy rate
verifier log warningszeroany

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.

bash
# Generate signing key
openssl req -new -x509 -nodes -days 3650 -subj '/CN=BPF Signing' -keyout bpf.key -out bpf.crt
# Sign object file
llvm-objcopy --add-section .bpf.sign=signature.sig my_prog.o
# Load with verification
bpftool prog load my_prog.o /sys/fs/bpf/my_prog type xdp pinmaps /sys/fs/bpf/

✦

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.

ℹ️
NoteeBPF security is a moving target. Subscribe to [email protected] and CVE feeds for verifier bypasses. The tooling evolves faster than most docs—bpftool is your ground truth.
Share𝕏 Twitterin LinkedInin Whatsapp