iTranslated by AI
eBPF: A Breath of Fresh Air for Kernel Extensibility
Introduction
I happened to see the following post on X (Twitter) and thought, "Oh, I should summarize eBPF," so I'm putting this together.
A New Breeze Blown into Kernel Extensions
With the rise of modern cloud environments, microservices, and containerized workloads, the demands on the Linux kernel are becoming more sophisticated every day. Particularly in terms of performance, observability, and security, traditional kernel extension methods are no longer sufficient. Until now, there were two main options for extending the kernel: developing a kernel module or building a solution that resides entirely in user space.
Kernel modules are powerful, but they require a deep understanding of the kernel's internal structure, making development difficult. Furthermore, it is challenging to maintain compatibility across different kernel versions, and there is a risk that a bug could crash the entire system. On the other hand, user-space solutions are safe, but they incur significant overhead for communication with the kernel via system calls, which limits performance.
eBPF (extended Berkeley Packet Filter) emerged as a technology to solve this dilemma. eBPF is a technology that allows user programs to run safely within the Linux kernel. It can dynamically extend the kernel's behavior without restarting the system and possesses the versatility to be used for various purposes.
The paradigm shift brought by eBPF lies in the improvement of programmability at the operating system level. Traditionally, the pace of innovation in OSs was slower compared to the application layer, but eBPF has made it possible to safely extend kernel functionality without modifying the core OS code. Just as JavaScript extended the functionality of web browsers, eBPF has brought new possibilities to the Linux kernel.
The Evolution of eBPF
The history of eBPF dates back to 1992. The original BPF (Berkeley Packet Filter) was a technology developed to efficiently filter network packets. Compared to the traditional stack-based CSPF (CMU/Stanford Packet Filter), BPF adopted a register-based virtual machine, significantly improving packet filtering performance.
The following table summarizes the key milestones in the evolution of eBPF.
| Year | Event | Impact and Significance |
|---|---|---|
| 1992 | Announcement of Original BPF | ・Paper published by Steven McCanne and Van Jacobson ・Packet filtering using a register-based virtual machine ・Revolutionized network monitoring in UNIX systems |
| 1997 | Implementation as Linux Socket Filter | ・Linux 2.1.75 ・BSD's BPF ported to Linux as Linux Socket Filter (LSF) ・Established the foundation for packet filtering in Linux |
| 2013 | Alexei Starovoitov's eBPF Proposal | ・[PATCH net-next] extended BPF (Mailing list archive) |
| 2014 | Inclusion of eBPF | ・Linux 3.18 ・Introduction of 64-bit registers ・Ability to attach to arbitrary kernel hooks ・Introduction of data sharing mechanism via maps |
| 2019 | BPF CO-RE Proposal | ・Compile Once - Run Everywhere ・Improved compatibility across different kernel versions |
| 2021 | Announcement of eBPF for Windows | ・eBPF ported to Windows environment led by Microsoft ・The first step toward becoming cross-platform |
| 2021-Present | Establishment and Development of eBPF Foundation | ・Community expansion under the Linux Foundation ・Promotion of standardization and compatibility |
The adoption of eBPF proceeded mainly among large technology companies such as Facebook, Cloudflare, Google, and Netflix, and subsequently spread to networking and security use cases in Kubernetes environments. Today, it has become a standard solution for system observability, security, and networking in cloud-native environments.
eBPF Architecture and Operating Principles
eBPF is not just a packet filter, but a virtual machine embedded within the Linux kernel. This virtual machine consists of multiple components for executing programs safely. The overall picture of the eBPF architecture can be divided into a development phase and a runtime phase.
The eBPF architecture consists of two main phases: "Development" and "Runtime," as shown in the figure above. In the development phase, an eBPF program written in C or other languages is converted into eBPF bytecode by the CLANG compiler (here, C is used as an example, but it is not limited to C). This bytecode and map definitions are passed to the kernel through user-space libraries such as the eBPF Go library.
In the runtime phase, the program is first loaded into the kernel via a system call and strictly verified for safety by the eBPF Verifier. Programs that pass verification are converted into native machine code by the JIT compiler, enabling high-performance execution. The program and user-space processes can share data bidirectionally via eBPF maps, and it also interacts with the TCP/IP stack and socket interfaces.
The following table explains the main components of eBPF and their roles in detail.
| Component | Role and Function |
|---|---|
| Verifier | ・Statically analyzes and guarantees program safety ・Prevents infinite loops and kernel crashes ・Verifies memory access safety ・Detects invalid pointer operations |
| JIT Compiler | ・Converts eBPF bytecode into native machine code ・Performs architecture-specific optimizations ・Supports various architectures such as x86_64, ARM64, and RISC-V ・Significantly improves runtime performance |
| Maps | ・Shares data between eBPF programs and user space ・Provides various structures such as hash maps, arrays, LRU hashes, and ring buffers ・Maintains statistical information and state ・Functions as persistent data storage |
| Helper Functions | ・Provides access to predefined kernel functions ・Functions for packet manipulation, time retrieval, random number generation, etc. ・The only kernel functions that can be called safely within the sandbox ・Callable functions are restricted by program type |
| Program Types and Hooks | ・Defines where eBPF programs can be attached ・Includes networking (XDP, TC), tracing (kprobes, tracepoints), security (LSM, Seccomp), etc. ・Each has its own unique context and functionality |
The eBPF Verifier is the most important component that ensures overall safety. It converts bytecode into a graph and analyzes all execution paths to verify that there are no issues. Specifically, it performs infinite loop detection, memory access safety checks, and resource usage limits. Thanks to this Verifier, user-defined programs can be executed safely even within kernel space.
The JIT compiler is the key to performance optimization. While early BPF used interpreter execution, modern eBPF is always JIT-compiled. This allows it to perform as well as native-compiled kernel code. Furthermore, techniques such as constant blinding are used to prevent JIT spraying attacks.
eBPF programs can be attached to arbitrary locations in the kernel and perform processing according to each connection point. For example, there are various hook points such as XDP (eXpress Data Path) programs that process network packets the moment they reach the NIC, Seccomp programs that filter system calls, and kprobes programs that trace the execution of kernel functions.
eBPF Programming Model
The eBPF programming model differs significantly from traditional kernel module development. eBPF programs are essentially event-driven and are executed by being attached to specific hook points. The program lifecycle consists of the following flow:
There is a wide variety of eBPF program types (defined as an enum) and hook points. The following table shows the primary ones:
| Program Type | Attachable Hooks | Main Applications |
|---|---|---|
| XDP (eXpress Data Path) | Network device drivers | ・Ultra-high-speed packet processing ・DDoS mitigation ・Packet filtering ・Routing |
| Traffic Control (TC) | Network queues | ・Traffic control ・QoS implementation ・Packet transformation ・Bandwidth control |
| cgroup | Control groups | ・Container network policies ・Device access control ・Resource limits |
| Socket | Socket operations | ・Socket filtering ・Protocol analysis ・Connection tracking |
| kprobe/uprobe | Kernel/User functions | ・Function tracing ・Performance analysis ・Dynamic debugging |
| tracepoint | Static tracepoints | ・System call tracing ・Kernel event monitoring ・Statistical information collection |
| perf_event | Performance events | ・CPU performance counter monitoring ・Hardware event analysis |
| LSM (Linux Security Module) | Security hooks | ・Security policy implementation ・Access control ・Privilege checks |
There are multiple languages that can be used for eBPF programming, but they can be broadly categorized into two approaches: a low-level direct approach and a high-level abstracted approach.
| Programming Approach | Languages and Tools | Features |
|---|---|---|
| Low-level approach | ・C (libbpf) ・Rust (libbpf-rs) |
・Fine-grained control possible ・High performance ・Direct control of eBPF instructions ・Minimal runtime overhead |
| High-level approach | ・Python (BCC) ・Go (gobpf) ・DSL (bpftrace) |
・Rapid prototyping ・Concise syntax ・Gentle learning curve? ・Sacrifices some performance |
A noteworthy aspect of eBPF programming is CO-RE (Compile Once - Run Everywhere). This technology solves the compatibility issues of eBPF programs across different kernel versions. By leveraging BPF Type Format (BTF) to generate symbolic relocations at compile time and dynamically resolve them at load time, programs compiled once can now run on various kernels. This concept is similar to Java's "Write Once, Run Anywhere" and has significantly lowered the barriers to eBPF's practicality and adoption.
eBPF Safety and Formal Verification
The key to eBPF running safely within the Linux kernel is the Verifier. eBPF programs are passed to the kernel as bytecode and undergo a strict verification process by the Verifier before execution. The figure below shows the lifecycle of an eBPF program and the role of the Verifier.

