Keystone: A Framework for Architecting TEEs

Dayeol Lee, David Kohlbrenner, Shweta Shinde, Dawn Song, Krste AsanovicarXiv 2019

Abstract

Keystone is the first open-source framework that allows developers to build customized Trusted Execution Environments (TEEs) tailored to specific hardware and security needs. By leveraging RISC-V hardware primitives and a modular software architecture, it breaks the "one-size-fits-all" model of vendor-locked TEEs like Intel SGX or ARM TrustZone.

Introduction

Trusted Execution Environments (TEEs), often called "enclaves," are secure areas of a processor that protect sensitive data even if the operating system is compromised. However, current TEEs are vendor-specific "black boxes." If you use Intel SGX, you are stuck with Intel’s design choices—such as static memory limits or a specific threat model—regardless of whether they fit your application.

This lack of flexibility leads to two major issues:

  1. Bloated Trusted Computing Base (TCB): To work around hardware limitations, developers often add massive software layers inside the enclave, increasing the attack surface.
  2. Rigid Trade-offs: A cloud server and a tiny IoT sensor have very different power and security requirements, yet current TEEs offer little room to tune these parameters.

The Keystone Architecture

Keystone takes a "Software Defined Infrastructure" approach to TEEs. It utilizes three key layers to provide isolation and security:

  • Hardware Primitives: It uses standard RISC-V Physical Memory Protection (PMP) to isolate memory regions. No custom, proprietary hardware is required.
  • Security Monitor (SM): A tiny, highly privileged layer running in RISC-V "Machine Mode." Its only job is to enforce the boundaries between the untrusted OS and the enclaves.
  • Enclave Runtime (RT): This is the "secret sauce." Unlike other TEEs, Keystone moves the management logic (like memory allocation and system call proxying) into a "Runtime" that lives inside the enclave in "Supervisor Mode."
Keystone system architecture showing the separation of privilege levels and enclave components.

This modularity allows developers to use plugins to add features only when needed. For example, a "Cache Partitioning" module can be plugged in to defend against side-channel attacks, or a "Dynamic Resizing" module can allow enclaves to grow their memory footprint on the fly.

Comparative Analysis and Key Insights

The core philosophy of Keystone is that hardware should provide simple security primitives, not point-wise solutions. Software should then orchestrate these primitives into a TEE. By separating the Security Monitor (which enforces isolation) from the Runtime (which manages the enclave), the authors reduced the most critical part of the code—the Security Monitor—to just 1.6 KLoC (thousand lines of code).

Comparison of Keystone with existing TEE architectures across security and performance metrics.

Keystone allows for customizable threat models, enabling users to "pay only for what they use." If a threat model doesn't include physical attackers, expensive memory encryption plugins can be disabled to gain performance. Furthermore, in-enclave page management prevents the untrusted OS from seeing memory access patterns, naturally mitigating a large class of "controlled-channel" side-channel attacks.

Evaluation and Results

The authors evaluated Keystone using standard benchmark suites (RV8, Beebs, CoreMark) and real-world applications like private machine learning inference (Torch, FANN) and cryptography (libsodium).

  • Minimal Overhead: For pure computation, Keystone has near-zero (<1%) overhead compared to running natively on Linux.
  • TCB Reduction: A typical Keystone enclave has a TCB of about 12-15 KLoC. In contrast, systems porting legacy apps to SGX often reach TCBs in the millions of lines of code.
  • Machine Learning Performance: Running complex models like ResNet via the Torch plugin resulted in an execution overhead of only ~3% to 7%.
  • I/O Costs: The main bottleneck is I/O. Because every system call must be proxied through the "edge call" interface to the untrusted OS, high-I/O tasks saw performance hits of around 40%.

Limitations and Future Work

While Keystone offers significant flexibility, it has limitations. The current version does not natively protect against "Spectre-style" speculative execution attacks on out-of-order processors. Additionally, while it supports multi-threading within a single core, it does not yet support parallel execution of a single enclave across multiple physical cores. Finally, while the TCB is small enough for formal verification, the authors leave full formal verification of the Security Monitor for future work.

Summary updated

BibTeX
@misc{lee2019keystone,
  author = {Dayeol Lee and David Kohlbrenner and Shweta Shinde and Dawn Song and Krste Asanovic},
  title = {{Keystone: A Framework for Architecting TEEs}},
  year = {2019},
  eprint = {1907.10119},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1907.10119},
}
Figure