Andrey Konovalov Fuzzing The Linux Kernel
Andrey Konovalov Fuzzing The Linux Kernel
Andrey Konovalov
Senior Software Engineer, Google
• xairy.github.io
• @andreyknvl
My experience with Linux kernel fuzzing
• Network fuzzing via syscalls
– 3 LPE exploits
No
Generate Execute
Crash?
input program
Yes
Great!
Programs
• Fuzzing — feeding in random inputs until the program crashes
• Programs:
– Application
– Library
– Kernel
– Firmware
– ...
Fuzzing
• Fuzzing — feeding in random inputs until the program crashes
Choose a New
Mutate Execute
random input cover?
Yes
Corpus of
Add to corpus
inputs
Guided generation
• Types of signal
– Code coverage (thus, coverage-guided fuzzing)
– Memory state
– ...
Kernel
vmlinux
module.ko
Kernel inputs: external
Userspace
Kernel
vmlinux
module.ko
• clone, sigaction
– API with callbacks?
• github.com/iovisor/bpf-fuzzer
• Kernel Fuzzing in Userspace (fuzzing ASN.1) by Eric Sesterhenn
Reusing a userspace fuzzer
• Take a userspace fuzzer (AFL, libFuzzer, …)
• Interact with the kernel instead of calling into e.g. a userspace library
• Need to plug kernel coverage into the fuzzer
• Works fine for fuzzing blob-like inputs: filesystem images, netlink, etc.
• But other kernel inputs aren't blobs => Need custom generators/mutators
• SockPuppet: A Walkthrough of a Kernel Exploit for iOS 12.4 by Ned Williamson
– (Turning structure-aware fuzzing into API-aware with libprotobuf-mutator)
Using syzkaller
• See syzkaller talks for usage
• Good at fuzzing API-based interfaces out-of-the-box
• Tip #1: Don't just fuzz mainline with the default config
– Add new descriptions
– Tighten attack surface: fuzz a small number of related syscalls
– Fuzz distro kernels
syzkaller is extensible
• Tip #2: Build your fuzzer on top of syzkaller
– Coverage-Guided USB Fuzzing with Syzkaller [slides] by Andrey Konovalov
– KVM: dev_kvm.txt, common_kvm_amd64.h, ifuzz
• For inspiration:
– Writing the world's worst Android fuzzer, and then improving it by Brandon Falk
– Fuzzing for eBPF JIT bugs in the Linux kernel by Simon Scannell
– Fuzzing the Linux kernel (x86) entry code by Vegard Nossum
Fuzzing tips
Read the code
• Understand the code you're fuzzing
– What kind of inputs it expects
– Which part you are trying to target
• Revert fixes for bugs/CVEs and check that fuzzer finds them
Fast vs smart
• Fast fuzzer
– More execs/sec
• Smart fuzzer
– Better input generation
– Relevant guidance signal
__sanitizer_cov_trace_pc(); // 1
if (...) {
__sanitizer_cov_trace_pc(); // 2
...
}
__sanitizer_cov_trace_pc(); // 3
Userspace interface
• Kernel DebugFS extension that exposes coverage per-thread
void background_thread() {
kcov_remote_start(UNIQUE_ID); // Start collecting coverage associated with UNIQUE_ID.
...
kcov_remote_stop(); // Stop collecting coverage.
}
• People to follow
– @dvyukov, @gamozolabs, whoever else's work was linked in this talk
● The LF Mentoring Program is designed to help new developers with necessary skills
and resources to experiment, learn and contribute effectively to open source
communities.
● Outreachy remote internships program supports diversity in open source and free
software
● Linux Foundation Training offers a wide range of free courses, webinars, tutorials and
publications to help you explore the open source technology landscape.
● Linux Foundation Events also provide educational content across a range of skill levels
and topics, as well as the chance to meet others in the community, to collaborate,
exchange ideas, expand job opportunities and more. You can find all events at
events.linuxfoundation.org.