betaFeedback

WorksComputer Science

TechReport: Implementing CHERI in gem5

Abstract

Despite countless mitigation efforts, memory safety issues still prevail. The recently discovered security issues in PHP underline this fact. One of the most promising approaches to solving this problem is the concept of Capability Hardware Enhanced RISC Instructions (CHERI). There is a well-developed ecosystem of ISA simulators, compilers, operating systems, and hardware designs that support CHERI. However, the lack of a simulator modeling microarchitectural detail hinders efficient and fast design space exploration for CHERI-enhanced designs means the performance impact of CHERI remains understudied. Therefore, we present gem5-CHERI: a CHERI-enhanced adaptation of the gem5 simulator that can boot the CheriBSD operating system and run custom workloads. The simulator is available open-source on GitHub.

Introduction

Memory safety is one of the oldest concerns in computer security [1]. Still, issues like out-of-bounds reads and writes continue to rank high in the top 10 of the MITRE CWE most dangerous software weaknesses in 2025 [2]. Widely used programming languages like C/C++ are not memory-safe as they allow for manual pointer modification and dereferencing which can cause memory leaks or corruption.

This enables attackers to alter the control flow or behavior of the program, for example with the help of buffer overflows and code injection [3]. Defenses like Address Space Layout Randomization or data execution prevention impede memory corruption exploits but do not combat the underlying issue [4]. In addition, these defenses can be circumvented by other attack mechanisms, such as return-oriented programming [5]. New vulnerabilities related to memory safety continue to emerge.

In October 2026, the security issues in PHP related to CVE-2026-109618 and CVE-2026-109619 globally caused service disruptions [6]. Both are related to the known weaknesses Improperly Controlled Sequential Memory Allocation, Use After Free, Improper Handling of Exceptional Conditions, and Access of Uninitialized Pointer. This highlights the need for holistic memory safety approaches, especially since rapidly increasing AI capabilities make it easier to detect and exploit such vulnerabilities.

One approach to tackle this issue is to use modern type and memory-safe languages like Rust [7]. However, it is not possible to replace all C/C++ legacy code in the near future with Rust. For some code, such as certain low-level embedded software, a replacement can be technically infeasible [8].

A possible solution to this problem is to enforce memory safety directly in the hardware. In recent years, the concept of Capability Hardware Enhanced RISC Instructions (CHERI) [9] is gaining traction as one of the most promising and holistic approaches to architectural memory safety. CHERI’s main concept are so called Capabilities that extend ordinary pointers by appending meta data encoding the bounds and permissions plus an additional tag bit, at the cost of effectively doubling the original size. CHERI extends customary Instruction Set Architectures (ISAs) such as ARM and RISC-V with additional instructions to handle and manipulate these capabilities.

Scope of This Work

The main aspects of this work are summarized as follows:

  • We extend the gem5 computer architecture simulator to support the CHERI-RISC-V v9 ISA. The extension comprises capability registers, CHERI support in the decoder, a tag-aware memory subsystem, and the enforcement of the CHERI bounds and permission checks. The simulator is available open-source1.

  • Our simulator can boot the CheriBSD operating system in full system mode and run custom user-defined workloads. This enables fast DSE for CHERI workloads. Additionally, CHERI-specific microarchitectural components can be prototyped and profiled.

gem5-CHERI

Our goal is to enable the full system microarchitectural evaluation of CHERI-RISC-V single-core designs. We need a platform that is both capable of booting an operating system such as CheriBSD [10] and running user workloads. Additionally, it must model microarchitectural detail and be easily configurable for design space exploration.

We build gem5-CHERI on the baseline of the well-established gem5 computer architecture simulator [11], [12]. The open-source community-supported project provides a Python-based scripting interface that makes the simulator dynamically configurable. It provides well-tested standard components including out-of-order and in-order processor cores, caches, a DRAM model, I/O devices and more. The components are designed as parameterized models, which makes it easy to explore different system configurations, e.g., evaluate the performance impact of different cache sizes. More information on the gem5 simulator can be found in [11], [12]. We base gem5-CHERI on the latest CHERI-RISC-V ISA v9 [13].

Integrating CHERI into a CPU design involves considerable microarchitectural adaptations to support the capability-based features. These changes affect almost every part of a standard RISC-V implementation and change an instruction’s latency along its way through the pipeline. It is important for designers to be able to evaluate the impact of specific design decisions on the system performance quickly and easily.

The main goals of our implementation are as follows:

  • Full-system capability: The simulator can boot a CheriBSD kernel and can run userspace workloads in pure-capability, hybrid and plain RV64 modes. This ensures comparability between the different modes and enables realistic benchmarking and workload profiling.

  • Re-use of existing gem5 infrastructure: The added CHERI support is integrated into gem5’s existing CPU models, components and simulation infrastructure. This simplifies architectural modifications, design-space exploration, and trustworthy performance metrics.

Figure 1(a) shows an overview of our gem5-CHERI implementation. The implemented features can be divided into three main categories. The blue blocks denote new CHERI components that are implemented from scratch. The dashed yellow blocks are components that already exist in gem5 but needed to be modified for supporting the CHERI specifications. Lastly, the grey blocks are components that remain unmodified. We implement CHERI as a separate ISA, derived from the RISC-V RV64GC ISA implementation of gem5 [14].

Figure 1. Overview of gem5-CHERI, (b) CHERI checks and faults in each stage of the instruction flow clc cd, imm(cs1), and (c) Inside E. CheriTaggedMemory with a two-level tag table

The first modified component is the single CHERI-RISC-V hart (A) that implements the CHERI ISA v9. First, we created a 129 bit capability register container that is used for the register file and the 14 capability-extended control and status registers (CSRs). We implemented a merged register file, i.e., the integer register xnx_n is the address field of the 129 bit capability register cnc_n. All integer instructions modifying xnx_n overwrite bits 128 to 64 of cnc_n with zeros. One important modification is the program counter capability (PCC). Besides checking the allowed bounds during the instruction fetch stage, the PCC also encodes the current execution mode, i.e., capability or integer. Depending on this mode some instructions are allowed to be executed or decoded differently, e.g., AUIPC becomes AUIPCC. The decode unit is extended to reflect this behavior and to support the compressed and uncompressed CHERI-specific instructions for capability management and accesses required to run custom workloads under CheriBSD.

The memory management unit (MMU) translates the virtual addresses used by software into physical addresses and enforces the CheriBSD operating system’s page permissions. In gem5-CHERI, we extend the paging control to capabilities as specified in the ISAv9. The reserved bits of the page table entry (PTE) format Sv39 are utilized to let the OS control loads and stores of capabilities.

The core part of the CHERI ISA are the formally verified memory safety guarantees [15, 16] that are enforced by permission and bounds checks. In gem5-CHERI, we implement each check as an independent function performing the architectural checks on memory accesses, jumps, and instruction fetch. We perform these checks in the priority order given in the Sail CHERI-RISC-V reference model [17], i.e., a capability must be tagged, unsealed, carry the required permission, and the access must be within the encoded bounds. A failed check raises a CHERI exception that records which register and which check failed. Additionally, monotonicity is ensured by clearing the tag whenever a derived capability would exceed the original capability’s rights.

Figure 1(b) shows where these checks happen at the example of the capability load clc cd, imm(cs1). The decoder checks that the PCC allows the instruction to be fetched. The execute stage computes the effective address from cs1cs1 and checks the tag, seal, permissions and bounds (i.e. cap check) of cs1cs1. If a check fails, no request is sent to memory. During address translation, the MMU checks the capability permissions in the PTE. If the page is not permitted to hold capabilities, the load completes but the tag of the loaded value is cleared. If the page’s capability generation is stale, the MMU raises a capability page fault, which CheriBSD uses as its revocation load barrier. A faulting instruction carries its fault to the commit stage, meaning a squashed wrong-path instruction never traps. A CHERI exception then enters the CheriBSD trap handler, which sends a SIGPROT signal to the process that caused the fault.

Our gem5-CHERI simulator supports all standard gem5 CPU models. All models are modified to replace the standard integer register file with the capability register class and the dependencies are tracked through the standard scoreboard and renaming stage. In the o3 CPU model, we modified store-to-load forwarding to make it capability- and tag-aware and implemented a new type of memory request for the cloadtags instruction.

The cache subsystem (B in Figure 1(a)) and I/O devices (C) are mostly left unmodified with the exception of direct memory access (DMA) components. Every DMA write must clear the corresponding tags for memory regions it overwrites for enforcing safety. This ensures that a device does not turn an arbitrary write into a valid capability.

One major challenge in adopting the CHERI ISA is the management of the additional tag bit since standard addressing and accesses do not support 129 bit granules. Therefore, we split the implementation into two parts: the functional tag table (FTT) (D) and the CheriTaggedMemory (E).

The FTT is a software construct which holds the only functional copy of every tag value. CHERI enforces a tag bit for every 16 byte physical address chunk. The FTT is a hash map keyed by a chunk’s address and only stores tagged chunks. Non-hashed values have the tag 0. All instructions access the FTT during the write-back stage, ensuring functional correctness. Lastly, as the FTT is a purely functional implementation, accessing it takes zero simulated cycles. This choice vastly simplifies the implementation effort as it allows us to keep the caches unmodified. However, we still want to faithfully model the tag-related timing.

Therefore, we introduce CheriTaggedMemory. We base our implementation on the “Efficient tagged memory” from [18] by adding a small tag cache and with its own controller. The controller manages a two-level tag table (see Figure 1(c)) that is located in a reserved region at the top of physical memory.

The lower level is the leaf tag memory. One leaf bit holds the tag of one 16 B granule, i.e., one capability. Thus, one 64 B leaf tag line covers the tags for 8 KiB of data. In total, the leaf memory occupies around 0.78 % of the protected DRAM memory, e.g., for 8 GiB of DRAM 64 MiB of leaf memory are required.

The root tag memory can help accelerate tag reads for memory regions. A root bit is set if any tag in its leaf line is set, so a 64 B root line covers 512 leaf lines, or 4 MiB of data.

Overall, both the tables round up to a 0.85 % reservation of memory that the device tree hides from the CheriBSD kernel. In our implementation, the controller performs DRAM requests to model the traffic and timing but the results are never propagated. Instead, the values are taken from the FTT.

We implement a parametrized cache inside the controller to hold recently used table lines. It can be disabled, configured in flat mode, i.e., only use leaf tag memory, or, by default, configured as a hierarchical 32 KiB 8-way leaf cache and a 1 KiB 4-way root cache. In hierarchical mode, both caches are independent and each reads its own table. The root level only decides whether a leaf line has to be read. If the root bit is 0, the leaf line is all zeros and the read is skipped.

Hits in the L1 and L2 caches access tags in zero simulated time, faithfully modeling real hardware timing for CHERI-adapted caches. Therefore, only requests that do not get served by the L2 cache reach the CheriTaggedMemory controller that issues a tag request to model memory traffic. Note that all requests to DRAM, independently of integer or capability access, create tag traffic since every 16 B chunk of data comes with a corresponding tag bit.

On a leaf cache hit the tags are ready at no extra cost, since the lookup is shadowed by the DRAM data access. On a leaf cache miss, a tag-table read is issued two controller cycles after the lookup. Reads that go to the same line are merged by the controller.

In hierarchical mode, a root miss is served first, i.e., the root line is read from DRAM, and only when it returns as set, the controller checks the leaf bit. A data reply that arrives before its tags is held in the controller until they arrive. This hold is the only latency tags add directly to a load, although tag traffic can also delay other requests through DRAM contention.

Stores write their tags to the FTT in the writeback stage and issue a DRAM write request for the tag when the tag cache line is evicted.

Figure 2 shows an example execution trace. The capability load I1 misses in the L1 and L2 and reaches the memory controller. Its data line is read from DRAM while the controller, having missed in both tag caches, reads the root line. Both DRAM requests return shortly after each other. The controller then reads the leaf line, and the data reply is held until that read returns one full DRAM access later. I2 and I3 depend on I1 and stall. I2 is a CHERI arithmetic instruction and does not involve a memory access. The capability store I3 hits in the L1 and sets its tag in the functional table without involving the controller.

Figure 2. Example execution trace for a CHERI instruction sequence.

Validation

After implementation we validated that our implementation behaves according to the functional specification. We run two functional test suites both on our gem5-CHERI simulator and on CHERI-QEMU [19] and compare the result of every test. The first validation is based on CheriBSD’s own regression test suite cheribsdtest. The tests check basic ISA-level behavior, e.g., capability bounds and permissions, sealing and sentries, capability loads and stores and their tags. Many tests deliberately cause a capability fault and make sure that the kernel delivers the expected SIGPROT signal with the expected cause.

We run the default statically linked build of the test suite on QEMU, the AtomicCPU, the MinorCPU and the out-of-order (o3) CPU model and achieve matching results. All 313 tests yield the expected pass or fail result.