https://arxiv.org/html/2410.00026v2
As shown in this figure, an eBPF program goes through the following process:
- Source code (bpf.c) is converted into an ELF binary (bpf.o) by the Clang compiler + LLVM (S1→S2).
- The application loads the program into the kernel using the
bpf(BPF_PROG_LOAD, ...)system call (S3→S4). - The Verifier within the kernel verifies the program and rejects it (red X) if it is unsafe.
- Programs that pass verification are converted into native code by the JIT compiler.
- The program is attached to a hook point (e.g., network stack, eth0 interface) with the
bpf(BPF_LINK_CREATE, ...)system call (S5). - When the program execution ends, the link (S6) and the program (S7) are closed.
The following table explains the main verification processes of the Verifier and its security guardrails.
| Verification Item | Verification Content and Method |
|---|---|
| Path Exploration | ・Construct a control flow graph ・Explore all possible execution paths ・Detect unreachable code ・Verify the maximum instruction count limit |
| Infinite Loop Detection | ・Analyze loop termination conditions ・Allow only bounded loops (finite iterations) ・Verify the upper limit of iterations ・Eliminate the risk of infinite loops |
| Memory Access Verification | ・Range analysis of pointers ・Detect out-of-bounds access ・Check type safety ・Prevent illegal memory operations |
| Helper Function Calls | ・Verify that argument types match ・Confirm if the function is permitted for the program type ・Detect invalid function calls ・Check the valid range of parameters |
| Resource Usage Limits | ・Verify stack size limits ・Verify map usage ・Check upper limit on instruction count ・Protect system resources |
The Verifier always performs conservative verification. In other words, if it cannot determine for certain whether a program is safe, it rejects the program. For example, if all possibilities of a conditional branch cannot be analyzed statically or if loop termination cannot be guaranteed, the program will be rejected even if it is actually safe. Such strict verification minimizes the risks of executing user-defined code in kernel space.
Memory access verification is particularly important. The Verifier tracks pointer ranges and ensures that eBPF programs only read and write to memory areas that they are permitted to access. This prevents security risks such as kernel memory corruption or data leaks.
eBPF programs that pass the Verifier are converted into native machine code by the JIT compiler and executed with high performance. In this way, eBPF achieves both a strong safety guarantee by the Verifier and high performance by the JIT compiler.
Furthermore, the eBPF security model is based on the principle of defense-in-depth. Even if there were a bug in the Verifier, additional protection mechanisms safeguard the integrity of the kernel.
| Security Mechanism | Function and Role |
|---|---|
| Constant Blinding | ・Prevention of JIT spraying attacks ・Obfuscate constants in code ・Prevent insertion of executable code |
| JIT Hardening | ・Protection of JIT-compiled code ・Make execution code read-only ・Prevent code tampering |
| Privilege Separation | ・Restrict use for non-privileged users ・Protection by CAP_BPF privilege ・Mitigate privilege escalation attacks |
| Spectre Mitigations | ・Measures against speculative execution attacks ・Masking of memory access ・Prevention of side-channel attacks |
In recent years, formal verification approaches to further enhance the safety of eBPF have also been progressing. In particular, active research is being conducted on proving the correctness of JIT compilers and the integrity verification of the Verifier.
Main Application Areas
Due to its high versatility, eBPF applications are expanding across various domains. The main application areas are explained below.
Networking
Networking is one of the areas where eBPF exerts its most powerful effects. In particular, XDP (eXpress Data Path) allows packets to be processed as soon as they reach the device driver, enabling ultra-high-speed packet processing without going through the traditional kernel network stack.
| Networking Application | Functions and Examples |
|---|---|
| Packet Filtering | ・Suricata's packet filter engine ・Cloudflare's large-scale DDoS protection ・Facebook's traffic filtering ・Capable of processing millions of packets per second |
| Load Balancing | ・L4 load balancer with Katran ・Facebook's scalable connection distribution ・Communication optimization between microservices ・Consistent hash-based distribution |
| Network Policy | ・Kubernetes network policies by Cilium ・Communication control between microservices ・L7-level API-aware filtering ・Application layer protocol control |
| Traffic Shaping | ・Bandwidth control by TC programs ・Dynamic implementation of QoS ・Priority-based traffic distribution ・Traffic engineering |
This table shows the main fields of eBPF networking applications, along with their representative functions and implementation examples.
The combination of XDP and TC makes it possible to make the entire network stack from the edge to the core programmable. As a result, functions that were traditionally realized with hardware appliances or dedicated middleware can now be implemented as software on general-purpose servers.
Observability
Observability for visualizing the state and behavior of systems has grown in importance with the spread of microservice architectures in recent years. eBPF is an ideal tool providing high-precision observability with low overhead.

