eBPF is a programmable execution framework, most extensively implemented in Linux, that allows specially constrained programs to run in response to events within an operating system. Its name derives from the extended Berkeley Packet Filter, but its uses extend well beyond packet filtering. Programs can inspect network traffic, measure application and kernel activity, maintain shared state, and participate in selected policy decisions without requiring a separately developed kernel module.
The central design combines a defined instruction set, a load-time verifier, controlled interfaces to kernel facilities, and event-specific attachment points. Programs are usually compiled to eBPF instructions and then translated into native instructions before execution. Rather than providing unrestricted access to the kernel, eBPF exposes capabilities determined by program type, attachment point, system configuration, and loader privileges.
This combination has made eBPF important in network infrastructure, performance analysis, and host security. Its behavior is nevertheless inseparable from the surrounding operating system: verification does not establish arbitrary application correctness, attachment interfaces differ in stability, and supported features depend on the kernel and hardware environment.
Origins and expansion beyond packet filtering
The original Berkeley Packet Filter, described by Steven McCanne and Van Jacobson in 1993, addressed a practical problem in packet capture: copying every received packet into a user-space analysis program consumed unnecessary processing and memory bandwidth. BPF allowed an application to submit a small filter program that ran near the packet source. The filter examined packet fields and returned a value indicating how much of a matching packet should be retained. Nonmatching traffic could be discarded before expensive copying.
This original design, now commonly called classic BPF or cBPF, used a compact abstract machine with an accumulator, an index register, and scratch memory. Its instruction set was deliberately limited, making programs straightforward to validate. Packet-capture libraries such as libpcap translated expressions describing addresses, protocols, and ports into filter instructions. Consequently, many users encountered BPF indirectly through tools such as tcpdump rather than through programming the abstract machine itself.
Linux later extended this approach substantially. Work led by Alexei Starovoitov and other kernel developers introduced a new register-based instruction set in Linux 3.18, released in 2014. The extended design provided 64-bit registers, a more capable calling convention, maps for persistent state, and access to selected kernel functions through controlled interfaces. Its register organization was chosen to support efficient translation onto common processor architectures. Daniel Borkmann and other contributors helped develop the networking infrastructure and broader ecosystem around these facilities.
The distinction between classic and extended BPF remains technically important. They have different instruction sets and execution models, even though both descend from the same filtering idea. Linux can translate classic filter programs into its internal extended representation. Meanwhile, some interfaces historically associated with BPF, including packet capture and system-call filtering, retain classic-BPF programming interfaces. The word “BPF” therefore does not always identify the same program format or set of capabilities.
Expansion occurred through successive additions rather than a single replacement of the kernel’s extension model. Tracing, network traffic control, socket operations, control-group hooks, and security hooks each introduced different contexts and permissions. The eBPF Foundation, established under the Linux Foundation in 2021, reflected the technology’s growing cross-project ecosystem. Nevertheless, the Linux kernel remains the principal reference point for deployed eBPF functionality, and historical support for packet filtering should not be mistaken for support for every modern eBPF feature.
Instruction set and execution lifecycle
At its core, eBPF defines an instruction set architecture rather than a general-purpose application runtime. It has eleven 64-bit registers, conventionally named R0 through R10. R0 carries return values; R1 through R5 carry function arguments; R6 through R9 are preserved across calls; and R10 is a read-only frame pointer. Ordinary instructions occupy 64 bits, while certain operations, notably loading a 64-bit immediate, use a two-instruction encoding. Arithmetic operations include both 32-bit and 64-bit variants.
A typical development pipeline starts with restricted C or another supported source language. A compiler, commonly Clang using the LLVM infrastructure, emits an object file containing eBPF instructions, relocation information, and often type information. A user-space loader creates required maps, resolves references, submits programs to the kernel, and attaches successfully loaded programs to suitable hooks. The bpf() system call, introduced in Linux 3.18, provides the central management interface, although attachment can also involve subsystem-specific interfaces.
Loading and attachment are distinct operations. A program may be accepted by the kernel yet never execute because no event source references it. Conversely, a program can remain active after the original loading process exits if other references preserve its lifetime. File descriptors identify programs, maps, and attachment objects in user space. Objects can also be pinned in the BPF virtual file system, usually mounted at /sys/fs/bpf, allowing another process to reopen them without reconstructing the original loader’s state.
After verification, the kernel can execute instructions through an interpreter or use just-in-time compilation to translate them into native machine code. Availability depends on architecture and kernel configuration; some configurations require JIT execution. Native compilation removes the need to interpret each instruction on every event, but it does not eliminate event-delivery costs, map operations, synchronization, or other work performed by the program.
Programs do not generally start independent execution or run as ordinary processes. A kernel event invokes a program with a context whose layout and permitted operations depend on its type. That context might describe a packet, a tracing event, or a socket operation. Some tracing programs merely record information, whereas a packet-processing program may return an action such as pass, drop, or redirect. Execution therefore resembles a collection of constrained callbacks more than a continuously running virtual machine hosting arbitrary applications.
Verification and the limits of safety guarantees
The verifier examines a program before the kernel permits it to execute. Its task is to establish properties required for safe participation in a particular execution environment: valid memory accesses, initialized register use, permissible function calls, and acceptable control flow. Verification is closely related to abstract interpretation. Instead of running a program on every possible input, the verifier tracks abstractions of possible values and states along reachable paths through its control flow.
Register tracking distinguishes scalar values from categories of pointers, including pointers to stack memory, packet data, map values, and typed kernel objects. For scalar values, the verifier can track numerical bounds and information about known and unknown bits. This allows it to determine whether later arithmetic preserves an acceptable range. For pointers, it tracks properties such as object identity, offsets, and nullable status. A successful map lookup, for example, may return either a value pointer or a null pointer; the program ordinarily needs an appropriate check before dereferencing it.
Packet access illustrates the connection between ordinary programming and verification. An eBPF program may calculate the address of a protocol header and compare its end against the packet’s accessible boundary. Only after a suitable bounds check can the verifier establish that reading the header is valid. The exact arrangement of these checks matters because the verifier reasons about the compiled instructions, not the programmer’s informal intention. Two source-level formulations with similar apparent meaning can therefore produce different verification outcomes.
Termination and analysis cost are also important. Early eBPF implementations prohibited loops and required developers to unroll them. Linux 5.3, released in 2019, introduced support for bounded loops, allowing the verifier to accept loops whose execution could be sufficiently constrained. Later mechanisms, including bounded iteration helpers and iterator facilities, expanded the available approaches. These changes did not remove verification limits: paths can multiply rapidly, and a terminating program may still be rejected because its analysis requires excessive work or exceeds another implementation limit.
Verifier acceptance is not equivalent to unrestricted formal verification of the program’s purpose. A verified program can implement the wrong policy, produce inaccurate statistics, or consume unacceptable aggregate CPU time when invoked frequently. Verifier and JIT defects can themselves create a security vulnerability. The guarantees also depend on correct helper implementations and kernel interfaces. The relevant claim is narrower: under the implementation’s assumptions, accepted programs satisfy specific execution-safety rules, not that every possible behavior is desirable or that all kernel risks have disappeared.
Maps, callable interfaces, and shared state
eBPF programs need ways to retain information after an invocation ends and to exchange information with user-space applications. Maps provide this storage and communication layer. A map is a kernel-managed object with a declared type and configuration. Common types include arrays, hash maps, least-recently-used hash maps, per-CPU maps, and specialized structures for sockets or program references. The map interface exposes operations appropriate to each type rather than unrestricted memory allocation by the running program.
An array map has a fixed range of integer indices and preallocated elements. A hash map associates keys with values and is useful for information such as per-connection counters or activity indexed by process identifier. Per-CPU variants maintain separate values for individual processors, reducing contention when many CPUs update the same logical counter. A user-space reader may then aggregate these separate values. This arrangement exchanges simpler updates for higher memory consumption and a more complicated interpretation of the resulting snapshot.
Shared maps create concurrency questions. Several program invocations may update the same entry while a user-space process reads it. A sequence such as reading a counter, adding one, and writing it back can lose increments unless the design uses appropriate atomic operations or another supported coordination mechanism. Some map values can contain BPF spin locks, subject to restrictions. Verification of pointer accesses does not automatically provide race-free data structures or transaction-like consistency across multiple entries.
Callable kernel interfaces complement maps. Traditional BPF helpers expose operations such as obtaining a timestamp, looking up a map entry, calculating checksums, or redirecting a packet. The set available to a program depends on its type and other conditions. More recent BPF kernel functions, commonly called kfuncs, use typed interfaces associated with kernel type information. Neither mechanism is an unrestricted foreign-function interface: a program cannot simply call any kernel function by address. Some operations also require a sleepable execution context, which only particular program and attachment types support.
For event delivery, programs often use perf-event buffers or the BPF ring buffer introduced in Linux 5.8 in 2020. These allow programs to emit structured records that a user-space process consumes. The ring-buffer design can share capacity across CPUs and preserve reservation order across producers, unlike a collection of independent per-CPU buffers. Buffer exhaustion still requires explicit handling; a successful program invocation does not imply that every intended record reached a consumer.
Program-array maps provide another specialized mechanism: tail calls transfer execution to another eBPF program without returning to the caller. They support modular processing pipelines and dispatch tables. The kernel limits consecutive tail calls, preventing unbounded chains. Ordinary BPF-to-BPF function calls are different: they return to their caller and operate within verified stack and call-depth constraints.
Networking and packet-processing paths
Networking remains a central eBPF application because network subsystems contain frequent, well-defined decision points. An attachment point determines both what a program can observe and what it can change. A socket filter, for example, controls delivery to a particular socket rather than acting as a universal host firewall. Traffic-control programs operate within Linux’s packet-processing and queuing infrastructure. Other program types act on socket creation, connection establishment, address selection, or messages exchanged through selected socket paths.
Express Data Path, or XDP, attaches programs near the receive side of a network device. In native mode, supported drivers invoke XDP before allocating the usual socket-buffer structure for the packet. This positioning makes early rejection and redirection possible before much of the normal network stack runs. Common return actions include XDP_PASS, XDP_DROP, XDP_TX, and XDP_REDIRECT. The last two support transmission or forwarding decisions, subject to the capabilities of the device and redirect target.
The location of XDP explains both its efficiency and its constraints. An early program can inspect packet bytes and make a routing or filtering decision with limited overhead, but it cannot assume that higher-layer kernel processing has already established connection state or performed other transformations. Generic XDP operates through a later software path and broadens compatibility, while hardware-offloaded execution moves supported programs onto a capable network device. These modes differ in performance, available features, and implementation restrictions; “XDP support” alone does not specify which behavior is available.
Traffic-control, or TC, attachment points operate on socket buffers and can address ingress and egress processing. They are useful where packet metadata, interaction with the regular network stack, or outbound policy is required. Programs can consult maps to implement service selection, traffic classification, or load balancing. They can also modify supported packet fields and update checksums. Correctness depends on packet layout, fragmentation, offload behavior, and the precise networking hooks traversed.
Projects such as Cilium use eBPF to implement networking, policy enforcement, and service handling, particularly in Kubernetes environments. A user-space control plane translates configuration into maps and attached programs, while the packet path performs frequent decisions. This separation is important: eBPF supplies execution mechanisms, not a complete distributed policy system. Configuration distribution, endpoint identity, consistency during updates, and recovery remain responsibilities of the surrounding software.
Networking performance claims require a defined workload. Dropping packets early can avoid expensive later processing, but parsing variable-length headers, traversing maps, or maintaining shared state introduces costs of its own. Encryption, memory bandwidth, network-interface queues, and CPU placement can dominate the result. A packet-rate figure obtained for a minimal XDP drop program does not establish the throughput of an application implementing connection tracking, tunneling, and security policy.
Tracing, profiling, and production observability
eBPF supports observability by executing short programs when selected events occur and retaining or exporting only relevant results. Instead of copying every event to an analysis process, a program can aggregate counts, construct latency distributions, or filter by process and workload identity inside the kernel. This is particularly useful when the underlying event rate greatly exceeds the rate at which a user-space consumer can process detailed records.
Attachment mechanisms differ in what they expose. Tracepoints are explicitly placed instrumentation sites that provide defined event fields. Kprobes attach dynamically to kernel instruction locations, often at function entry, while return probes observe completion. User-space probes provide analogous instrumentation for application code. Performance-event attachments support sampling, including profiling based on hardware or software events. These mechanisms are not interchangeable: their data formats, overhead, stability, and execution contexts differ.
A common latency measurement records a timestamp at the beginning of an operation and retrieves it when the operation finishes. A map keyed by thread identifier can associate the two events, after which the program increments an appropriate histogram bucket. This design requires careful treatment of nested operations, missed events, and entries left behind when a task exits or an operation never reaches the expected completion hook. Merely subtracting timestamps is not enough to guarantee that the measured interval corresponds to the intended operation.
Profilers can sample instruction addresses and capture user and kernel call stacks. Symbolization—the conversion of addresses into function names and source locations—usually happens in user space and depends on matching binaries, debug information, address-space mappings, and language runtime behavior. Capturing a stack identifier does not automatically provide a reliable high-level stack for every managed or JIT-compiled language. Frame-pointer availability, unwinding support, and runtime-specific metadata can materially affect the result.
The BPF Compiler Collection, or BCC, helped popularize practical eBPF tracing tools, while bpftrace provides a higher-level language for concise event-driven investigations. Lower-level applications often use libbpf for object loading and interaction with kernel BPF facilities. These tools occupy different layers: a short tracing script and a continuously deployed agent may both use eBPF but have different compilation, packaging, and lifecycle requirements.
Observability can alter the system being measured. A probe on a frequently executed function adds work to every invocation; stack collection and large event records can be costly. Ring-buffer losses or sampling bias can distort results, while aggregation may hide outliers or discard sequence information. Sound interpretation therefore depends on the measurement design: whether events are counted or sampled, how missing records are handled, what clock is used, and whether the observed hook accurately represents the application behavior under investigation.
Security enforcement and privilege boundaries
eBPF has two distinct relationships with cybersecurity. It can implement security monitoring and enforcement, and it is itself a privileged kernel facility requiring protection. Monitoring programs can observe process execution, file activity, network operations, or selected kernel events. Enforcement programs can participate in decisions at supported hooks. The ability to observe an operation should not be confused with the ability to prevent it: many tracing attachments report activity without providing an authorization decision.
The Linux Security Modules framework provides a major enforcement interface. BPF LSM support, introduced in Linux 5.7 in 2020, allows suitably privileged programs to attach to selected security hooks. Such programs can inspect permitted context and return decisions according to the hook’s contract. Other mechanisms, including control-group network hooks, can restrict specific operations in a workload’s scope. These capabilities supplement the kernel’s broader access-control mechanisms rather than replacing them wholesale.
Loading privileges depend on kernel version, program type, and configuration. Historically, many BPF operations relied on the broad CAP_SYS_ADMIN capability. Linux 5.8 introduced CAP_BPF and CAP_PERFMON, enabling finer separation of some BPF and performance-monitoring privileges; networking operations may additionally involve CAP_NET_ADMIN. These capabilities do not create a single universal permission to run every eBPF program. Systems can also disable unprivileged BPF through policy and configuration, and distributions frequently restrict it.
The verifier is an important boundary but not the only one. JIT compilation, helper implementations, map operations, and attachment infrastructure all contribute to the attack surface. Defects in any of these components can undermine intended isolation. Speculative-execution concerns add another dimension because architecturally valid checks do not necessarily prevent all side-channel attacks. Kernel mitigations and restrictions therefore address implementation details beyond the source-level structure of a submitted program.
Once an actor has sufficiently powerful BPF privileges, approved interfaces can provide extensive visibility into a host. The same mechanisms used by defensive agents can be misused for covert observation or interference. Applying least privilege requires considering who may load programs, which attachments are permitted, who can inspect maps, and how object references are retained. A container boundary alone does not imply that a workload is entitled to create host-wide tracing programs.
Security-policy correctness also depends on placement and coverage. A program attached to one file-operation hook does not necessarily cover every means of accessing data. A packet policy applied at one network point may see traffic before or after address translation, tunneling, or encryption. Effective reasoning therefore begins with a precise threat model and the semantics of the relevant hooks, rather than treating verifier acceptance or the presence of an eBPF security agent as proof of complete protection.
Portability, type information, and development tooling
Portability has several layers in eBPF. The instruction set abstracts over processor architectures, but programs still depend on kernel features, supported helpers, map types, attachment mechanisms, and context layouts. A program compiled to architecture-independent instructions can therefore fail to load on another Linux system. Differences in kernel configuration or distribution backports can matter as much as the nominal kernel version, making runtime feature detection valuable.
Kernel data structures present a particular difficulty for tracing. Their layouts are generally not a stable user-space application binary interface. A field may move, change type, or disappear between kernel builds. Earlier workflows often compiled tracing programs on the target system using locally available headers. This accommodated some layout differences but created deployment dependencies on compiler toolchains, headers, and build resources.
BPF Type Format, or BTF, supplies compact descriptions of types, functions, and associated information. It can describe both kernel types and types in an eBPF object. Kernel BTF is commonly exposed through /sys/kernel/btf/vmlinux when the relevant build support is enabled. This metadata supports typed attachment mechanisms, improved inspection, and more informed interactions between programs, loaders, and kernel objects. It is not itself a promise that every described interface remains stable.
Compile Once–Run Everywhere, usually abbreviated CO-RE, uses compiler-generated relocation records and target-system type information to adapt particular compiled references during loading. With libbpf, a field access can be adjusted to the target kernel’s actual structure layout rather than assuming the layout present during compilation. CO-RE also supports tests for the existence of certain types, fields, or enumeration values, enabling programs to select compatible behavior.
The name describes an engineering goal, not unlimited portability. Relocations cannot create an absent helper, supply an unsupported program type, or guarantee that a function retains its meaning. Programs may need alternate implementations for different capabilities. Architecture-specific register conventions, particularly in low-level probe contexts, can also require special handling. A portable artifact must therefore account for semantic compatibility as well as type-layout compatibility.
Development tools bridge these layers. Libbpf skeletons generate user-space interfaces for embedded BPF objects and simplify access to programs, maps, and global data. The bpftool utility can inspect loaded objects, dump instructions, examine BTF, and report supported features. Verifier logs help explain rejected programs, although they require familiarity with register states and compiled control flow. Build reproducibility, compiler behavior, and testing across representative kernels remain important because a small source change can alter the instructions presented to the verifier and consequently affect whether the program loads.
Performance engineering and operational constraints
eBPF performance follows from placing specialized computation close to an event source, not from a universal speed advantage over other code. In-kernel filtering can avoid copying data, waking user-space processes, or making repeated system calls. JIT compilation can make the program body efficient. However, every attachment adds some work, and moving computation into the kernel does not eliminate its CPU, memory, or synchronization costs.
A useful first approximation relates event frequency to execution time. If an attachment runs at rate events per second and adds mean execution time seconds per event, its direct CPU demand is approximately
where represents one fully occupied CPU core. At one million events per second, an additional 100 nanoseconds per event corresponds to roughly one-tenth of a core. This estimate excludes secondary effects such as cache disruption, contention, scheduling changes, and additional work caused elsewhere in the system.
Maps often determine these secondary costs. A per-CPU counter can avoid repeated cache-line ownership transfers, while a frequently updated shared entry may create contention across processors. Large maps increase memory use and can reduce CPU cache locality. Hash lookups introduce different costs from array indexing, and eviction-based maps introduce state-loss behavior that affects interpretation. The most efficient representation depends on key distribution, update frequency, CPU count, and whether readers require a consistent view.
Execution context imposes additional constraints. Many BPF programs run where blocking or sleeping is forbidden, while explicitly sleepable program variants permit a different set of operations. Stack space is limited, and allocating large temporary objects as ordinary local variables can prevent compilation or verification. Programs cannot treat the kernel as a general application environment with unrestricted libraries, arbitrary blocking input/output, or unlimited recursion. Designs commonly place configuration, complex analysis, and durable storage in a user-space control process.
Operational correctness includes object lifecycle. Closing a loader’s file descriptors does not necessarily remove objects that remain pinned or attached through other references. Conversely, an attachment managed by a BPF link can be automatically detached when the last relevant reference disappears, unless its lifetime is preserved appropriately. Updates must consider both program code and map schema: replacing a program while retaining an incompatible map can produce failures even when both versions independently pass verification.
Evaluation therefore separates several questions: whether a program loads, whether it implements the intended semantics, whether it remains correct under concurrent events, and whether its costs are acceptable under realistic traffic. Kernel self-tests, application-specific tests, failure injection, and workload benchmarks address different parts of this problem. Event-buffer exhaustion, map-capacity limits, partial feature support, attachment failures, and loader restarts are concrete operating conditions that affect deployed systems independently of the correctness of the eBPF instruction stream.