eBPF: Building High-Performance Kernel Plugins for Linux Security and Observability

A buggy eBPF program cannot crash the kernel—unless there is a bug in the kernel itself.
eBPF's safety guarantees come from kernel verification, making it fundamentally different from traditional kernel modules.
Mark

Why does eBPF matter so much more than, say, just writing a kernel module if you need to do something in kernel space?

Mimi

Because a kernel module can crash your entire system if it has a bug. eBPF programs cannot. The kernel verifies them first, checks for infinite loops and illegal operations, and only then lets them run. That safety changes everything—it means you can deploy eBPF programs to production systems without the same level of fear.

Mark

But doesn't that safety come at a cost? What can't you do with eBPF that you could do with a kernel module?

Mimi

Yes, eBPF programs are restricted. They can't do everything a kernel module can. But the restrictions are actually the point. You lose some power, but you gain the ability to iterate quickly, to deploy without rebooting, and to know that a mistake won't bring down the system. For most use cases—networking, observability, security—those restrictions don't matter.

Mark

You mentioned that companies like Netflix and Cloudflare use eBPF. What are they actually using it for?

Mimi

The source doesn't specify exactly what each company does with it, but the pattern is clear: they use it where it matters most. High-performance packet filtering, tracing system calls across millions of processes, custom scheduling. Anywhere you need to intercept something at the kernel level and do it fast.

Mark

The example with bpftrace seemed much simpler than writing a full eBPF program with libbpf-bootstrap. Why would anyone do the harder thing?

Mimi

bpftrace is great for quick one-liners and ad hoc tracing. But once you need to do something more complex—maintain state across events, perform calculations, integrate with external systems—you need the full control that writing an eBPF program gives you. bpftrace is a tool. libbpf-bootstrap is a foundation for building systems.

Mark

What's the biggest unsolved problem in eBPF right now?

Mimi

The verifier. It's the gatekeeper that makes eBPF safe, but it's also a bottleneck. Sometimes it rejects programs that are actually safe, just overly conservative. And there's always the risk of loopholes—ways to bypass the restrictions. A lot of smart people are working on making the verifier both safer and less frustrating to work with.

  • Traditional kernel modules carry the power to destroy the very system they extend — eBPF breaks this dangerous bargain by enforcing strict verification before any program ever runs.
  • Production systems at global scale are already being reshaped: Cilium replaces Kubernetes networking overhead, XDP stops DDoS attacks before packets reach the kernel stack, and bpfilter rewrites firewall rules as eBPF programs on the fly.
  • The verifier — eBPF's gatekeeper — remains a source of friction, sometimes rejecting valid programs and frustrating developers, making its improvement one of the field's most active research challenges.
  • Accessibility is expanding rapidly: bpftrace lets a single command-line one-liner trace every directory deletion system-wide, while libbpf-bootstrap provides ready-made scaffolding so developers can skip the tedious boilerplate.
  • The technology is now escaping Linux entirely, spreading to Windows and hardware SmartNICs, signaling that eBPF's model of safe, dynamic kernel extension may become a cross-platform standard.

Deep within the Linux kernel, where a single errant instruction can bring down an entire system, a technology called eBPF has quietly redefined what it means to extend an operating system. By allowing small, rigorously verified programs to run in kernel space — intercepting network packets, tracing system calls, influencing process scheduling — eBPF offers the power of traditional kernel development without its existential risks. What began as an evolution of the Berkeley Packet Filter has grown, through the trust of Google, Meta, Cloudflare, and Netflix, into a new philosophy of systems programming: that safety and capability need not be opposites.

eBPF has become one of the most unlikely success stories in systems programming — a technology that lets small, verified programs run inside the Linux kernel, doing things that once required dangerous kernel modules, but without the risk of bringing the system down.

The appeal is rooted in reach. Kernel-space programs can intercept network packets before they enter the network stack, trace every system call, or participate in process scheduling — none of which is possible from user space. The crucial difference is that eBPF programs operate under strict constraints: no infinite loops, no illegal operations. A buggy eBPF program cannot crash the kernel. This makes kernel extension a fearless activity in a way traditional modules never were.

The practical impact is already visible. Cilium uses eBPF to replace kube-proxy and iptables in Kubernetes, cutting overhead by handling load balancing at the lowest possible level. bpfilter translates firewall rules into eBPF programs automatically. XDP filters packets at the NIC driver level, making it the preferred tool for DDoS mitigation. For observability, bpftrace offers an AWK-like language that compiles down to eBPF internally — a single one-liner can log every directory removal across the entire system in real time.

Under the hood, the pipeline is precise: a developer writes an eBPF program in C, compiles it with Clang into eBPF bytecode, and submits it to the kernel via a bpf() system call. The verifier inspects it for safety, and if it passes, a JIT compiler translates it to native machine code. Execution is event-driven — the program fires when its attached hook triggers. Kernel and user space communicate through shared maps: arrays, hash tables, queues.

