SGXBOUNDS: Memory Safety for Shielded Execution
Total Page:16
File Type:pdf, Size:1020Kb
SGXBOUNDS: Memory Safety for Shielded Execution Dmitrii Kuvaiskiiy Oleksii Oleksenkoy Sergei Arnautovy Bohdan Trachy Pramod Bhatotia∗ Pascal Felberz Christof Fetzery yTU Dresden ∗The University of Edinburgh zUniversity of Neuchâtel Abstract Shielded execution aims to protect confidentiality and Shielded execution based on Intel SGX provides strong secu- integrity of applications when executed in an untrusted envi- rity guarantees for legacy applications running on untrusted ronment [19, 22]. The main idea is to isolate the application platforms. However, memory safety attacks such as Heart- from the rest of the system (including privileged software), bleed can render the confidentiality and integrity properties using only a narrow interface to communicate to the outside, of shielded execution completely ineffective. To prevent these potentially malicious world. Since this interface defines the attacks, the state-of-the-art memory-safety approaches can be security boundary, checks are performed to prevent the un- used in the context of shielded execution. trusted environment from attacks on the shielded application In this work, we first showcase that two prominent software- in an attempt to leak confidential data or subvert its execution. and hardware-based defenses, AddressSanitizer and Intel Shielded execution, however, does not protect the program MPX respectively, are impractical for shielded execution due against memory safety attacks [74]. These attacks are wide- to high performance and memory overheads. This motivated spread, especially on legacy applications written in unsafe languages such as C/C++. In particular, a remote attacker can our design of SGXBOUNDS—an efficient memory-safety approach for shielded execution exploiting the architectural violate memory safety by exploiting the existing program features of Intel SGX. Our design is based on a simple com- bugs to invoke out-of-bounds memory accesses (aka buffer bination of tagged pointers and compact memory layout. overflows). Thereafter, the attacker can hijack program control flow or leak confidential data [14, 42]. We implemented SGXBOUNDS based on the LLVM com- piler framework targeting unmodified multithreaded appli- To validate our claim, we reproduced many publicly avail- cations. Our evaluation using Phoenix, PARSEC, and RIPE able memory safety exploits inside the secure enclave (see x7 for details), including the infamous Heartbleed attack in benchmark suites shows that SGXBOUNDS has performance and memory overheads of 17% and 0:1% respectively, while Apache with OpenSSL [14] as well as vulnerabilities in Mem- providing security guarantees similar to AddressSanitizer cached [12], Nginx [13], and in 16 test cases from the RIPE and Intel MPX. We have obtained similar results with SPEC security benchmark [80]. These examples highlight that a CPU2006 and four real-world case studies: SQLite, Mem- single exploit can completely compromise the integrity and cached, Apache, and Nginx. confidentiality properties of shielded execution. To prevent exploitation of these bugs, a number of memory safety approaches have been proposed to automatically retrofit 1. Introduction bounds checking in legacy programs [17, 20, 26, 35, 55, 58]. Software security is often cited as a key barrier to the adoption Among these, we experimented with two prominent software- of cloud services [6, 7, 75]. In this context, trusted execution and hardware-based memory protection mechanisms in the environments provide mechanisms to make cloud services context of shielded execution: AddressSanitizer [69] and Intel more resilient against security attacks [1, 53]. Memory Protection Extensions (MPX) [9], respectively. In this work, we focus on Intel Software Guard Extensions Unfortunately, these approaches exhibit high performance (SGX) [53], a recently proposed set of ISA extensions for and memory overheads, thus rendering them impractical for trusted execution. Intel SGX provides an abstraction of se- shielded execution. For instance, consider the motivating ex- cure enclave— a memory region opaque to other software ample of SQLite evaluated against the speedtest benchmark including the hypervisor and the OS—that can be used to (shipped with SQLite) with increasing working set items. achieve shielded execution for unmodified legacy applications Figure 1 compares the performance and memory overheads on untrusted infrastructure. of SQLite hardened with AddressSanitizer and Intel MPX running inside an SGX enclave. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee The experiment shows that Intel MPX performs so poorly provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. that it crashes due to insufficient memory already after tiny Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]. working set of 100 (corresponding to memory consump- EuroSys ’17, April 23-26, 2017, Belgrade, Serbia tion of 60MB for the native SGX execution). AddressSan- c 2017 Copyright held by the owner/author(s). Publication rights licensed to ACM. ISBN 978-1-4503-4938-3/17/04. $15.00 itizer is more stable, but performs up to 3:1× slower than DOI: http://dx.doi.org/10.1145/3064176.3064192 205 DRAM (64GB) 1.4 SGX ASan MPX SGXBounds s) 3 1.2 Enclave Page Cache (~94MB) 10 × 1 CPU Cache (8MB) 3.1x MEE encryption EPC thrashing 0.8 (1 x —1 2 x ) EPC paging 0.6 MPX crashes due to (2 x —2 0 0 0 x ) insufficient memory 0.4 0.2 1.3x Figure 2: Memory hierarchy and relative performance Execution time ( 0 overheads of Intel SGX w.r.t. native execution [19]. 3.5 3 tions, (2) increased availability instead of the usual fail-stop se- mantics by tolerating out-of-bounds accesses based on failure- 2.5 57x 2 oblivious computing [64, 65], and lastly, (3) generic APIs for SGXBounds 3.1x 1.5 overlaps with SGX objects’ metadata management to support new use-cases. 1 SGXBOUNDS is targeted but not inherently tied to SGX 0.5 Memory used (GB) enclaves. Our approach is also applicable to programs that use 0 64-bit registers to hold pointers but can fit in 32-bit address 10 20 50 100 200 400 600 800 1000 1100 1200 Working set items space. However, as we show in our evaluation, SGXBOUNDS Figure 1: Performance and memory overheads of SQLite. provides no tangible benefits in traditional, unconstrained- SGX on larger inputs (with virtual memory consumption of memory environments in comparison to other techniques. 700 − 800MB for the native SGX execution). Additionally, We implemented SGXBOUNDS as an extension to the AddressSanitizer consumes 3:1× more virtual memory which LLVM compiler with several optimizations for performance. can quickly exhaust available memory inside the enclave. Our compiler framework targets unmodified legacy multi- These overheads illustrate a drastic mismatch between threaded applications and thus requires no source code modifi- memory needs of current memory-safety approaches and the cations. We evaluated SGXBOUNDS using two multithreaded architectural limitations of Intel SGX (high encryption over- benchmark suites, Phoenix and PARSEC, and four real-world heads and limited enclave memory, as explained in x2.1). In applications: SQLite, Memcached, Apache, and Nginx. On particular, both AddressSanitizer and Intel MPX incur high this set of benchmarks, AddressSanitizer and Intel MPX memory overheads due to additional metadata used to track exhibit high performance overheads of 51% and 75% respec- object bounds, which in turn leads to poor performance. (We tively; memory consumption is 8:1× and 1:95× higher than detail the reasons behind the SQLite overheads in x2.3.) native SGX. In contrast, SGXBOUNDS shows an average In this paper, we present SGXBOUNDS—a memory-safety performance slowdown of 17% and an increase in memory approach for shielded execution. Our design takes into account consumption by just 0:1%. At the same time, it provides architectural features of SGX and reduces performance and similar security guarantees. Additionally, we evaluated SGX- memory overheads to the levels acceptable in production use. BOUNDS on a CPU-intensive SPEC CPU2006 suite, both For instance, in the case of SQLite, SGXBOUNDS outperforms inside and outside SGX enclaves. both AddressSanitizer and Intel MPX, with performance over- heads of no more than 35% and almost zero memory overheads 2. Background and Related Work with respect to the native SGX execution. 2.1 Shielded Execution The SGXBOUNDS approach is based on a simple combina- Our work builds on SCONE [19], a shielded execution frame- tion of tagged pointers and efficient memory layout to reduce work to run unmodified applications. SCONE utilizes Intel overheads inside SGX enclaves. In particular, we note that SGX to provide confidentiality and integrity guarantees. SGX enclaves routinely use only 32 lower bits to represent Intel SGX is a set of ISA extensions for trusted computing program address space and leave 32 higher bits of pointers un- released with recent Intel processors [33, 53]. Intel SGX pro- used.1 We utilize these high bits to represent the upper bound vides an abstraction of enclave—a memory region for which on the referent object (or more broadly the beginning of the ob- the CPU guarantees confidentiality and integrity. ject’s metadata area); the lower bound value is stored right after A distinctive trait of Intel SGX is the use of a memory the object. Such metadata layout requires only 4 additional encryption engine (MEE). Enclave pages are located in the bytes per object and does not break cache locality—unlike Enclave Page Cache (EPC)—a dedicated memory region pro- Intel MPX and AddressSanitizer. Additionally, our tagged tected by the MEE (Figure 2). While in main memory, EPC pointer approach requires no additional memory lookups for pages are encrypted.