Isolation, Resource Management, and Sharing in Java
Total Page:16
File Type:pdf, Size:1020Kb
Processes in KaffeOS: Isolation, Resource Management, and Sharing in Java Godmar Back, Wilson C. Hsieh, Jay Lepreau School of Computing University of Utah Abstract many environments for executing untrusted code: for example, applets, servlets, active packets [41], database Single-language runtime systems, in the form of Java queries [15], and kernel extensions [6]. Current systems virtual machines, are widely deployed platforms for ex- (such as Java) provide memory protection through the ecuting untrusted mobile code. These runtimes pro- enforcement of type safety and secure system services vide some of the features that operating systems pro- through a number of mechanisms, including namespace vide: inter-application memory protection and basic sys- and access control. Unfortunately, malicious or buggy tem services. They do not, however, provide the ability applications can deny service to other applications. For to isolate applications from each other, or limit their re- example, a Java applet can generate excessive amounts source consumption. This paper describes KaffeOS, a of garbage and cause a Web browser to spend all of its Java runtime system that provides these features. The time collecting it. KaffeOS architecture takes many lessons from operating To support the execution of untrusted code, type-safe system design, such as the use of a user/kernel bound- language runtimes need to provide a mechanism to iso- ary, and employs garbage collection techniques, such as late and manage the resources of applications, analogous write barriers. to that provided by operating systems. Although other re- The KaffeOS architecture supports the OS abstraction source management abstractions exist [4], the classic OS of a process in a Java virtual machine. Each process exe- process abstraction is appropriate. A process is the basic cutes as if it were run in its own virtual machine, includ- unit of resource ownership and control; it provides iso- ing separate garbage collection of its own heap. The dif- lation between applications. On a traditional operating ficulty in designing KaffeOS lay in balancing the goals system, untrusted code can be forked in its own process; of isolation and resource management against the goal of CPU and memory limits can be placed on the process; allowing direct sharing of objects. Overall, KaffeOS is and the process can be killed if it is uncooperative. no more than 11% slower than the freely available JVM A number of approaches to isolating applications in on which it is based, which is an acceptable penalty for Java have been developed by others over the last few the safety that it provides. Because of its implementation years. An applet context [9] is an example of an base, KaffeOS is substantially slower than commercial application-specific approach. It provides a separate JVMs for trusted code, but it clearly outperforms those namespace and a separate set of execution permissions JVMs in the presence of denial-of-service attacks or mis- for untrusted applets. Applet contexts do not support re- behaving code. source management, and cannot defend against denial- of-service attacks. In addition, they are not general: ap- 1 Introduction plet contexts are specific to applets, and cannot be used easily in other environments. The need to support the safe execution of untrusted Several general-purpose models for isolating appli- programs in runtime systems for type-safe languages has cations in Java do exist, such as the J-Kernel [23] or become clear. Language runtimes are being used in Echidna [21]. However, these solutions superimpose an operating system kernel abstraction on Java without This research was largely supported by the Defense Advanced Re- changing the underlying virtual machine. As a result, search Projects Agency, monitored by the Air Force Research Labo- ratory, Rome Research Site, USAF, under agreements F30602–96–2– it is impossible in those systems to account for resources 0269 and F30602–99–1–0503. The U.S. Government is authorized to spent on behalf of a given application: for example, CPU reproduce and distribute reprints for Governmental purposes notwith- time spent while garbage collecting a process’s heap. standing any copyright annotation hereon. An alternative approach to separate different applica- Contact information: {gback,wilson,lepreau}@cs.utah.edu. School of Computing, 50 S. Central Campus Drive, Room 3190, University of tions is to give each one its own virtual machine, and Utah, SLC, UT 84112-9205. http://www.cs.utah.edu/flux/ run each virtual machine in a different process on an un- derlying OS [25, 29]. For instance, most operating sys- • We describe how lessons from building traditional tems can limit a process’s heap size or CPU consump- operating systems can and should be used to struc- tion. Such mechanisms could be used to directly limit an ture runtime systems for type-safe languages. entire VM’s resource consumption, but they depend on underlying operating system support. • We describe how software mechanisms in the com- Designing JVMs to support multiple processes is a su- piler and runtime can be used to implement isolation perior approach. First, it reduces per-application over- and resource management in a Java virtual machine. head. For example, applications on KaffeOS can share • classes in the same way that an OS allows applications We describe the design and implementation of Kaf- to share libraries. Second, communication between pro- feOS. KaffeOS implements our process model in cesses can be more efficient in one VM, since objects can Java, which isolates applications from each other, be shared directly. (One of the reasons for using type- provides resource management mechanisms for safe language technology in systems such as SPIN [6] them, and also lets them share resources directly. was to reduce the cost of IPC; we want to keep that goal.) • Third, embedding a JVM in another application, such as We show that the performance penalty for using a web server or web browser, is difficult (or impossible) KaffeOS is reasonable, compared to the freely avail- if the JVM relies on an operating system to isolate dif- able JVM on which it is based. Even though, due to ferent activities. Fourth, embedded or portable devices that implementation base, KaffeOS is substantially may not provide OS or hardware support for managing slower than commercial JVMs on standard bench- processes. Finally, a single JVM uses less energy than marks, it outperforms those JVMs in the presence multiple JVM’s on portable devices [19]. of uncooperative code. Our work consists of supporting processes in a modern Sections 2 and 3 describe and discuss the design and type-safe language, Java. Our solution, KaffeOS, adds a implementation of KaffeOS. Section 4 provides some process model to Java that allows a JVM to run multiple performance measurements of KaffeOS, and compares untrusted programs safely, and still supports the direct its performance with that of some commercial Java vir- sharing of resources between programs. The difficulty tual machines. Section 5 describes related work in more in designing KaffeOS lay in balancing conflicting goals: detail, and Section 6 summarizes our conclusions and re- process isolation and resource management versus direct sults. sharing of objects between processes. A KaffeOS process is a general-purpose mechanism that can easily be used in multiple application domains. 2 Design Principles For instance, KaffeOS could be used in a browser to sup- The following principles drove our design of KaffeOS, port multiple applets, within a server to support multiple in decreasing order of importance: servlets, or even to provide a standalone “Java OS” on bare hardware. We have structured our abstractions and • Process separation. We provide the “classical” APIs so that they are as broadly applicable as possible, property of a process: each process is given the il- much as the OS process abstraction is. Because the Kaf- lusion of having the whole virtual machine to itself. feOS architecture is designed to support processes, we have taken lessons from the design of traditional operat- • Safe termination of processes. Processes may ter- ing systems, such as the use of a user/kernel boundary. minate abruptly due to either an internal error or an Our design makes KaffeOS’s isolation and resource external event. In both cases, we ensure that the in- control mechanisms comprehensive. We focus on the tegrity of other processes and the system itself is not management of CPU time and memory, although we plan violated. to address other resources such as network bandwidth. The runtime system is able to account for and control • Direct sharing between processes. Processes can all of the CPU and memory resources consumed on be- directly share objects in order to communicate with half of any process. We have dealt with these issues by each other. structuring the KaffeOS virtual machine so that it sepa- rates the resources used by different processes as much • Precise memory and CPU accounting. The mem- as possible. ory and CPU time spent on almost all activities can To summarize, this paper makes the following contri- be attributed to the application on whose behalf it butions: was expended. • Full reclamation of memory. When a process is User code (untrusted) terminated, its memory must be fully reclaimed. In a language-based system, memory cannot be re- Runtime Libraries User User mode voked by unmapping pages: it must be garbage- (trusted) GC collected. We restrict a process’s heap writes to Kernel mode avoid uncollectable memory in the presence of di- rect object sharing. System Kernel code (trusted) GC • Hierarchical memory management. Memory al- location can be managed in a hierarchy, which pro- vides a simple model for controlling processes. Figure 1: Structure of KaffeOS. System code is divided into kernel and user modes; user code all runs in user mode. In user The interaction between these design principles is com- mode, code can be terminated arbitrarily; in kernel mode, code plex.