Mental model
eBPF allows developers to run sandboxed program bytecode directly inside the Linux kernel without mutating kernel source code or loading dangerous kernel modules. It attaches to kernel functions (kprobes), user functions (uprobes), tracepoints, and network sockets.
Theory
- Kernel Verifier: Audits eBPF bytecode before loading to guarantee it cannot crash the kernel: verifies no unbounded loops, no null pointer dereferences, and restricted memory access.
- JIT Compiler: Translates verified eBPF bytecode into native CPU assembly for zero-overhead execution.
- Probe Types:
kprobe/kretprobe: Dynamic instrumentation of kernel function entry and return.uprobe/uretprobe: Dynamic instrumentation of userspace application functions (e.g. SSL library calls).tracepoint: Static guaranteed kernel trace hooks.
Alternatives and trade-offs
- Kernel Modules (
.ko): Full kernel access; buggy code causes fatal Kernel Panic crashes. - eBPF Tracing: Guaranteed memory safety, near-zero overhead; restricted to verifier-approved helper functions and safe memory access patterns.
Failure modes and misconceptions
- Verifier Rejection of Complex Programs: Writing complex algorithms with dynamic loops causes the eBPF Verifier to reject the program. Keep eBPF probes lightweight and push heavy data analysis to userspace daemons via eBPF Ring Buffers.
- High Uprobe Overhead: Attaching
uprobesto high-frequency userspace functions called millions of times per second adds context-switch overhead between user and kernel space.
Decision scenario
Attach eBPF probes to kernel syscall tracepoints using tools like Cilium and bpftrace for production network observability and security profiling without kernel risks.
Learning outcomes
- Structure eBPF programs and pass memory checks through the kernel verifier.
- Attach
kprobes,uprobes, and tracepoints to kernel system events. - Stream high-speed kernel metrics to userspace using eBPF Ring Buffers.
Trade-offs
eBPF delivers revolutionary zero-overhead observability and kernel network filtering, but imposes strict verifier programming constraints.