https://www.brendangregg.com/blog/2019-07-15/bpf-performance-tools-book.html
| Observability Application | Functions and Examples |
|---|---|
| Performance Monitoring | ・System analysis with bpftrace/BCC ・CPU profiling ・I/O latency measurement ・Memory usage tracking |
| Distributed Tracing | ・Application monitoring with Pixie ・Tracing communication between microservices ・Service mesh visualization ・End-to-end analysis of request flows |
| Container Monitoring | ・Container communication observation with Cilium Hubble ・Network flow analysis in Kubernetes environments ・Container metrics collection ・Anomaly detection and troubleshooting |
| Custom Metrics | ・Metrics generation from kernel events ・Application-specific performance indicators ・Integration with Prometheus ・Real-time dashboard construction |
A notable point about eBPF-based observability tools is that they allow deep insights without requiring application changes or recompilation. This sets them apart from traditional APM (Application Performance Management) tools and profilers.
Performance monitoring methods like the "USE Method" (Utilization, Saturation, and Errors) proposed by Brendan Gregg have also become significantly easier to implement using eBPF tools.
Security
eBPF is also bringing revolutionary progress to the security field. By providing kernel-level visibility and control, it overcomes many of the limitations of traditional security solutions.
| Security Application | Functions and Examples |
|---|---|
| Runtime Protection | ・Linux system monitoring with Falco ・Detection of anomalous behavior or security violations ・File access control ・Process execution management |
| Container Security | ・Control of inter-container communication with Cilium ・Microservice segmentation ・Privilege escalation detection ・Container escape prevention |
| System Call Auditing | ・System call tracing with Tetragon ・Real-time detection of security events ・Forensic analysis ・Compliance monitoring |
| Intrusion Detection/Prevention | ・Advanced threat detection with Tracee ・Zero-day attack detection ・File injection detection ・Blocking of anomalous network communication |
The advantage of security solutions using eBPF is the significant improvement in the "visibility vs. performance" trade-off that traditional security tools faced. Because it runs directly at the kernel level, it reduces the overhead associated with user-space agents while achieving deeper visibility and control.
Additionally, because eBPF programs are event-driven, they avoid CPU consumption caused by continuous polling and are designed efficiently to execute only when necessary. This has enabled security monitoring that can run constantly even in production environments.
Storage and I/O
Storage and I/O optimization is another new application area for eBPF. Especially with the spread of high-speed NVMe devices, the overhead of the kernel storage stack has become more noticeable, and optimization methods using eBPF are attracting attention.

