eBPF is a strength for defense, but it is also code that runs in the kernel: as such, it is an attack surface that you must know in order to reduce it. This page takes the defender's point of view: why loading an eBPF program is a sensitive privilege, which parts of the subsystem an attacker can target, and what this implies in practice. No offensive method here, only what is needed to understand the risk and control it. Audience: administrator or security engineer. For the step-by-step countermeasures, see hardening eBPF.
What you will learn
- Understand why eBPF is both a defense tool and an attack surface
- Identify the three risk zones of the subsystem
- Situate the historical flaws of the verifier
- Assess what an already privileged attacker can do with eBPF
- Link this finding to the hardening measures
Why is eBPF an attack surface?
The paradox is real: the same technology that makes it possible to detect intrusions (see Tetragon (not yet translated) and Falco, which live in the Kubernetes course) gives, in the wrong hands, a way to observe and manipulate the system at the lowest level. An eBPF program runs in the kernel, sees data pass before it is encrypted or after it has been decrypted, and can, depending on its type, influence the behavior of the system.
The attack surface of eBPF breaks down into three distinct zones, which must be handled separately: loading by an unprivileged user, the verifier itself, and abuse by an already privileged attacker.
Zone 1: loading by an unprivileged user
Historically, a user without privilege could load certain eBPF programs. This is the most dangerous zone, because it turns any local account into a potential starting point: a single kernel flaw exploitable from an eBPF program is enough to go from a simple user to root.
This is why recent distributions disable unprivileged eBPF by default (the kernel.unprivileged_bpf_disabled sysctl, detailed in hardening eBPF). Closing this door alone cancels a whole class of public exploits, which worked only from an unprivileged caller.
Zone 2: the verifier itself
The verifier is the guardian that guarantees a program is safe. But it is code, complex, and code has bugs. A defect in the verifier can make it accept a program that actually violates its own rules, for example by accessing out-of-bounds memory.
This is not theoretical. CVE-2021-3490 (CVSS 7.8, HIGH) is the typical example: a defect in the tracking of the 32-bit bounds of logical operations (AND, OR, XOR) let out-of-bounds reads and writes through in the kernel, paving the way to arbitrary code execution. The flaw was in the mechanism supposed to prevent everything.
Zone 3: abuse by an already privileged attacker
The third zone concerns an attacker who has already obtained the necessary privileges (through another flaw, a stolen credential, an overly permissive container). eBPF then becomes a tool to settle in discreetly: observe traffic, capture plaintext credentials at the moment an application handles them, or hide. This is the domain of eBPF rootkits, covered in detail in eBPF rootkits.
The key point for the defender: at this stage, eBPF is not the entry vector, it is a means of persistence and stealth. The defense is therefore also played downstream: monitor the loaded eBPF programs, because an unexpected program can betray a compromise already under way.
What does the defender see?
The good news is that eBPF is observable. Every loaded program is visible with bpftool, whatever tool placed it. On a healthy machine at rest, the list is short and explainable:
sudo bpftool prog show | grep -E '^[0-9]+:' | awk '{print $2}' | sort | uniq -c | sort -rn 6 cgroup_skb 6 cgroup_device 1 tracingThe cgroup_skb and cgroup_device come from systemd (network and device filtering of services); the tracing program is internal to the kernel. Anything that departs from this known reference deserves an investigation. A kprobe, tracepoint or tracing program absent from your reference is a strong signal. Visibility is your best asset: an attacker can load a program, but cannot easily make it invisible to a defender who knows where to look.
The reference is taken on each family of machines, never once and for all. The output above comes from an Ubuntu 24.04 VM, where the tracing program is hid_tail_call, internal to the kernel. On AlmaLinux 10.2, the same reading at rest gives another list, just as legitimate: an lsm program named restrict_filesystems (placed by systemd), a socket_filter, 12 cgroup_skb and 7 cgroup_device. Comparing an Alma machine to an Ubuntu reference would raise false alarms.
How do you trace an unknown program back to its process?
Spotting a program is not enough: you must know who loaded it to decide. The lab played this gesture with a bpftrace probe on the sched_process_exec tracepoint, and the two distributions do not answer the same way. On AlmaLinux 10.2 (kernel 6.12, bpftool 7.7), bpftool prog show directly shows the owner (abridged output):
135: tracepoint name tracepoint_sched_sched_process_exec_1 ... pids bpftrace(21860)On Ubuntu 24.04 (kernel 6.8, bpftool 7.4), the same line has no pids field, and bpftool link show does not list the probe. The command that gives the PID on both is bpftool perf show, which links each program attached to a performance event to the process that holds it:
sudo bpftool perf showpid 1821 fd 7: prog_id 79 tracepoint sched_process_execThe prog_id links this line to bpftool prog show, the pid leads to the process, and systemctl status <pid> gives the service that carries it. Last resort, valid everywhere: a process that holds an eBPF program keeps an anon_inode:bpf-prog descriptor, visible with sudo ls -l /proc/*/fd 2>/dev/null | grep bpf-prog. Stopping the service with systemctl stop then systemctl disable is enough to make it disappear: a simple kill does not hold if the unit carries Restart=always, which restarts the process right away. Other traps measured in the lab: systemctl mask refuses to overwrite a real unit file present in /etc/systemd/system (with or without --force), so delete or move that file before masking; and removing the file of a running unit leaves the process running.
How do you reduce the surface?
Facing these three zones, the approach is consistent and comes down to a few principles, developed in the hardening lesson.
- Close zone 1: keep unprivileged eBPF disabled.
- Reduce zone 2: keep the kernel up to date, the only defense against verifier flaws.
- Monitor zone 3: regularly audit the loaded programs, apply least privilege (
CAP_BPF, withCAP_PERFMON, rather thanrootfor agents designed for it, a path not replayed in the lab;bpftraceand the BCC diagnostic tools remainroottools).
These measures do not hamper the legitimate uses of eBPF: an observability or security tool that you deployed yourself runs perfectly within this framework. They only close the doors that an attacker would try to use, by applying least privilege to the subsystem.
Hands-on practice
On the lab VM, a service with an innocuous name loads an eBPF program into the kernel. You list the programs with bpftool, you trace back to the process then to the systemd service that carry the unknown one, you name its type, then you stop this service and prevent it from coming back. The validation also checks that you did not touch the programs that systemd loads itself.
Key takeaways
- eBPF is double-edged: a defense tool, but also an attack surface because it runs code in the kernel.
- Zone 1, unprivileged loading: the most dangerous, disabled by default on recent distributions.
- Zone 2, the verifier: it is code, it has had flaws (e.g. CVE-2021-3490, CVSS 7.8); the defense is an up-to-date kernel.
- Zone 3, abuse by a privileged attacker: eBPF then serves as persistence and stealth, not as an entry vector.
- eBPF remains observable:
bpftoolshows every loaded program; the unexplained is suspect. - Reducing the surface does not hamper legitimate uses: it is least privilege applied to the subsystem.
Knowledge check
Check that the essentials of this lesson are in place. The questions only cover what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: eBPF rootkits: understand the threat and detect it
A new full quiz with random questions
Work again only on the questions you missed