Intel(R) Software Guard Extensions Developer Reference for Linux* OS
Total Page:16
File Type:pdf, Size:1020Kb
Intel® Software Guard Extensions (Intel® SGX) SDK for Linux* OS Developer Reference Intel® Software Guard Extensions Developer Reference for Linux* OS Legal Information No license (express or implied, by estoppel or otherwise) to any intellectual prop- erty rights is granted by this document. Intel disclaims all express and implied warranties, including without limitation, the implied warranties of merchantability, fitness for a particular purpose, and non- infringement, as well as any warranty arising from course of performance, course of dealing, or usage in trade. This document contains information on products, services and/or processes in development. All information provided here is subject to change without notice. Contact your Intel representative to obtain the latest forecast, schedule, spe- cifications and roadmaps. The products and services described may contain defects or errors known as errata which may cause deviations from published specifications. Current characterized errata are available on request. Intel technologies features and benefits depend on system configuration and may require enabled hardware, software or service activation. Learn more at Intel.com, or from the OEM or retailer. Copies of documents which have an order number and are referenced in this doc- ument may be obtained by calling 1-800-548-4725 or by visiting www.in- tel.com/design/literature.htm. Intel, the Intel logo, VTune, Xeon, and Xeon Phi are trademarks of Intel Corporation in the U.S. and/or other countries. Optimization Notice Intel's compilers may or may not optimize to the same degree for non-Intel micro- processors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optim- izations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor- dependent optimizations in this product are intended for use with Intel micro- processors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice. Notice revision #20110804 * Other names and brands may be claimed as the property of others. Copyright 2014-2019 Intel Corporation. - 2 - Intel® Software Guard Extensions Developer Reference for Linux* OS This software and the related documents are Intel copyrighted materials, and your use of them is governed by the express license under which they were provided to you (License). Unless the License provides otherwise, you may not use, modify, copy, publish, distribute, disclose or transmit this software or the related documents without Intel's prior written permission. This software and the related documents are provided as is, with no express or implied warranties, other than those that are expressly stated in the License. - 3 - Intel® Software Guard Extensions Developer Reference for Linux* OS Revision History Revision Number Description Revision Date 1.5 Intel® SGX Linux 1.5 release May 2016 1.6 Intel® SGX Linux 1.6 release September 2016 1.7 Intel® SGX Linux 1.7 release December 2016 1.8 Intel® SGX Linux 1.8 release March 2017 1.9 Intel® SGX Linux 1.9 release July 2017 2.0 Intel® SGX Linux 2.0 release November 2017 2.1 Intel® SGX Linux 2.1 release December 2017 2.1.1 Intel® SGX Linux 2.1.1 release March 2018 2.1.2 Intel® SGX Linux 2.1.2 release March 2018 2.1.3 Intel® SGX Linux 2.1.3 release April 2018 2.2 Intel® SGX Linux 2.2 release July 2018 2.3 Intel® SGX Linux 2.3 release September 2018 2.4 Intel® SGX Linux 2.4 release November 2018 2.5 Intel® SGX Linux 2.5 release March 2019 2.6 Intel® SGX Linux 2.6 release June 2019 2.7 Intel® SGX Linux 2.7 release September 2019 2.7.1 Intel® SGX Linux 2.7.1 release November 2019 2.8 Intel® SGX Linux 2.8 release January 2020 - 4 - Intel® Software Guard Extensions Developer Reference for Linux* OS Introduction Intel provides the Intel® Software Guard Extensions (Intel® SGX) SDK Developer Reference for software developers who wish to harden their applic- ation security using the Intel Software Guard Extensions technology. This document covers an overview of the technology, tutorials, tools, sample code as well as an API reference. Intel® Software Guard Extensions SDK is a collection of APIs, sample source code, libraries, and tools that enable the software developer to write and debug Intel® Software Guard Extensions applications in C/C++ programming language. NOTE Intel® Software Guard Extensions (Intel® SGX) technology is only available on the 6th Generation Intel® Core(TM) Processor or newer. Intel® Software Guard Extensions Technology Overview Intel® Software Guard Extensions is an Intel technology whose objective is to enable a high-level protection of secrets. It operates by allocating hardware- protected memory where code and data reside. The protected memory area is called an enclave. Data within the enclave memory can only be accessed by the code that also resides within the enclave memory space. Enclave code can be invoked via special instructions. An enclave can be built and loaded as a shared object on Linux* OS. NOTE: The enclave file can be disassembled, so the algorithms used by the enclave developer will not remain secret. Intel® Software Guard Extensions technology has a hard limit on the protected memory size, typically 64 MB or 128 MB. As a result, the number of active enclaves (in memory) is limited. Depending on the memory footprint of each enclave, use cases suggest that 5-20 enclaves can reside in memory sim- ultaneously. Linux*, however, can increase the protected memory size through paging. Intel® Software Guard Extensions Security Properties l Intel designs the Intel® Software Guard Extensions to protect against soft- ware attacks: - 5 - Intel® Software Guard Extensions Developer Reference for Linux* OS o The enclave memory cannot be read or written from outside the enclave regardless of current privilege level and CPU mode (ring3/user-mode, ring0/kernel-mode, SMM, VMM, or another enclave). The abort page is returned in such conditions. o An enclave can be created with a debug attribute that allows a spe- cial debugger (Intel® Software Guard Extensions debugger) to view its content like a standard debugger. Production enclaves (non- debug) cannot be debugged by software or hardware debuggers. o The enclave environment cannot be entered via classic function calls, jumps, register manipulation or stack manipulation. The only way to call an enclave function is via a new instruction that per- forms several protect checks. Classic function calls initiated by enclave code to functions inside the enclave are allowed. o CPU mode can only be 32 or 64 bit when executing enclave code. Other CPU modes are not supported. An exception is raised in such conditions. l Intel designs the Intel® Software Guard Extensions to protect against known hardware attacks: o The enclave memory is encrypted using industry-standard encryp- tion algorithms with replay protection. o Tapping the memory or connecting the DRAM modules to another system will only give access to encrypted data. o The memory encryption key changes every power cycle randomly (for example, boot/sleep/hibernate). The key is stored within the CPU and it is not accessible. o Intel® Software Guard Extensions is not designed to handle side channel attacks or reverse engineering. It is up to the Intel® SGX developers to build enclaves that are protected against these types of attack. Intel® Software Guard Extensions uses strong industry-standard algorithms for signing enclaves. The signature of an enclave characterizes the content and the layout of the enclave at build time. If the enclave’s content and layout are not correct per the signature, then the enclave will fail to be initialized and, hence, will not be executed. If an enclave is initialized, it should be identical to the original enclave and will not be modified at runtime. - 6 - Intel® Software Guard Extensions Developer Reference for Linux* OS Application Design Considerations An Intel® Software Guard Extensions application design is different from non- Intel® SGX application as it requires dividing the application into two logical components: l Trusted component. The code that accesses the secret resides here. This component is also called an enclave. More than one enclave can exist in an application. l Untrusted component. The rest of the application including all its mod- ules.1 The application writer should make the trusted part as small as possible. It is suggested that enclave functionality should be limited to operate on the secret data. A large enclave statistically has more bugs and (user created) security holes than a small enclave. The enclave code can leave the protected memory region and call functions in the untrusted zone (by a special instruction). Reducing the enclave depend- ency on untrusted code will also strengthen its protection against possible attacks. Embracing the above design considerations will improve protection as the attack surface is minimized. The application designer, as the first step to harnessing Intel® Software Guard Extensions SDK in the application, must redesign or refactor the application to fit these guidelines. This is accomplished by isolating the code module(s) that access any secrets and then moving these modules to a separate pack- age/library. The details of how to create such an enclave are detailed in the tutorials section. You can also see the demonstrations on creating an enclave in the sample code that are shipped with the Intel® Software Guard Extensions SDK. Terminology and Acronyms AE Architectural enclaves. Enclaves that are part of the Intel® Soft- ware Guard Extensions framework. They include the quoting 1From an enclave standpoint, the operating system and VMM are not trusted components, either.