https://www.usenix.org/conference/osdi22/presentation/zhong
| Storage Application | Functions and Examples |
|---|---|
| Storage I/O Optimization | ・NVMe driver hooks with the XRP framework (pictured above) ・Bypassing unnecessary storage stack processing ・Custom index searching ・Storage engine optimization |
| File System Extension | ・User-space file system extension with ExtFUSE ・File access pattern analysis ・Custom caching strategies ・Strengthening file system security |
| Block I/O Tracing | ・Real-time measurement of block I/O latency ・I/O pattern analysis by application ・Identification of storage bottlenecks ・Dynamic adjustment of I/O schedulers |
| Cache Optimization | ・Dynamic management of memory cache |
Research projects like XRP have succeeded in significantly reducing storage stack overhead and bringing out the inherent performance of NVMe devices. This is particularly significant for applications where storage I/O is critical, such as databases and key-value stores.
IoT and Embedded Systems
The use of eBPF is also advancing in resource-constrained IoT environments. In particular, lightweight eBPF implementations are being adopted for embedded Linux and operating systems for microcontrollers.
| IoT Application | Functions and Examples |
|---|---|
| Lightweight eBPF Implementations | ・rBPF implementation in RIOT OS ・Lightweight VM for microcontrollers ・Formally verified JIT ・Minimization of memory footprint |
| Edge Computing | ・Data filtering on edge devices ・Reduction of communication volume through local processing ・Preprocessing of sensor data ・Coordination between cloud and edge |
| IoT Security | ・Security monitoring in resource-constrained environments ・Anomaly detection ・Monitoring of inter-device communication ・Detection of remote attacks |
| Femto-containers | ・Safe functional expansion on IoT devices ・OTA programming ・Resource isolation ・Dynamic functional updates |
In IoT environments, where computing power and memory are limited, lightweight implementations with restricted functionality are often preferred over full-featured eBPF. For example, RIOT OS's rBPF is optimized for embedded devices, achieving both safety and efficiency with a formally verified JIT compiler.
Summary
eBPF is like the "Lego blocks" of the Linux ecosystem. While integrated into the kernel as basic components, combining them opens up infinite possibilities.
On a separate note, if we bring the Japanese internet meme "the level where Gandhi takes a running start and punches you" into the context of the bee industry, we could call it "the level where a carpenter bee takes a running start and stings you." Though I wouldn't know for sure.



Discussion