A Principled Approach to Kernel Memory Management
Total Page:16
File Type:pdf, Size:1020Kb
A Principled Approach To Kernel Memory Management A thesis submitted to the School of Computer Science and Engineering at the University of New South Wales in fulfilment of the requirements for the degree of Doctor of Philosophy. Dhammika Elkaduwe 2010 !! " #$ % & '!( )' ( ! * + "()%',(-. /0012 /!! ! ! "# $$%' -. /0032 4!! 2 ! !& '( ) ) "* " , /0032 5!! 2 ' #𐠁 &9'-./0082 :!! "! & ) '( ( "* () ) )/0082 ;!! 2 1 $! ) '( *+ < . ( )/00;2 Abstract Small kernels are a promising approach to secure and reliable system construction. These systems reduce the size of the kernel to a point where it is feasible to formally verify the implementation correctness of the kernel with respect to an abstract formal model of the kernel’s behaviour. The system is composed of user-level components, isolated from one another using the kernel-provided mechanisms. The abstract formal model facilitates the enforcement, and reasoning about the enforcement of different policies between these user-level components. However, existing formal models only capture the application-level interface of a small kernel with no clear relationship between the externally visible access control model and the kernel’s low-level management of physical memory. In this work, a model for managing the in-kernel memory of a formally verified, small kernel is designed and evaluated for its formal and empirical characteristics. The design eliminates all implicit memory allocations within the kernel by promoting all dynamically allocated kernel memory into first-class, explicitly allocated kernel objects. This reduces the problem of physical memory management within the kernel to that of controlling the authority to perform these explicit allocations and controlling the dissemination of author- ity over already allocated objects. A formal protection model that unifies in-kernel management of physical memory with access control is developed by extending the take-grant model. A formal analysis carried out on the above developed model demonstrates that the model is capable of enforcing spatial partitioning and isolation. The extension preserves the decidability of the original take-grant model while providing the ability to reason about kernel memory consumption of components which is not feasible in the original model. Performance of the model is evaluated using a prototype implementation based on an L4 microkernel. The analysis shows no significant performance degradation due to export- ing all in-kernel memory allocations to user-level. When enforcing spatial partitioning to a para-virtualised Linux kernel the model shows performance improvements compared to a L4 based system enforcing a similar policy by run-time monitoring and shows similar performance to a L4 system that attempts no control over memory consumption and a Xen based system. This work demonstrates the feasibility of exporting all in-kernel memory allocations to user-level resource managers through a capability-based, decidable, protection model. The model shows no performance degradation in the scenarios examined and can be used to make strong formal guarantees on memory consumption of components. Acknowledgement This thesis would not have been possible without the help and the encouragement of many. In particular, lot of the credit for successfully completing this thesis should go to my supervisor Kevin Elphinstone. His persistent support, guidance and advice made this work a reality. I am grateful to my co-supervisor Gernot Heiser for his advice and feedback on the project when I needed them. In addition to my supervisors, a number of others at ERTOS enriched the project with their knowledge and skills. The support and the guidance given by Gerwin Klein was in- strumental for the formal modelling and analysis of the kernel’s protection model. I would like to thank Carl Van Schaik, Peter Chubb and Ben Leslie for enriching the seL4 and seL4::Wombat implementations with their vast knowhow on low-level system program- ming. In addition to these direct involvements I want to thank all my colleagues at ERTOS for their input and the team spirit which made a difficult journey enjoyable. Even with the help and support of all the above mentioned, this work would not have been possible without the support and the understanding of my better-half Risheeka. I greatly appreciate her understanding and support during a stressful period. Last but not least my deepest gratitude goes to my parents, without whom none of this would have been possible. Contents 1 Introduction 1 1.1 Microkernel-Based Systems ........................ 2 1.2 A Formally Verified Microkernel ...................... 3 1.3 Managing Kernel Memory ......................... 4 1.4 Protection Models .............................. 5 1.5 Aim and Scope of Research ......................... 5 1.6 Contributions ................................ 7 1.7 Overview of this thesis ........................... 8 2 Related Work 9 2.1 Kernel Memory Management ........................ 9 2.1.1 In-Kernel Policy .......................... 10 2.1.2 Kernel Memory as a Cache ..................... 13 2.1.3 User-Level Management ...................... 14 2.1.4 Summary .............................. 15 2.2 Formal Modelling .............................. 17 2.2.1 Background ............................. 18 2.2.2 Classical Access-Control Models ................. 19 2.2.3 Summary .............................. 22 3 Managing Kernel Memory 23 3.1 L4.verified – Formal Verification ...................... 23 3.1.1 Overview of the Methodology ................... 23 3.1.2 Proof Effort: Case Study ...................... 24 3.2 Summary of Existing Approaches ..................... 27 3.2.1 Reasoning About Memory ..................... 28 3.3 seL4 Approach: Rationale ......................... 28 4 Conceptual Model 30 4.1 Overview of seL4 .............................. 31 4.1.1 Basic Kernel Model ........................ 31 4.1.2 System Structure .......................... 31 4.1.3 seL4 Memory Management .................... 32 4.1.4 Kernel Objects ........................... 33 4.2 Overview of Memory Management API .................. 34 4.3 Kernel Object Allocation .......................... 34 4.3.1 Type and Memory Safety of Kernel Objects ............ 36 4.3.2 Preventing User-Level Access to Kernel Data ........... 36 4.3.3 The Capability Derivation Tree ................... 36 i 4.3.4 Summary of the Retype Operation ................. 39 4.4 Recycling Memory ............................. 39 4.5 Reusing Memory .............................. 40 4.6 Managing Address Spaces ......................... 41 4.6.1 Exception Model .......................... 42 4.6.2 Capability Address Space ..................... 43 4.6.3 Virtual Memory Address Space .................. 46 4.7 Implementation Details ........................... 50 4.7.1 Untyped Memory Abstraction ................... 50 4.8 Summary .................................. 52 5 Formal Model of Authority 53 5.1 The Take-Grant Model ........................... 54 5.1.1 The seL4 protection model — Informal Introduction ....... 56 5.2 Isabelle/HOL system ............................ 57 5.3 The seL4 Protection model ......................... 58 5.3.1 Semantic Entities .......................... 58 5.3.2 Protection State ........................... 59 5.3.3 Operational Semantics ....................... 60 5.3.4 The Initial System State ...................... 64 5.3.5 Fundamental Invariant of the Model ................ 65 5.4 Informal Correspondence to seL4 ..................... 65 5.4.1 Concrete and Abstract Protection States .............. 66 5.4.2 Concrete and Abstract Operations ................. 68 5.5 Summary .................................. 70 6 Formal Analysis of the Protection Model 71 6.1 Informal Discussion of Requirements ................... 71 6.1.1 Capability Based Protection .................... 72 6.2 Predicates .................................. 73 6.3 Necessary Conditions for Propagation of Authority ............ 75 6.4 Enforcing Subsystems ........................... 82 6.4.1 Example System .......................... 86 6.4.2 Relation to Concrete System .................... 89 6.4.3 Reducing Resource Manager’s Complexity ............ 89 6.5 Information Access Control ......................... 90 6.5.1 Isolated Components ........................ 90 6.5.2 Proof of Isolation .......................... 92 6.5.3 Enforcing Isolation ......................... 95 6.6 Summary .................................. 96 7 seL4::Pistachio 97 7.1 Cost of Managing Kernel Objects ..................... 98 7.1.1 Cost of Allocating Kernel Objects ................. 98 7.1.2 Prototype Allocator ......................... 102 7.1.3 Memory Overhead of Untyped Capabilities ............ 102 7.1.4 Cost of Revoking Memory ..................... 103 7.1.5 Cost of Recycling Kernel Objects ................. 105 7.1.6 Different Management Policies .................. 106 ii 7.1.7 Limitations ............................. 106 7.2 Cost of Capabilities ............................. 107 7.2.1 Layout of a CSpace ......................... 107 7.2.2 Capability Lookup Cost ...................... 108 7.2.3 Managing a CSpace ........................ 111 7.3 Performance of Kernel Primitives ..................... 113 7.3.1 IPC operation ............................ 114 7.3.2 Thread Operations ........................