Frameworks like libbpf-bootstrap lower the barrier further, providing boilerplate and build configuration so developers can focus on logic rather than plumbing. The surrounding ecosystem — bpftop for real-time program monitoring, bpftool for inspection, llvm-objdump for bytecode disassembly — continues to mature. As eBPF spreads to Windows and hardware SmartNICs, what began as a packet filter extension has grown into something far larger: a new, safer model for extending operating systems at scale.

eBPF has become one of the most unlikely success stories in systems programming. A technology that lets you write small programs that run inside the Linux kernel—traditionally the domain of dangerous, crash-prone kernel modules—now has a foundation, an academic workshop, a documentary, and the backing of companies like Google, Meta, Cloudflare, and Netflix. The reason for this strange popularity is simple: eBPF lets you do things that matter, in places where they matter most, without the risk that comes with traditional kernel development.

The appeal lies in what eBPF can reach. A program running in kernel space can hook into critical system events—network packets arriving at the NIC driver, system calls being made, process scheduling decisions—and intercept or manipulate them before they propagate further. You can drop a packet before it even enters the kernel's network stack. You can trace every directory removal across the entire system. You can participate in process scheduling. None of this is possible from user space. But here is the catch: eBPF programs are not free to do whatever they want. The kernel enforces strict restrictions. They cannot contain infinite loops. They cannot perform illegal operations. This sounds limiting, but it is actually the source of eBPF's power. A buggy eBPF program cannot crash the kernel—unless there is a bug in the kernel itself. This makes extending the kernel a fearless activity, something that cannot be said of traditional kernel modules, which have the full power of the kernel and can destroy it just as easily.

The practical impact is already visible in production systems. Cilium, a networking layer for Kubernetes, uses eBPF to replace the traditional kube-proxy and iptables workflow, eliminating significant overhead by doing load balancing and routing at the lowest level possible. bpfilter is a firewall solution that translates network filtering rules into eBPF programs automatically, serving as a drop-in replacement for iptables. You can use its command-line tool, bfcli, to load filtering chains and attach them to network interfaces. For example, you can block all ICMP packets—effectively disabling ping—by loading a chain that drops traffic matching the rule, then attaching it to a specific network interface by its index. XDP, the eXpress Data Path, is an eBPF-based feature that filters packets at the NIC driver level, making it the tool of choice for DDoS mitigation because filtering happens before packets enter the kernel network stack.

For observability, bpftrace offers a simpler entry point. It accepts programs written in an AWK-like language and converts them to eBPF internally, inspired by the D language used in DTrace. A single command can log every time a process removes a directory: you write a one-liner that hooks into the rmdir system call tracepoint, and it prints the process name whenever that call is made. You can test it by creating and deleting a directory in another terminal and watching the logs appear in real time.

Understanding how eBPF works requires understanding the pipeline. An eBPF program is an ELF binary containing eBPF bytecode instead of machine code. You write it in C or Assembly, compile it with Clang, and send it to the kernel via a bpf() system call using a user-space loader program. Once the kernel receives it, the eBPF verifier inspects the program to ensure it is free of infinite loops and illegal operations. If it passes, a JIT compiler translates the bytecode to native machine code for the current architecture—x86_64, ARM, and others. Then the program is ready to run. Execution is event-driven: the program runs when the hook it is attached to fires, whether that is a network packet arriving, a system call being made, or a timer expiring. eBPF programs communicate with their user-space loaders through maps—data structures like arrays, hash tables, and queues that bridge kernel and user space.

Writing eBPF programs from scratch requires building both the kernel-space program and the user-space loader, which is tedious without a framework. libbpf-bootstrap is a collection of sample programs with all the boilerplate and build configuration already in place, licensed under BSD 3-Clause. The minimal example demonstrates the pattern: the eBPF program hooks into the write() system call and prints a message whenever it fires, while the loader program prints a dot every second, triggering the eBPF program repeatedly. You can clone the repository, run make minimal, and then sudo ./minimal to start the loader. In another terminal, reading from /sys/kernel/debug/tracing/trace_pipe shows the output from the eBPF program. Modifying the example to hook into rmdir() instead and removing the process filter allows you to trace directory deletions across the entire system—something that would require significantly more code in user space or a full kernel module.

The ecosystem continues to grow. Tools like bpftop provide a real-time view of running eBPF programs similar to top or htop. bpftool lets you inspect and manipulate eBPF programs and maps. llvm-objdump can disassemble eBPF bytecode so you can see the actual instructions. The verifier remains an active area of research and improvement—it is the gatekeeper that makes eBPF safe, but it can also be overly strict, making development frustrating. As eBPF adoption spreads to Windows and hardware SmartNICs, and as more companies build production systems on top of it, the technology that started as an extension of Berkeley Packet Filter has become something far larger: a new way to extend operating systems safely, dynamically, and at scale.

eBPF lets us write high-performance dynamic plugins for the Linux kernel, with use cases ranging from tracing to custom schedulers
— Open Source For You article
Kernel modules can be far more capable than eBPF programs, but eBPF programs have restrictions enforced by the kernel that make extending the kernel a fearless activity
— Open Source For You article
Möchten Sie die ganze Geschichte? Das Original lesen bei Open Source For You ↗
Kontakt FAQ