eBPF lets you load small programs into the running Linux kernel, which the kernel checks, compiles and runs when a specific event happens, such as a system call or an incoming packet. Jesús Espino walks through it in detail in part 12 of his kernel series on Internals for Interns, published on November 16, 2026 and based on Linux 7.3 on x86-64. This article sums up how it works and how to check it on a server.
Key points on how eBPF works in the kernel in 30 seconds
- An eBPF program is bytecode for a virtual CPU with eleven 64-bit registers and a 512-byte stack.
- Maps are kernel key-value stores shared by programs and user space.
- Programs attach to hooks such as kprobes, tracepoints, uprobes, XDP or cgroup device control.
- The verifier walks every branch before accepting a program, with a one-million-instruction limit.
- A JIT then compiles it to native code in executable, non-writable memory.
Many admins associate eBPF with observability tools such as bpftrace, but eBPF programs are very likely already running on any server with systemd. That is exactly Espino’s example: systemd loads a program called sd_devices for services that use DeviceAllow= or PrivateDevices= and attaches it to the service’s cgroup device hook. When the service stops, the program is freed.
Bytecode, maps and hooks
An eBPF program is a set of instructions for a virtual CPU defined by the kernel. It has eleven 64-bit registers, R0 to R10: R0 holds the return value, R1 receives the context on entry, and R10 is a read-only frame pointer to a 512-byte stack. Each instruction is 8 bytes (struct bpf_insn) with opcode, destination register, source register, offset and immediate fields.
Maps are key-value stores that live in the kernel and persist across runs. They can be hash tables, arrays or ring buffers, and they are shared by the program, other eBPF programs and user space through the bpf(2) system call. Hooks are where programs attach. Kprobes are flexible but fragile across kernel versions; tracepoints are stable because developers place them; XDP handles each packet before the rest of the network stack; and uprobes watch user-space functions, although the program still runs in the kernel.
From the verifier to the JIT
The loader, systemd for example, uses bpf(2) to create maps, load the program with its type, name, license and a log buffer, and attach it to a hook. Before accepting it, the verifier (do_check()) walks the program tracking every register’s state: it checks context reads, helper arguments against their prototypes and exit values. For instance, it requires a map lookup result to be checked against NULL before use. The sd_devices program has 52 instructions, but the verifier processed 217 because of branches, and it gives up at one million (BPF_COMPLEXITY_LIMIT_INSNS).
Each program type has its own verifier ops table, which decides which parts of the context it may access and which helpers it may call. Once verified, bpf_int_jit_compile() turns the bytecode into native x86-64 code placed in executable but non-writable memory. The result is a file descriptor. Programs are reference-counted: the loader’s descriptor, the hook and files pinned in /sys/fs/bpf each hold a reference, and the program is freed when the count drops to zero.
Seeing it on a server with bpftool
With bpftool, packaged as bpftool or in the kernel tools on most distributions, you can inspect all of the above:
# What the kernel supports (program types, maps and helpers)
sudo bpftool feature probe kernel
# Loaded eBPF programs and existing maps
sudo bpftool prog show
sudo bpftool map show
# Programs attached to each cgroup (for example, systemd's)
sudo bpftool cgroup tree
# Verified bytecode and JIT-generated native code (replace 42 with the id)
sudo bpftool prog dump xlated id 42
sudo bpftool prog dump jited id 42
# Programs and maps pinned in the BPF filesystem
ls /sys/fs/bpfCode language: PHP (php)
On a server with services using PrivateDevices=yes or DeviceAllow=, bpftool cgroup tree should list the cgroup_device programs loaded by systemd. For hardening, it is also worth checking that unprivileged eBPF loading is disabled with sysctl kernel.unprivileged_bpf_disabled, which most distributions already do by default.
FAQ
What is eBPF?
A Linux kernel mechanism to load small programs that the kernel verifies, compiles and runs when an event occurs, such as a system call or an incoming packet.
What does the eBPF verifier do?
It walks every branch of the program to check memory accesses, helper arguments and exit values before allowing it to load, with a limit of one million processed instructions.
How do I see which eBPF programs are loaded on my server?
Run sudo bpftool prog show; sudo bpftool cgroup tree lists those attached to cgroups, such as systemd’s.
Sources:
