· AI dev tools
Cerise project extends formal verification to bug-finding in CHERIoT switcher
The ability for a malicious caller to trigger a fault in the switcher, thereby gaining access to the callee’s stack frame and its private data, was one of the two critical vulnerabilities uncovered…
The ability for a malicious caller to trigger a fault in the switcher, thereby gaining access to the callee’s stack frame and its private data, was one of the two critical vulnerabilities uncovered during a verification effort on the CHERIoT switcher. This discovery arose from a research project, Griotte, which was a sub-initiative of the longer-running Cerise project.
Cerise, which translates to "cherry" in French, originated nearly a decade ago at Aarhus University. Its fundamental objective involves devising formal techniques to validate the attributes of capability machines, paying particular attention to issues of non-monotonicity, and establishing comprehensive, end-to-end proofs even when facing code whose inner workings are unknown. The scope of Cerise has expanded to encompass various facets of capability machines, and its development has benefited from collaborations with several other academic institutions, including the research group led by Dominique Devriese at KU Leuven, alongside the universities of Cambridge and Edinburgh.
Initially, Cerise involved proofs conducted manually on idealized machine models, and its early focus was centered on reasoning about the control-flow integrity of encapsulation within stack-based calling conventions. However, the research group has since scaled this approach across three distinct dimensions. Firstly, the proofs were made more rigorous; Cerise now integrates with the Iris separation logic framework within the Rocq theorem prover, a development that has been essential for maintaining correctness as the proofs have grown increasingly complex. Secondly, the investigation broadened to cover a wider spectrum of properties, such as those related to attestation and Memory-Mapped I/O (MMIO). Thirdly, Cerise was adapted to operate with an instruction set that more closely resembles the CHERIoT Sail model, allowing for the verification of programs utilizing those specific instructions.
When the author began their doctoral studies, the CHERIoT project had only recently been announced. This provided an opening to apply the verification methodologies developed in Cerise to the CHERIoT switcher, specifically to confirm its compartment isolation and no-capture enforcement. This led to the initiation of the Griotte sub-project. During this verification work, two security flaws were unearthed in the CHERIoT switcher. The first issue allowed a scheduler, whether malicious or faulty, to resurrect an exited thread in an outdated state, thereby granting it access to a capability it should no longer possess. The second vulnerability permitted an adversarial caller to exploit the stack high watermark register to induce a fault within the switcher, consequently obtaining access to the callee’s stack frame and its private information.
The threat model inherent in CHERI/CHERIoT accounts for interactions with compartments that are unknown, containing arbitrary code that might be buggy or malicious, and which can share objects in memory. Reasoning about such arbitrary code presents a significant hurdle because it demands a complete characterization of every possible behavior that code might exhibit. The difficulty intensifies when trying to define what an unknown compartment can influence; this requires accounting not only for direct inputs—if an unknown compartment receives a write capability to a memory segment, it is behaviorally granted the power to overwrite that memory region—but also for indirect influences. Indirect effects include recursive access, where if an unknown compartment is physically given a read capability to a memory area, it is behaviorally endowed with the ability to acquire whatever capability resides within that memory region. Furthermore, the system must account for access via non-monotonic domain transitions; for instance, if an unknown compartment is physically provided a sealed entry point capability to a "counter" compartment's increment function, it is behaviorally granted the capacity to affect that counter, but strictly limited to incrementing it.
A distinctive capability of Cerise is its capacity to reason about this latter complexity. The difficulty in designing such a characterization lies in the necessity for it to be both precise enough and simple enough to allow for the verification of the programs that are the subject of the work. Abstractly, Griotte establishes a language designed to concisely describe what is impacted—and conversely, to state what is not impacted. The kinds of properties sought for description go beyond mere memory safety; this includes guarantees like "if I pass a buffer to the caller, I am assured it cannot access global data I never shared," as well as no-capture guarantees, such as "if I share a buffer with its global permissions removed, I am assured it cannot retain a copy across calls," among many other security attributes like secrecy.
Technically, the reasoning system was constructed in two components. Initially, a separation logic was defined and proven sound, enabling line-by-line verification of known code to demonstrate that it meets expected pre- and post-conditions and preserves the necessary invariants. This logic was applied to both the switcher’s code and to the code of specific compartments under scrutiny, such as a key-value store. This separation logic was engineered for reusability, with the expectation that it could be applied to verify other compartments of interest. Secondly, a logical relation within the separation logic was defined; this relation serves as an over-approximation of the impact of unknown code, which the separation logic then utilizes to reason about a jump into unknown code (via the switcher) in a single step, effectively functioning as a "universal contract" for CHERIoT. A key aspect of separation logic is the frame rule, which dictates that if one can confirm that the resources (both informally and technically within separation logic) of the calling code are separate from those described by the logical relation, those resources will remain intact after the call. For example, if unknown code is invoked with a capability to a shared buffer while retaining some private data, the logical relation mandates that the unknown code must only be given capabilities that are technically safe to share. Consequently, a universal contract is established, asserting that if an adversary only has access to capabilities deemed safe to share, it can execute without issue and only generate other safe-to-share capabilities.
The initial phase involved building a simplified model of CHERIoT alongside a miniature version of the CHERIoT-RTOS. This model specifically mirrored the compartmentalization mechanisms and the cross-compartment call sequence of the switcher. The features of the CHERIoT hardware, including the new permissions for deep immutability and deep locality, are reflected in this simplified model. Although the mini switcher does not replicate the CHERIoT switcher instruction by instruction, it executes the same procedural steps. Within this model, proofs on numerous small examples demonstrated that the hardware-software co-design successfully implements the anticipated memory-safety properties, and that the switcher’s overall architecture enforces both stack safety and compartmentalization. These "end-to-end" results for concrete examples assume the machine begins in a state where the firmware image has been correctly loaded; the loader itself has not been verified and is thus considered part of the Trusted Computing Base (TCB). Technically, the analysis only considers executions originating from a "loader-final" state. Since the loader is deterministic, it is relatively straightforward to capture the memory contents from a device or simulator after the loader has run and confirm that a specific execution of the loader meets the criteria for our "loader-final" state. While proving the loader correct is anticipated, this remains a future endeavor.
The initial model represented a simplification of CHERIoT, omitting features like exceptions and concurrency/context switching, and excluding certain switcher optimizations, such as the stack high watermark. The CHERIoT team has maintained a commitment to ensuring CHERIoT's trustworthiness and has been highly cooperative with the verification efforts. To support this, they embedded detailed annotations within the switcher's source code, outlining the expected invariants and behavior of the switcher in the form of pre- and post-conditions for its execution blocks. They highlighted that the complex control flow within the switcher's exception path was a likely source of errors. Our findings indicated that the verified cross-compartment call (and return) path was relatively uncomplicated (though formally stating no-capture and stack safety at the separation logic level is far from trivial!), yet it provided a solid foundation. Nevertheless, as the CHERIoT team noted, the features initially excluded are more susceptible to mistakes: the switcher's exception handler, which manages context switching and error handling, possesses a more intricate and convoluted execution path, and the stack high watermark introduces a new trust boundary.
By extending the verification work to incorporate the features absent in the initial model, some of the scenarios proven in the simplified setup ceased to function, which, in fact, uncovered bugs within the switcher. The first vulnerability identified stems from an interaction between the exception handler and the stack high watermark. When an exception handler is active, every instruction must either guarantee that it will not fault, or that the exception handler can safely proceed (either by unwinding forcibly to the caller or by yielding control to the faulting compartment's error handler). In our formal proof, this translates into every instruction carrying a proof obligation ensuring that all system invariants remain valid, even if the instruction is capable of faulting. Conversely, the stack high watermark (SHWM) is an optimization that allows the switcher to clear only the stack frame used during the call. Specifically, the SHWM tracks, in hardware, the highest memory address that has been written to on the stack, and the switcher only cleans up to this address, rather than the entire shared stack region. The switcher's code relied on an invariant concerning the SHWM: it must always reside between the boundaries of the stack capability at the moment of a cross-compartment call. To uphold this, the switcher consistently resets it within the stack capability bounds upon both cross-compartment calls and returns. This invariant was inherently dynamic because the stack boundaries shift between cross-compartment invocations. However, it was discovered that this invariant was not upheld; a malicious caller could construct a stack pointer with restricted boundaries, alongside a stack object located outside this restricted stack, intended for later use by a callee. This situation could precipitate a fault during the callee's switcher return sequence, before the callee's stack frame has been cleared, which then enables the malicious caller to reclaim
Why it matters
For developers working with secure systems, this research demonstrates a powerful toolchain for verifying complex code against adversarial threats. The ability to reason about unknown or malicious code is critical for building trustworthy, robust software components.




