Kernel Fuzzing with syzkaller and the eBPF Verifier
User-space fuzzers feed bytes to a function. A kernel takes something richer: sequences of system calls whose arguments are file descriptors returned by earlier calls, pointers to structures, flags with meanings, lengths that must match buffers. And one kernel feature, eBPF, goes further and accepts whole programs from user space, which a verifier must prove safe before they run in the kernel. This lesson explains how syzkaller fuzzes the first kind of input, and builds a toy verifier for the second to show both how it works and how its bugs are found.
syzkaller: fuzzing system-call sequences
syzkaller (Google, open source) is the standard kernel fuzzer, used for Linux and also for several BSDs, Fuchsia and others. Its design answers each difficulty of kernel input:
| Difficulty | syzkaller's answer |
|---|---|
| inputs are call sequences with typed arguments | syzlang, a description language for system calls, structures, flags and resources (file descriptors that one call produces and another consumes) |
| coverage of kernel code | the kernel's kcov interface reports the basic blocks a thread executed in the kernel |
| a crash takes the kernel down | the fuzzed kernels run in virtual machines (usually QEMU), many in parallel, managed by syz-manager |
| silent memory errors | the kernel is built with KASAN, KMSAN, KCSAN, UBSAN |
| making a report useful | automatic reproduction and minimisation into a syzkaller program and, when possible, a stand-alone C reproducer |
A syzlang description for a hypothetical toy driver /dev/tlv (illustrative: the shape of real descriptions, not a file from the kernel tree):
resource fd_tlv[fd]
openat$tlv(fd const[AT_FDCWD], file ptr[in, string["/dev/tlv"]], flags flags[open_flags], mode const[0]) fd_tlv
ioctl$TLV_SET_NAME(fd fd_tlv, cmd const[TLV_SET_NAME], arg ptr[in, tlv_name])
ioctl$TLV_GET_SUM(fd fd_tlv, cmd const[TLV_GET_SUM], arg ptr[out, int32])
tlv_name {
len len[data, int8]
data array[int8, 0:255]
}From that, syzkaller knows to open the device first, pass the returned descriptor to the ioctls, and fill len consistently with data most of the time and inconsistently some of the time, which is exactly where bugs like the toy parser's live. A lab session on a test machine looks like this (abridged; scope: a throwaway kernel built for fuzzing, in local QEMU VMs):
lab@fuzz-host:~/syz$ ./bin/syz-manager -config tlv.cfg
2026/11/20 10:02:11 loading corpus...
2026/11/20 10:02:14 booting test machines...
2026/11/20 10:02:41 VMs 4, executed 18210, cover 41233, signal 52906/55012, crashes 0, repro 0
2026/11/20 10:31:07 VMs 4, executed 902114, cover 47810, signal 60122/63390, crashes 1, repro 1
2026/11/20 10:31:07 vm-2: crash: KASAN: stack-out-of-bounds Write in tlv_ioctl
2026/11/20 10:34:52 reproduced: KASAN: stack-out-of-bounds Write in tlv_ioctl (C repro available)The crash title (KASAN: ... Write in tlv_ioctl) is syzkaller's deduplication key, the kernel version of the stack hash in Crash Triage. syzbot runs the same system continuously on upstream kernels, reports to the maintainers' mailing lists with reproducers, and tracks fixes, a public example of continuous fuzzing as a disclosure pipeline.
eBPF and its verifier
eBPF lets user space load small programs into the kernel: packet filters, tracing probes, security hooks. Because they run in kernel mode, the kernel must be sure they cannot read or write outside their own memory, loop forever, or leak kernel pointers. The verifier checks every possible path through the program before loading it, tracking for every register its type (scalar, pointer to the packet, pointer to a map value...) and the range of values it can hold. A memory access is allowed only if the range proves it in bounds.
The toy below has one kind of memory access, map_load r (read entry r of a 16-entry map), a byte read from the packet (range 0 to 255), and with a constant and a conditional jump. The verifier explores every path and keeps a range per register; the jump splits a range in two (r > k on the jump, r <= k on the fall-through). A concrete interpreter with a bounds-checked map is the runtime oracle. It runs in your browser:
# A toy eBPF-style verifier: tracks the range [lo, hi] of every register on every path.
MAP_SIZE = 16
def verify(prog, buggy=False):
"""Explore all paths (jumps go forward only, so there are no loops). Return None if safe."""
work = [(0, {"r1": None, "r2": None})] # (pc, register ranges); None = uninitialised
while work:
pc, regs = work.pop()
op, *a = prog[pc]
regs = dict(regs)
if op == "load_byte": # r = one byte of the packet: [0, 255]
regs[a[0]] = (0, 255)
elif op == "and":
lo, hi = regs[a[0]]
regs[a[0]] = (0, min(hi, a[1]))
elif op == "jgt": # if r > k: goto target
lo, hi = regs[a[0]]
k = a[1]
if hi > k:
work.append((a[2], {**regs, a[0]: (max(lo, k + 1), hi)}))
if lo <= k: # fall-through: r <= k
regs[a[0]] = (lo, k if not buggy else k - 1) # seeded bug: off by one
else:
continue
elif op == "map_load": # r0 = map[r]
if regs[a[0]] is None:
return f"pc {pc}: {a[0]} used before it was set"
lo, hi = regs[a[0]]
if lo < 0 or hi >= MAP_SIZE:
return f"pc {pc}: map index {a[0]} in [{lo}, {hi}] may be outside [0, {MAP_SIZE - 1}]"
elif op == "exit":
continue
work.append((pc + 1, regs))
return None
def run(prog, packet_byte):
"""The concrete interpreter, with a bounds-checked map: the runtime oracle."""
regs, pc = {}, 0
while True:
op, *a = prog[pc]
if op == "load_byte": regs[a[0]] = packet_byte
elif op == "and": regs[a[0]] &= a[1]
elif op == "jgt" and regs[a[0]] > a[1]:
pc = a[2]; continue
elif op == "map_load" and not 0 <= regs[a[0]] < MAP_SIZE:
return f"OUT OF BOUNDS: map[{regs[a[0]]}]"
elif op == "exit": return "ok"
pc += 1
PROGRAMS = {
"unchecked": [("load_byte", "r1"), ("map_load", "r1"), ("exit",)],
"masked": [("load_byte", "r1"), ("and", "r1", 15), ("map_load", "r1"), ("exit",)],
"bounded": [("load_byte", "r1"), ("jgt", "r1", 15, 3), ("map_load", "r1"), ("exit",)],
"bounded16": [("load_byte", "r1"), ("jgt", "r1", 16, 3), ("map_load", "r1"), ("exit",)],
"uninit": [("map_load", "r2"), ("exit",)],
}
for name, prog in PROGRAMS.items():
print(f"{name:<10} {verify(prog) or 'accepted'}")
print("\nverifier with a seeded off-by-one, checked against the interpreter on all 256 packets:")
for name, prog in PROGRAMS.items():
if verify(prog, buggy=True) is None:
bad = [b for b in range(256) if run(prog, b) != "ok"]
print(f"{name:<10} accepted; runtime violations for packet bytes {bad or 'none'}")unchecked pc 1: map index r1 in [0, 255] may be outside [0, 15]
masked accepted
bounded accepted
bounded16 pc 2: map index r1 in [0, 16] may be outside [0, 15]
uninit pc 0: r2 used before it was set
verifier with a seeded off-by-one, checked against the interpreter on all 256 packets:
masked accepted; runtime violations for packet bytes none
bounded accepted; runtime violations for packet bytes none
bounded16 accepted; runtime violations for packet bytes [16]
The correct verifier accepts exactly the safe programs: masking with 15 or jumping away when r1 > 15 both prove r1 is in [0, 15]. It rejects the unchecked load, the use of an uninitialised register, and bounded16, whose author made an off-by-one (> 16 leaves 16 possible).
Then the verifier itself gets a seeded off-by-one: on the fall-through of jgt r, k it records r <= k - 1 instead of r <= k. Now bounded16 is accepted, and the interpreter shows the consequence: packet byte 16 reads map[16], one entry past the end. In a real kernel such a verifier bug is serious: a program the kernel believes safe performs out-of-bounds accesses in kernel memory. Several real eBPF vulnerabilities have been exactly this kind of range-tracking mistake, which is why many distributions disable unprivileged eBPF by default (the kernel option CONFIG_BPF_UNPRIV_DEFAULT_OFF, added in 2021, sets kernel.unprivileged_bpf_disabled = 2: off, but an administrator may turn it back on).
How verifier bugs are detected
The second half of the example is the technique: differential testing between what the verifier claims and what execution does. Research tools fuzz the verifier by generating programs, keeping those it accepts, running them on many inputs under a runtime check (in the kernel: KASAN, or extra assertions inserted after verification), and reporting any accepted program that violates a bound. Formal methods are also used: the range and bit-tracking logic ("tnums") of the Linux verifier has been checked with SMT solvers in academic work.
How the risk is reduced
- Fix the range logic and add the failing program as a verifier self-test (the Linux tree has hundreds).
- Defence in depth after verification: the kernel masks pointer arithmetic and adds runtime checks in places where speculation or verifier mistakes could matter.
- Restrict who can load programs:
kernel.unprivileged_bpf_disabled, capabilities (CAP_BPF), and LSM hooks. - For syzkaller findings: fix, add the C reproducer as a regression test, and backport to stable kernels.
Pitfalls
- Trusting the verifier as a sandbox for hostile users. It is complex code; treat unprivileged eBPF as attack surface.
- Kernel fuzzing on your workstation's own kernel. Use VMs with throwaway kernels; a kernel crash takes everything down.
- Ignoring "unreproducible" crashes. Races and rare paths often reproduce poorly; KCSAN and repeated runs help.
Practice
1. Add an add r, k instruction to the toy verifier. What range does it produce, and what new risk appears?
(lo + k, hi + k). The risk is overflow: with 64-bit registers in a real verifier, ranges near the limits wrap around, and getting the wrap-around rules wrong is a classic verifier bug. The toy, with Python's unbounded integers, cannot show it.
2. Why does the verifier need to explore both sides of every jump?
Each side has different facts about the registers (r > k or r <= k), and a memory access may be safe on one side and not the other. A path-insensitive verifier would have to assume the full range everywhere and reject safe programs.
3. In the syzlang description, why does len[data, int8] matter for finding bugs?
It tells syzkaller that the field is the length of data, so it usually generates consistent pairs (getting past basic validation) and sometimes deliberately inconsistent ones (testing that validation). Random bytes would almost always fail the first check.
Test yourself
What does kcov give syzkaller?
- Crash reports
- Coverage of kernel code executed by the fuzzing thread
- System-call descriptions
- Virtual machines
What does the eBPF verifier track to decide whether a map access is safe?
- Execution time
- For every path, each register's type and range of possible values
- The program's name
- The user's privileges only
How was the seeded verifier bug detected?
- By reading the logs
- By running accepted programs on all inputs with a bounds-checked interpreter: a differential test
- By KASLR
- By a syzlang description
Why do many distributions disable unprivileged eBPF?
- eBPF is slow
- Verifier bugs would let any local user run unsafe code in the kernel
- It needs a GPU
- It conflicts with seccomp