Kafl: Hardware-Assisted Feedback Fuzzing for OS Kernels
Total Page:16
File Type:pdf, Size:1020Kb
kAFL: Hardware-Assisted Feedback Fuzzing for OS Kernels Sergej Schumilo, Cornelius Aschermann, and Robert Gawlik, Ruhr-Universität Bochum; Sebastian Schinzel, Münster University of Applied Sciences; Thorsten Holz, Ruhr-Universität Bochum https://www.usenix.org/conference/usenixsecurity17/technical-sessions/presentation/schumilo This paper is included in the Proceedings of the 26th USENIX Security Symposium August 16–18, 2017 • Vancouver, BC, Canada ISBN 978-1-931971-40-9 Open access to the Proceedings of the 26th USENIX Security Symposium is sponsored by USENIX kAFL: Hardware-Assisted Feedback Fuzzing for OS Kernels Sergej Schumilo Cornelius Aschermann Robert Gawlik Ruhr-Universität Bochum Ruhr-Universität Bochum Ruhr-Universität Bochum Sebastian Schinzel Thorsten Holz Münster University of Applied Sciences Ruhr-Universität Bochum Abstract free vulnerabilities, are known threats for programs run- Many kinds of memory safety vulnerabilities have ning in user mode as well as for the operating system been endangering software systems for decades. (OS) core itself. Past experience has shown that attack- Amongst other approaches, fuzzing is a promising ers typically focus on user mode applications. This is technique to unveil various software faults. Recently, likely because vulnerabilities in user mode programs are feedback-guided fuzzing demonstrated its power, pro- notoriously easier and more reliable to exploit. How- ducing a steady stream of security-critical software bugs. ever, with the appearance of different kinds of exploit Most fuzzing efforts—especially feedback fuzzing—are defense mechanisms – especially in user mode, it has limited to user space components of an operating system become much harder nowadays to exploit known vul- (OS), although bugs in kernel components are more nerabilities. Due to those advanced defense mechanisms severe, because they allow an attacker to gain access in user mode, the kernel has become even more appeal- to a system with full privileges. Unfortunately, kernel ing to an attacker since most kernel defense mechanisms components are difficult to fuzz as feedback mechanisms are not widely deployed in practice. This is due to more (i.e., guided code coverage) cannot be easily applied. complex implementations, which may affect the system Additionally, non-determinism due to interrupts, kernel performance. Furthermore, some of them are not part threads, statefulness, and similar mechanisms poses of the official mainline code base or even require sup- problems. Furthermore, if a process fuzzes its own port for the latest CPU extension (e.g., SMAP / SMEP kernel, a kernel crash highly impacts the performance of on x86-64). Additionally, when compromising the OS, the fuzzer as the OS needs to reboot. an attacker typically gains full access to the system re- In this paper, we approach the problem of coverage- sources (except for virtualized systems). Kernel-level guided kernel fuzzing in an OS-independent and vulnerabilities are usually used for privilege escalation hardware-assisted way: We utilize a hypervisor and In- or to gain persistence for kernel-based rootkits. tel’s Processor Trace (PT) technology. This allows us For a long time, fuzzing has been a critical compo- to remain independent of the target OS as we just re- nent in testing and establishing the quality of software. quire a small user space component that interacts with However, with the development of American Fuzzy Lop the targeted OS. As a result, our approach introduces (AFL), smarter fuzzers have gained significant traction almost no performance overhead, even in cases where in the industry [1] as well as in research [8, 14, 35, 37]. the OS crashes, and performs up to 17,000 executions This trend was further amplified by Google’s OSS Fuzz per second on an off-the-shelf laptop. We developed a project that successfully found—and continues to find— framework called kernel-AFL (kAFL) to assess the secu- a significant number of critical bugs in highly security- rity of Linux, macOS, and Windows kernel components. relevant software. Finally, DARPA’s Cyber Grand Chal- Among many crashes, we uncovered several flaws in the lenge showed that fuzzing remains highly relevant for ext4 driver for Linux, the HFS and APFS file system of the state-of-the-art in bug finding. The latest generation macOS, and the NTFS driver of Windows. of feedback-driven fuzzers generally uses mechanisms to learn which inputs are interesting and which are not. 1 Introduction Interesting inputs are used to produce more inputs that may trigger new execution paths in the target. Inputs that Several vulnerability classes such as memory corrup- did not trigger interesting behavior in the program are tions, race-conditional memory accesses, and use-after- discarded. Thus, the fuzzer is able to “learn” the input USENIX Association 26th USENIX Security Symposium 167 format. This greatly improves efficiency and usability • Hardware-assisted feedback: Our fuzzing ap- of fuzzers, especially by reducing the need for an oracle proach utilizes Intel’s Processor Trace (PT) tech- which generates semi-valid inputs or an extensive corpus nology, and thus has a very small performance over- that covers most paths in the target. head. Additionally, our PT-decoder is up to 30 times Unfortunately, AFL is limited to user space applica- faster than Intel’s ptxed decoder. Thereby, we ob- tions and lacks kernel support. Fuzzing kernels has a tain complete trace information that we use to guide set of additional challenges when compared to userland our evolutionary fuzzing algorithm to maximize test (or ring 3) fuzzing: First, crashes and timeouts mandate coverage. the use of virtualization to be able to catch faults and • Extensible and modular design: Our modular de- continue gracefully. Second, kernel-level code has sig- sign separates the fuzzer, the tracing engine, and nificantly more non-determinism than the average ring 3 the target to fuzz. This allows to support additional program—mostly due to interrupts, kernel threads, state- x86 operating systems’ kernel space and user space fulness, and similar mechanisms. This makes fuzzing components, without the need to develop a system kernel code challenging. Furthermore, there is no equiv- driver for the target OS. alent to command line arguments or stdin to interact with kernels or drivers in a generic way except for plain • kernel-AFL: We incorporated our design con- interrupt or sysenter instructions. In addition, the Win- cepts and developed a prototype called kernel-AFL dows kernel and many relevant drivers and core compo- (kAFL) which was able to find several vulnerabili- nents (for Windows, macOS and even Linux) are closed ties in kernel components of different operating sys- source and cannot be instrumented by common tech- tems. To foster research on this topic, we make the niques without a significant performance overhead. source code of our prototype implementation avail- Previous approaches to kernel fuzzing were not able at https://github.com/RUB-SysSec/kAFL. portable because they relied on certain drivers or recom- pilation [10, 34], were very slow due to emulation to 2 Technical Background gather feedback [7], or simply were not feedback-driven at all [11]. We use the Intel Processor Trace (Intel PT) extension of In this paper, we introduce a new technique that al- IA-32 CPUs to obtain coverage information for ring 0 lows applying feedback fuzzing to arbitrary (even closed execution of arbitrary (even closed-source) OS code. To source) x86-64 based kernels, without any custom ring facilitate efficient and OS-independent fuzzing, we also 0 target code or even OS-specific code at all. We make use of Intel’s hardware virtualization features (In- discuss the design and implementation of kernel-AFL tel VT-x). Hence, our approach requires a CPU that sup- (kAFL), our prototype implementation of the proposed ports both Intel VT-x and Intel PT. This section provides a techniques. The overhead for feedback generation is very brief overview of these hardware features and establishes small (less than 5%) due to a new CPU feature: Intel’s the technical foundation for the later sections. Processor Trace (PT) technology provides control flow information on running code. We use this information 2.1 x86-64 Virtual Memory Layouts to construct a feedback mechanism similar to AFL’s in- Every commonly used x86-64 OS uses a split virtual strumentation. This allows us to obtain up to 17,000 ex- memory layout: The kernel is commonly located at the ecutions per second on an off-the-shelf laptop (Thinkpad upper half of each virtual memory space, whereas each T460p, i7-6700HQ and 32 GB RAM) for simple target user mode process memory is located in the lower half. drivers. Additionally, we describe an efficient way for For example, the virtual memory space of Linux is typ- dealing with the non-determinisms that occur during ker- ically split into kernel space (upper half) and user space nel fuzzing. Due to the modular design, kAFL is exten- (lower half) each with a size of 247 due to the 48-bit sible to fuzz any x86/x86-64 OS. We have applied kAFL virtual address limit of current x86-64 CPUs. Hence, to Linux, macOS, and Windows and found multiple pre- the kernel memory is mapped to any virtual address viously unknown bugs in kernel drivers in those OSs. space and therefore it is located always at the same In summary, our contributions in this paper are: virtual address. If an user mode process executes the syscall/sysenter instruction for kernel interaction or • OS independence: We show that feedback-driven causes an exception that has to be handled by the OS, the fuzzing of closed-source kernel mode components OS will keep the current CR3 value and thus does not is possible in an (almost) OS-independent manner switch the virtual memory address space. Instead, the by harnessing the hypervisor (VMM) to produce current virtual memory address space is reused and the coverage.