KCoFI: Complete Control-Flow Integrity for Commodity Operating System Kernels John Criswell, Nathan Dautenhahn, and Vikram Adve Department of Computer Science University of Illinois at Urbana-Champaign Email: fcriswell,dautenh1,[email protected] Abstract that is comprehensive, efficient, and straightforward to im- plement. However, operating systems pose three challenges We present a new system, KCoFI, that is the first we for existing CFI techniques. First, not all targets of indirect know of to provide complete Control-Flow Integrity protection control transfers can be determined statically from the kernel for commodity operating systems without using heavyweight code. Interrupts can occur at any instruction boundary, so the complete memory safety. Unlike previous systems, KCoFI kernel must be able to transfer control to any interrupted protects commodity operating systems from classical control- instruction on a return from interrupt. Second, operating flow hijack attacks, return-to-user attacks, and code segment systems operations affect control flow in complicated ways. modification attacks. We formally verify a subset of KCoFI’s Signal handler dispatch, for example, modifies the program design by modeling several features in small-step semantics counter in interrupted program state saved in memory [7], [8], and providing a partial proof that the semantics maintain and efficient user-kernel memory copying functions modify control-flow integrity. The model and proof account for oper- interrupted kernel state [7] to recover from page protection ations such as page table management, trap handlers, context faults. Third, operating systems have access to privileged switching, and signal delivery. Our evaluation shows that hardware that invalidate assumptions commonly made by CFI KCoFI prevents all the gadgets found by an open-source techniques. As an example, some CFI systems [4], [9] assume Return Oriented Programming (ROP) gadget-finding tool in the that the code segment is non-writable. Errant DMA and MMU FreeBSD kernel from being used; it also reduces the number configurations can invalidate that assumption [5], [6]. of indirect control-flow targets by 98.18%. Our evaluation also shows that the performance impact of KCoFI on web server Most solutions for enforcing CFI [4], [10], [9] do not bandwidth is negligible while file transfer bandwidth using protect commodity operating system code. The few that do OpenSSH is reduced by an average of 13%, and at worst protect system-level code have serious limitations: Hyper- 27%, across a wide range of file sizes. PostMark, an extremely Safe [6] only protects a hypervisor and does not provide file-system intensive benchmark, shows 2x overhead. Where control-flow integrity for operations found in operating systems comparable numbers are available, the overheads of KCoFI (e.g., signal handler dispatch); it also does not protect against are far lower than heavyweight memory-safety techniques. return to user (ret2usr) attacks [11] that corrupt the program counter saved on interrupts, traps, and system calls to execute code belonging to less-privileged software. The kGuard [11] I. INTRODUCTION system, designed to thwart ret2usr attacks, enforces a very weak CFI variant that only ensures that control-flow is directed Despite much research, memory safety attacks are still a at virtual addresses within the kernel; some of its protection is scourge for C/C++ programmers. Worse yet, most commodity probabilistic, and it does not handle attacks that use the MMU operating systems are written in C/C++ and are therefore to change the instructions within the code segment. Secure susceptible to memory safety attacks. As the operating system Virtual Architecture (SVA) [12], [5] provides comprehensive (OS) is part of the Trusted Computing Base (TCB) in nearly all protection against control hijacking attacks, but it does so with commodity systems, a vulnerability in the OS can undermine heavyweight memory-safety techniques that have relatively the security of an entire system. high overheads even after being optimized by techniques using Many memory safety attacks work by diverting a pro- sophisticated whole-program pointer analysis [13]. gram’s control flow to instructions of the attackers choosing; Furthermore, only the original CFI system [4] formally these instructions may be injected by the attacker [1] or proves that it enforces control-flow integrity, and it does not may already exist within the program [2], [3]. Control-flow model features such as virtual memory, trap handlers, context integrity (CFI) is a family of security policies that thwart such switching, and signal delivery found in modern operating sys- attacks. Traditional CFI requires that all computed branches tems. Having an approach for enforcing control-flow integrity (e.g., returns from functions and indirect function calls) jump on these operations that has been formally verified would to virtual addresses that are designated as correct via static increase confidence that the approach works correctly. analysis [4]. Additional restrictions to CFI [5], [6] require that the instructions do not change. We have built a system named KCoFI (Kernel Control Flow Integrity, pronounced “coffee”) that aims to provide compre- Enforcing CFI on commodity operating system kernel hensive, efficient, and simple protection against control flow code could provide protection against control hijack attacks attacks for a complete commodity operating system. KCoFI operates between the software stack and processor. Essentially, to modify any memory location. We additionally assume that KCoFI uses traditional label-based protection for programmed the attacker is using such corruption to modify control-data, indirect jumps [4] but adds a thin run-time layer linked into the including targets that are not of concern to traditional CFI OS that protects some key OS data structures like thread stacks techniques, e.g., processor state (including the PC and stack and monitors all low-level state manipulations performed by pointer) saved in memory after a context-switch; trap and the OS. Our system provides the first comprehensive control- interrupt handler tables; invalid pointer values in user-kernel flow integrity enforcement for commodity OS kernels that copy operations; malicious MMU reconfiguration; etc. Non- does not rely on slower and more sophisticated memory safety control data attacks [15] are excluded from our model. techniques. Our protection thwarts both classical control flow Notice that external attackers in our model can influence attacks as well as ret2usr attacks. To verify that our design OS behavior only through system calls, I/O, and traps. For correctly enforces control-flow integrity, we have built a formal example, dynamically loaded device drivers are assumed not model of key features of our system (including the new to be malicious, but may also be buggy (just like the rest of protections for OS operations) using small-step semantics and the OS kernel), and will be protected from external attack. provided a partial proof that our design enforces control-flow We assume that the system is employing secure boot features integrity. The proofs are encoded in the Coq proof system and such as those found in AEGIS [16] or UEFI [17] to ensure are mechanically verified by Coq. that KCoFI and the kernel are not corrupted on disk and are The contributions of our system are as follows. the first pieces of software loaded on boot. We further assume that the attacker does not have physical access to the machine; • We provide the first complete control-flow integrity hardware-based attacks are outside the scope of our model. solution for commodity operating systems that does not rely on sophisticated whole-program analysis or III. KCOFI INFRASTRUCTURE a much stronger and more expensive security policy like complete memory safety. KCoFI has several unique requirements. First, it must in- strument commodity OS kernel code; existing CFI enforcement • We have built a formal model of kernel execution with mechanisms use either compiler or binary instrumentation [4], small-step semantics that supports virtual to physical [10], [18]. Second, KCoFI must understand how and when address translation, trap handling, context switching, OS kernel code interacts with the hardware. For example, it and signal handler dispatch. We use the model to must understand when the OS is modifying hardware page provide a partial proof that our design prevents CFI tables in order to prevent errors like writeable and executable violations. (We do not verify our implementation.) memory. Third, KCoFI must be able to control modification of • We evaluate the security of our system for the interrupted program state in order to prevent ret2usr attacks. FreeBSD 9.0 kernel on the x86-64 architecture. We The Secure Virtual Architecture (SVA) [12], [5] provides find that all the Return Oriented Programming (ROP) the infrastructure that KCoFI needs. As Figure 1 shows, gadgets found by the ROPGadget tool [14] become SVA interposes a compiler-based virtual machine between the unusable as branch targets. We also find that our sys- hardware and the system software (such as an operating system tem reduces the average number of possible indirect or hypervisor). All software, including the operating system branch targets by 98.18%. and/or hypervisor, is compiled to the virtual instruction set • We evaluate the performance of our system and find that SVA provides. The SVA virtual machine (VM) translates that KCoFI has far lower
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages16 Page
-
File Size-