Kernel & Hypervisor Fuzzing
Advanced Fuzzing Techniques · VR Analysis & Discovery track
9 min read
In this module
Fuzzing the Most Privileged Code
Kernel bugs are some of the most valuable finds in security research. One good one and you escalate from any user to root, kernel mode, the lot. Fuzzing the kernel is awkward, though. A crash kills the whole machine. The attack surface is the syscall interface, not a file you can hand to a parser. And instrumenting the thing requires its own bag of tricks. This lesson walks through the tools used to hunt bugs in the most privileged code on the box.
syzkaller: Google's Kernel Fuzzer
syzkaller is the dominant kernel fuzzer. It's responsible for thousands of Linux kernel bugs. It generates syscall sequences with semi-random but structurally valid arguments, watches the kernel for crashes and sanitizer reports, and minimises plus reproduces any findings on its own.
syzkaller's architecture:
syz-manager (host) | |-- VM 1: syz-executor -> kernel |-- VM 2: syz-executor -> kernel |-- VM 3: syz-executor -> kernel ...syz-manager sits on the host and does the actual fuzzing: it generates and mutates syscall programs, keeps the corpus, and coordinates the VM fleet. Each VM runs syz-executor, which takes programs from the manager over RPC and runs them against the kernel in short-lived subprocesses. When a VM panics, the manager logs the crash and brings the VM back up. Older write-ups show a separate syz-fuzzer process inside each VM; recent syzkaller folded that job into the manager, so the VM side is just the executor.
System Call Descriptions (syzlang)
syzkaller describes syscall interfaces in a small DSL called syzlang. The descriptions pin down argument types, valid ranges, and how arguments relate to each other:
# syzlang description for the read() system callread(fd fd, buf buffer[out], count len[buf])
# syzlang description for socket creationsocket(domain flags[socket_domain], type flags[socket_type], proto int32) fd
socket_domain = AF_UNIX, AF_INET, AF_INET6, AF_NETLINK, AF_PACKETsocket_type = SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_SEQPACKETThese descriptions tell syzkaller:
readtakes a file descriptor, an output buffer, and a length that matches the buffer sizesockettakes domain flags, type flags, and a protocol number, and returns a file descriptor- File descriptors returned by
socketcan be used as thefdargument toread
That bit of structural knowledge is what lets syzkaller produce meaningful syscall sequences instead of random garbage. It knows to call socket() first, thread the returned fd into read(), and stick to flag combinations that actually exist.
Setting Up syzkaller
# Build syzkallergit clone https://github.com/google/syzkallercd syzkallermake
# Configure a kernel with coverage and sanitizers# In kernel .config:# CONFIG_KCOV=y # Coverage instrumentation# CONFIG_KASAN=y # Kernel AddressSanitizer# CONFIG_UBSAN=y # Undefined Behaviour Sanitizer# CONFIG_DEBUG_INFO=y # Debug symbols# CONFIG_CONFIGFS_FS=y # Required by syzkaller
# For uninitialised-memory bugs, build a SEPARATE kernel with KMSAN# instead of KASAN. KMSAN depends on !KASAN and needs Clang:# CONFIG_KMSAN=y # Kernel MemorySanitizer (no KASAN)A syzkaller configuration file specifies the kernel image, VMs, and fuzzing parameters:
{ "target": "linux/amd64", "http": "127.0.0.1:56741", "workdir": "/path/to/workdir", "kernel_obj": "/path/to/linux", "image": "/path/to/vm-image.raw", "sshkey": "/path/to/ssh-key", "syzkaller": "/path/to/syzkaller", "procs": 8, "type": "qemu", "vm": { "count": 4, "kernel": "/path/to/bzImage", "cpu": 2, "mem": 2048 }}KASAN (Kernel AddressSanitizer), KMSAN (Kernel MemorySanitizer), and UBSAN (Undefined Behaviour Sanitizer) are kernel-mode siblings of the userland sanitizers from earlier. They catch memory corruption, uninitialised reads, and undefined behaviour inside the kernel. KASAN and KMSAN can't share a kernel (KMSAN's Kconfig depends on !KASAN, and it only builds with Clang), so fleets like syzbot run them as separate instances. Fuzz with the sanitizers on and your bug count balloons. Plenty of kernel memory corruptions complete silently without KASAN there to wave a flag.
kAFL: Feedback-Driven Kernel Fuzzing
kAFL comes at the problem from a different angle. Instead of producing syscall sequences, it leans on Intel Processor Trace (Intel PT) for hardware-assisted coverage feedback, paired with KVM hypervisor patches so it can fuzz any kernel code path, not just syscall handlers.
Intel PT logs branch decisions in silicon at near-zero overhead, giving you coverage data without touching kernel source. Which is what makes kAFL useful for:
- Closed-source drivers (no source needed)
- UEFI/BIOS firmware (pre-OS code)
- Hypervisor code (code running below the OS)
# kAFL workflow (conceptual)# 1. Configure QEMU/KVM with PT support# 2. Load the target (kernel/driver/firmware) in the VM# 3. Define the fuzzing agent (what input to provide and where)# 4. Run kAFL - it uses PT traces for coverage feedback
# Illustrative only: option names change between kAFL releases,# so check `kafl fuzz --help` for the real ones.kafl fuzz \ --kernel /path/to/bzImage \ --initrd /path/to/initramfs \ --agent /path/to/fuzz_agent \ --seed-dir /path/to/seeds \ --work-dir /path/to/outputSnapshot Fuzzing
Traditional fuzzing restarts the target after each test case. Snapshot fuzzing captures a memory snapshot at a chosen point and restores to it for every new input. The restore is orders of magnitude cheaper than a full reboot — invaluable for kernel work, where boot time alone can swallow seconds per case.
Normal kernel fuzzing: Boot kernel (5-30 sec) -> run syscalls -> crash -> reboot -> repeat
Snapshot fuzzing: Boot kernel -> reach target state -> SNAPSHOT Restore snapshot (milliseconds) -> run with input 1 -> restore Restore snapshot (milliseconds) -> run with input 2 -> restore ...Press play and compare the two loops. Then drag the dirty-pages slider up: restore cost grows with every page an input touches, which is why snapshot fuzzers reset only the dirty pages instead of the whole guest.
Reboot per input vs snapshot fuzzing
One loop reboots the target for every input. The other boots once, takes a snapshot, and after each input copies back only the pages that input dirtied. All timings are illustrative; move the sliders to see what drives throughput.
- Boot
- 10 s
- Run input
- 1 ms
- Per input
- 10 s
- Boot and snapshot (once)
- 11 s
- Run input
- 1 ms
- Restore 500 pages × 2 µs
- 1 ms
- Per input
- 2 ms
Once it's running, the snapshot loop does about 5,001× as many executions per second. The reboot loop pays 10 s of boot for every input; the snapshot loop pays it once.
Nyx restores a VM snapshot between inputs and resets only the pages the last input dirtied. Current kAFL releases run on Nyx's snapshot support.
Snapshot fuzzing is also handy for:
- Device driver fuzzing — snapshot after the driver is loaded, before any input lands
- Stateful protocol fuzzing — snapshot post-handshake and fuzz only the data phase
- UEFI fuzzing — snapshot at the moment the firmware reaches its input-processing entry
Fuzzing Device Drivers
Drivers are juicy targets. They run in kernel mode, parse untrusted hardware input, and are routinely shipped by vendors who give them a fraction of the scrutiny core kernel code receives.
A few approaches to driver fuzzing:
Virtual device fuzzing — stand up a virtual hardware device that feeds malicious data to the driver under test. QEMU's device emulation framework makes this tractable:
# Conceptual: fuzz a USB driver# 1. Write a virtual USB device in QEMU that sends fuzzed descriptors# 2. The kernel loads the target USB driver# 3. The driver processes the malicious descriptors# 4. Monitor for kernel panics, KASAN reports, etc.IOCTL fuzzing — drivers expose functionality through ioctl(). Hammer that interface with assorted command codes and data buffers:
// Simple IOCTL fuzzerint fd = open("/dev/target_device", O_RDWR);for (int cmd = 0; cmd < 0xFFFF; cmd++) { char buf[4096]; // Fill buf with fuzz data ioctl(fd, cmd, buf); // Try each ioctl command}syzkaller does IOCTL fuzzing too, via syzlang descriptions that pin down the valid commands and argument shapes for a given driver.
Hypervisor Fuzzing Concepts
Hypervisor bugs are the holy grail of vuln research. A good one buys you VM escape — break out of the guest, own the host. Fuzzing hypervisors (QEMU, VMware, Hyper-V, Xen) goes after:
- Virtual device emulation — the seam between guest and emulated hardware
- Hypercall handlers — direct guest-to-hypervisor calls
- Memory management — page tables, ballooning, shared memory
It's a hard problem:
- The target sits at a privilege level above the OS
- Crashes need special detection (nested virtualisation)
- The attack surface is sprawling (hundreds of emulated devices)
A few tools show how people get around that. QEMU ships its own in-tree fuzzing targets: build with --enable-fuzzing and libFuzzer drives a device's PIO, MMIO and DMA interfaces from inside the QEMU process, and those targets run continuously on OSS-Fuzz. Nyx (USENIX Security 2021) runs the target hypervisor nested inside a modified KVM and restores fast VM snapshots between inputs, so it can fuzz hypervisors you can't recompile. Microsoft's HyperFuzzer takes a similar hardware-assisted route for Hyper-V, using bespoke instrumentation and monitoring to chase bugs inside hypervisor code.
UEFI Fuzzing
UEFI firmware runs before the operating system and parses plenty of untrusted data along the way: bootloader files, network boot payloads, NVRAM variables. A UEFI bug buys you persistent root that survives OS reinstallation.
# UEFI fuzzing targets:# - Boot service protocols (file system drivers, network stack)# - Runtime services (variable storage, capsule processing)# - SMM handlers (System Management Mode - highest privilege)# - Option ROM processingIntel's HBFA (Host-Based Firmware Analyser) and efiXplorer give you frameworks to work with. The recipe is straightforward: rip UEFI modules out of firmware images, write harnesses that call their entry points with fuzzed input, run the lot under sanitizers, and wait for the crashes.