Wang, the Pennsylvania State University; Xi Xiong, Facebook Inc
Total Page:16
File Type:pdf, Size:1020Kb
Between Mutual Trust and Mutual Distrust: Practical Fine-grained Privilege Separation in Multithreaded Applications Jun Wang, The Pennsylvania State University; Xi Xiong, Facebook Inc. and The Pennsylvania State University; Peng Liu, The Pennsylvania State University https://www.usenix.org/conference/atc15/technical-session/presentation/wang_jun This paper is included in the Proceedings of the 2015 USENIX Annual Technical Conference (USENIC ATC ’15). July 8–10, 2015 • Santa Clara, CA, USA ISBN 978-1-931971-225 Open access to the Proceedings of the 2015 USENIX Annual Technical Conference (USENIX ATC ’15) is sponsored by USENIX. Between Mutual Trust and Mutual Distrust: Practical Fine-grained Privilege Separation in Multithreaded Applications Jun Wang, Xi Xiong†1, Peng Liu Pennsylvania State University, Facebook Inc.† Abstract exploit certain vulnerabilities (e.g., format string CVE- Threads in a multithreaded process share the same ad- 2004-1097) to inject shellcode and thus access the private dress space and thus are implicitly assumed to be mutu- data of another connection served by a different thread. ally trusted. However, one (compromised) thread attack- Meanwhile, logic bugs (e.g., Heartbleed [8]) might ex- ing another is a real world threat. It remains challenging ist so that an attacker can fool a thread to steal private to achieve privilege separation for multithreaded applica- data belonging to other threads. (3) For the multithreaded tions so that the compromise or malfunction of one thread userspace file system FUSE [6], logic flaws or vulner- does not lead to data contamination or data leakage of abilities might also allow one user to read a buffer that other threads. contains private data of another user, which violates the The Arbiter system proposed in this paper explores access control policy. This is especially critical for en- the solution space. In particular, we find that page table crypted file systems built upon FUSE (e.g., EncFS [5]), protection bits can be leveraged to do efficient reference wherein data can be stored as cleartext in memory and a monitoring if data objects with the same accessibility stay malicious user could enjoy a much easier and more ele- in the same page. We design and implement Arbiter gant way to crack encrypted files than brute force. which consists of a new memory allocation mechanism, a A common characteristic of the above applications is policy manager, and a set of APIs. Programmers specify that they may concurrently serve different users or clients, security policy through annotating the source code. We which represent distinct principals that usually do not apply Arbiter to three applications, an in-memory key/- fully trust each other. This characteristic directly con- value store, a web server, and a userspace file system, tradicts the “threads-are-mutually-trusted” assumption. and show how they can benefit from Arbiter in terms of Therefore, a fundamental multithreaded application secu- security. Our experiments on the three applications show rity problem arises, that is, how to retrofit the classic mul- that Arbiter reduces application throughput by less than tithreaded programming model so that the “threads-are- 10% and increases CPU utilization by 1.37-1.55 . mutually-trusted” assumption can be properly relaxed? × In other words, could different principal threads have dif- 1 Introduction ferent privileges to access shared data objects so that the While multithreaded programming brings clear advan- compromise or malfunction of one thread does not lead tages over multiprocessed programming, the classic mul- to data contamination or data leakage of another thread? tithreaded programming model has an inherent security limitation, that is, it implicitly assumes that all the threads 1.1 Prior Work and Our Motivation From a programmer’s point of view, we identify two inside a process are mutually trusted. This is reflected by kinds of privilege separation problems. The first prob- the fact that all the threads run in the same address space lem is to split a monolithic application into least-privilege and thus share the same privilege to access resources, es- compartments. For example, an SSH server only requires pecially data. root privilege for its monitor (listening to a port and per- However, one thread attacking another thread of the forming authentication), rather than the slave (process- same application process is a real world threat. Here are ing user commands). Since the two parts are usually a few examples: (1) For the multithreaded in-memory closely coupled, developers in the old days simply put key/value store Memcached [9], it has been shown that the two into one program. Due to the emergence of buffer many large public websites had left it open to arbitrary overflow and other relevant attacks against the root privi- access from Internet [2], making it possible to connect to leged part, however, this monolithic program design is no (a worker thread of) such a server, dump and overwrite longer appropriate. Separation of the two parts into dif- cache data belonging to other threads [7]. In addition, ferent privileged processes with IPC mechanisms in be- vulnerabilities [11, 10] could be exploited by an adver- tween (e.g., via pipes) becomes a more appropriate ap- sary (e.g., buffer overflow attack via CVE-2009-2415) so proach. Actually, OpenSSH has already adopted this ap- that the compromised worker thread can arbitrarily ac- proach. cess data privately owned by other threads. (2) For the The second problem is to do fine-grained privilege sep- multithreaded web server Cherokee [3], an attacker could aration in multithreaded applications. As introduced ear- 1work was done while this author was at Pennsylvania State Univer- lier, threads in a multithreaded program were implicitly sity. assumed to be mutually trusted. However, the evolving USENIX Association 2015 USENIX Annual Technical Conference 361 1st PS Problem (OpenSSH [27], 2nd PS Problem (Arbiter) of multithreaded applications tends to break this assump- Privtrans [15], Wedge [14], etc.) tion by concurrently serving different principals. Usually Sequential invocation of compartments Concurrent execution the principals do not fully trust one another. with different privileges Only privileged process/thread can Data shared among different The first problem has been studied for many years access sensitive data (unprivileged) principal threads [29, 27, 19, 15, 14]. Provos et al. [27] pioneered the Static capability policy Dynamic (label) policy methodology and design of privilege separation. Priv- Table 1: Different assumptions of 1st and 2nd privilege separa- trans [15] can automatically partition a program into a tion (PS) problem privileged monitor and an unprivileged slave. Wedge [14] reveals that over 80% of existing web servers are multi- combines privilege separation with capabilities to do threaded. It is impractical to redesign all those applica- finer-grained partitioning. For the second one, however, tions that are already multithreaded. there are no systematic research investigations that we are 2) Software fault isolation. Address space isolation aware of. puts each process into a protection domain, but does not This paper focuses on the second privilege separation do finer-grained isolation inside an address space. Soft- problem. Our goal is to apply least privilege principle on ware fault isolation [30, 17] did an innovative work on (shared) data objects so that a data object can be read- making a segment of address space as a protection do- writable, read-only, or inaccessible to different threads at main by using software approaches like a compiler. Nev- the same time and, more importantly, to require minimum ertheless, it is difficult for SFI to map program data ob- retrofitting effort from programmers. First of all, let’s jects (e.g., array) into a protection domain: address-based look at existing mechanisms to see whether they can be confinement and static instrumentation cannot easily deal applied to solve this problem. with dynamically allocated data. LXFI [24] instruments 1) Process isolation. Process isolation is the essen- kmalloc so that the principal and address information of tial idea behind existing approaches to the first privilege dynamic kernel data objects are made aware to the ref- separation problem. OpenSSH [27] and Privtrans [15] erence monitor. However, this is done only to kernel leverage process address space isolation while using IPC modules and kernel data. In addition, LXFI focuses on to make the privileged part and the unprivileged part integrity and does not check memory reads due to per- work together. However, neither of them handles data formance reasons. However, our goal is to prevent both object granularity. In addition, when there are many unauthorized reads and writes. Therefore, we need to principal threads, IPC might become very inefficient. catch invalid reads as well. Wedge [14] advances process isolation with new ideas. 3) Other related mechanisms. We investigate four It creates compartments with default-deny semantics and additional types of related mechanisms to see whether maps shared data objects into appropriate compartments. they can handle our problem. (a) OS abstraction level ac- However, Wedge is proposed to address the first privilege cess control has been extensively studied (e.g., SELinux separation problem, which has very different nature from [23], AppArmor [1], Capsicum [31]). However, these the problem we consider, as shown in Table 1. Due to mechanisms treat a process/thread as an atomic unit and these differences, Wedge’s all-or-nothing privilege model do not deal with data objects “inside” a process. So a with default-deny semantic is not very applicable to a granularity gap exists between these techniques and our multithreaded program, wherein threads by default share goal. (b) HiStar [33] is a from-scratch OS design of lots of resources. To apply Wedge on our problem, one decentralized information flow control (DIFC). Perhaps still needs to address the challenges considered in this pa- HiStar can meet our goal of privilege separation on data per.