Second, we run the more comprehensive security benchmark suite Juliet 1.3 [20] from the US National Institute of Standards and Technology (NIST). Each test targets one class from the Common Weakness Enumeration (CWE) list, such as Stack Overflow or Buffer Under-read. We, again, achieve the same results as CHERI-QEMU for the 25,180 test cases from the Juliet test suite.

Together, both experiments validate our implementation of the CHERI memory safety features.

Conclusion

With gem5-CHERI, we present the first CHERI-aware microarchitectural simulator, allowing for fast and efficient design space exploration. We extend gem5 with the CHERI-RISC-V ISAv9, including the functional and faulting behavior of all instructions as well as the tag management in memory. We decouple the tag functionality from the timing model in order to be able to investigate the introduced overheads individually. In future work, gem5-CHERI could be extended to support multi-cores, i.e., modeling cache coherence for tags.

Acknowledgement

The reported research was supported by Agentur für Innovation in Cybersicherheit GmbH under grant PROTECT (EVIT program).

References

  1. [1]L. Szekeres, M. Payer, T. Wei, and D. Song, “SoK: Eternal war in memory,” in 2013 IEEE Symposium on Security and Privacy, 2013, pp. 48–62.DOI
  2. [2]MITRE, “2025 CWE Top 25 Most Dangerous Software Weaknesses,” accessed: 2026-10-20. [Online]. Available: https://cwe.mitre.org/top25/archive/2025/2025_cwe_top25.html
  3. [3]C. Cowan, F. Wagle, C. Pu, S. Beattie, and J. Walpole, “Buffer overflows: Attacks and defenses for the vulnerability of the decade,” in Proceedings DARPA Information Survivability Conference and Exposition. DISCEX’00, vol. 2. IEEE, 2000, pp. 119–129.
  4. [4]“PaX ASLR.” [Online]. Available: https://pax.grsecurity.net/
  5. [5]R. Roemer, E. Buchanan, H. Shacham, and S. Savage, “Return-oriented programming: Systems, languages, and applications,” ACM Transactions on Information and System Security (TISSEC), vol. 15, no. 1, pp. 1–34, 2012.
  6. [6]L. Chutel, A. Nierenberg, and B. O. Otieno, “From Kenya to Japan, Rush to Fix Security Flaw Takes Sites Briefly Offline,” accessed: 2026-10-26. [Online]. Available: https://www.nytimes.com/2026/10/22/world/php-vulnerability-websites-cybersecurity-ai.html
  7. [7]N. D. Matsakis and F. S. Klock, “The Rust language,” in Proceedings of the 2014 ACM SIGAda Annual Conference on High Integrity Language Technology, ser. HIIT ’14. New York, NY, USA: Association for Computing Machinery, 2014, p. 103–104.
  8. [8]A. Sharma, S. Sharma, S. R. Taksalkar, S. Torres-Arias, and A. Machiry, “Rust for embedded systems: Current state and open problems,” in Proceedings of the 2024 acm ACM SIGSAC Conference on Computer and Communications Security, ser. CCS ’24. New York, NY, USA: Association for Computing Machinery, 2024, p. 2296–2310.DOI
  9. [9]J. Woodruff, R. N. Watson, D. Chisnall, S. W. Moore, J. Anderson, B. Davis, B. Laurie, P. G. Neumann, R. Norton, and M. Roe, “The cheri capability model: Revisiting risc in an age of risk,” ACM SIGARCH Computer Architecture News, vol. 42, no. 3, pp. 457–468, 2014.
  10. [10]“CheriBSD.” [Online]. Available: https://github.com/CTSRD-CHERI/cheribsd
  11. [11]N. L. Binkert, B. M. Beckmann, G. Black, S. K. Reinhardt, A. G. Saidi, A. Basu, J. Hestness, D. Hower, T. Krishna, S. Sardarthi, R. Sen, K. Sewell, M. S. Balat, N. Vaish, M. D. Hill, and D. A. Wood, “The gem5 Simulator,” SIGARCH Comput. Archit. News, vol. 39, no. 2, pp. 1–7, 2011.DOI
  12. [12]J. Lowe-Power, A. M. Ahmad, A. Akram, M. Alian, R. Amslinger, M. Andreozzi, A. Armejach, N. Asmussen, S. Bharadwaj, G. Black, G. Bloom, B. R. Bruce, D. R. Carvalho, J. Castrillón, L. Chen, N. Derumigny, S. Dielsterhorst, W. Elsasser, M. Fariborz, A. F. Farahani, P. Fotouhi, R. Gambord, J. Gandhi, D. Gope, T. Grass, B. Hanindhito, A. Hansson, S. Haria, A. Harris, T. Hayes, A. Herrera, M. Horsnell, S. A. R. Jafri, R. Jagtap, H. Jang, R. Jeyapaul, T. M. Jones, M. Jung, S. Kannoth, K. Khaleghzadeh, Y. Kodama, T. Krishna, T. Marinelli, C. Menard, A. Mondelli, T. Mück, O. Naji, K. Nathella, H. Nguyen, N. Nikoleries, L. E. Olson, M. S. Orr, B. Pham, P. Prieto, T. Reddy, A. Roelke, M. Samani, A. Sandberg, J. Setoain, B. Shingarov, M. D. Sinclair, T. Ta, R. Thakur, G. Travaglini, M. Upton, N. Vaish, I. Vougioukas, Z. Wang, N. Wehn, C. Weis, D. A. Wood, H. Yoon, and É. F. Zulian, “The gem5 Simulator: Version 20.0+,” CoRR, vol. abs/2007.03152, 2020. [Online]. Available: https://arxiv.org/abs/2007.03152
  13. [13]R. N. Watson, P. G. Neumann, J. Woodruff, M. Roe, H. Almatary, J. Anderson, J. Baldwin, G. Barnes, D. Chisnall, J. Clarke, B. Davis, L. Eisen, N. W. Filardo, F. A. Fuchs, R. Grisenthwaite, A. Ioannou, B. Laurie, A. T. Markettos, S. W. Moore, S. J. Murdoch, K. Nienhuis, R. Norton, A. Richardson, P. Rugg, P. Sewell, S. Son, and H. Xia, “Capability Hardware Enhanced RISC Instructions: CHERI Instruction-Set Architecture (Version 9),” University of Cambridge, Computer Laboratory, Tech. Rep. UCAM-CL-TR-987, Sep. 2023. [Online]. Available: https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-987.pdfDOI
  14. [14]A. Roelke and M. R. Stan, “Risc5: Implementing the RISC-V ISA in gem5,” in First Workshop on Computer Architecture Research with RISC-V (CARRV), 2017.
  15. [15]K. Nienhuis, A. Ioannou, T. Bauereiss, A. Fox, M. Roe, B. Campbell, M. Naylor, R. M. Norton, S. W. Moore, P. G. Neumann et al., “Rigorous engineering for hardware security: Formal modelling and proof in the cheri design and implementation process,” in 2020 IEEE Symposium on Security and Privacy (SP). IEEE, 2020, pp. 1003–1020.
  16. [16]A. L. Duque Antón, J. Müller, P. Schmitz, T. Jauch, A. Wezel, L. Deutschmann, M. Rahmani Fadideh, D. Stoffel, and W. Kunz, “VeriCHERI: Exhaustive Formal Security Verification of CHERI at the RTL,” in Proceedings of the 43rd IEEE/ACM International Conference on Computer-Aided Design, ser. ICCAD ’24. New York, NY, USA: Association for Computing Machinery, 2025.
  17. [17]“CHERI-RISC-V Sail model.” [Online]. Available: https://github.com/CTSRD-CHERI/sail-cheri-riscv
  18. [18]A. Joannou, J. Woodruff, R. Kovacsics, S. W. Moore, A. Bradbury, H. Xia, R. N. Watson, D. Chisnall, M. Roe, B. Davis, E. Napierala, J. Baldwin, K. Gudka, P. G. Neumann, A. Mazzinghi, A. Richardson, S. Son, and A. T. Markettos, “Efficient tagged memory,” in 2017 IEEE International Conference on Computer Design (ICCD), 2017, pp. 641–648.DOI
  19. [19]“CHERI-QEMU.” [Online]. Available: https://github.com/CTSRD-CHERI/qemu
  20. [20]“Juliet C/C++ 1.3.” [Online]. Available: https://samate.nist.gov/SARD/test-suites/112

Paper details

vlnc:W_2nny48st
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 2

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

Not recorded for this paper

View statement
Looking for related papers…
Contents