Verifying RISC-V Physical Memory Protection

Kevin Cheang, Cameron Rasmussen, Dayeol Lee, David W. Kohlbrenner, Krste Asanovic, Sanjit A. SeshiaarXiv 2022 · DOI

Introduction

In secure computing, "enclaves" provide isolated environments to protect sensitive data from potentially compromised operating systems. In the RISC-V architecture, the Physical Memory Protection (PMP) unit serves as the primary hardware gatekeeper for this isolation. PMP allows firmware to define specific memory regions and assign access permissions (read, write, execute) across different privilege modes.

Despite the RISC-V ISA manual's clear definitions, a gap often exists between architectural specifications and actual hardware implementations (RTL code). Bugs in the PMP unit's hardware logic can undermine the security of entire frameworks, such as Keystone. This research addresses this critical gap by formally verifying the PMP implementation within the open-source RISC-V Rocket Chip.

Methodology

The researchers developed a formal verification pipeline to bridge the gap between hardware code and mathematical proofs. The process involved three main stages:

  1. Formal Specification: Natural language rules from the RISC-V ISA manual were translated into formal mathematical invariants. This included modeling address matching and the priority logic that determines which rule applies when regions overlap.
  2. Hardware Translation: The PMP implementation, originally written in Chisel for the Rocket Chip, was translated into Uclid5—a language specialized for formal verification—using the LIME tool.
  3. Verification: Utilizing the Uclid5 toolkit and the Z3 SMT solver, the team performed 1-step induction to prove that the PMPChecker module—the core combinatorial logic responsible for permission checks—consistently adheres to the formal specification.

The primary target for this verification was the PMP implementation from the Rocket Chip generator. While the original Chisel code consisted of only 48 lines, the resulting Uclid5 models expanded to 1,125 lines, reflecting the inherent complexity of the hardware logic.

Key Insights and Ideas

The verification effort yielded several critical insights into the nature of hardware security logic:

  • Modular Focus on PMPChecker: By isolating the PMPChecker module, the researchers made the complex task of hardware verification computationally tractable without sacrificing the rigor of the proof for the core logic.
  • Modeling the Whitelist: PMP operates as a "default-deny" whitelist. The authors successfully modeled how high-privilege Machine mode can bypass checks unless specific "lock" bits are engaged.
  • The Criticality of Priority Logic: RISC-V PMP rules are statically prioritized; the lowest-numbered matching entry takes precedence. This logic is a frequent source of subtle hardware bugs. Formalizing this priority was essential for ensuring the hardware correctly handles overlapping memory regions.
RISC-V PMP register structure and priority-based memory region isolation.
  • Bridging Abstraction Gaps: The study demonstrates that automated tools like LIME can effectively transform "runnable" hardware code into "provable" mathematical models, significantly reducing the manual effort typically associated with formal methods.

Results

The verification confirmed that the Rocket Chip's PMP implementation is functionally correct according to the RISC-V ISA. Notably, the formal proof was completed in just 41.33 seconds on a standard laptop (2.6 GHz Intel Core i7), demonstrating that verifying core hardware units is feasible without specialized high-performance computing resources. The significant increase in line count from hardware code to formal model underscores the hidden complexity within seemingly simple hardware modules.

Limitations and Future Work

While verifying the PMPChecker is a vital first step, it does not cover the entire system. Future research will focus on:

  • System-Level Composition: PMP interacts with the Translation Look-aside Buffer (TLB) and the Page Table Walker (PTW). Stale TLB entries could potentially bypass PMP rules, necessitating verification of these components in tandem.
  • Software-Hardware Co-verification: Security also depends on the "Security Monitor" software correctly managing PMP registers. Future work aims to verify the Keystone security monitor alongside the hardware.
  • Expanded Configurations: This initial effort used some restricted configurations; future iterations will address the full, unrestricted RISC-V PMP feature set.

Summary updated

BibTeX
@misc{cheang2022verifying,
  author = {Kevin Cheang and Cameron Rasmussen and Dayeol Lee and David W. Kohlbrenner and Krste Asanovic and Sanjit A. Seshia},
  title = {{Verifying RISC-V Physical Memory Protection}},
  year = {2022},
  eprint = {2211.02179},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2211.02179},
}
Figure