Open CharlyCst opened 2 months ago
Okay, i've looked at the both solutions for a bit, and here are some of my considerations:
Miralis in a big picture: It seems feasible to decouple SM from OpenSBI. After boot SM works as a mostly passive module, processing some traps (mostly ecalls) or timer interrupts. It has a fairly well-documented call interface, so that should not be too complicated to reproduce.
Keystone by default
┌────────────────┐ ┌────────────────┐
┌──────────────┐ │ │┌──────────────┐│ │┌──────────────┐│
│ U-Mode │ │ ││ App ││ ││ E-App ││
└──────────────┘ │ │└──────────────┘│ │└──────────────┘│
│ │ untrusted │ │ enclave │
┌──────────────┐ │ │┌──────────────┐│ │┌──────────────┐│
│ S-Mode │ │ ││ OS ││ ││ RT ││
└──────────────┘ │ │└──────▲┌──────┘│ │└──────▲┌──────┘│
│ Ecall/──┼┼───────┘ └───────┼┼─Ecall/┘
┌──────────────┐ │ ┌──mret┴▼─────────────────┴▼─────mret
│ M-Mode │ │ │ Security Monitor | OpenSBI │
└──────────────┘ │ └─────────────────────────────────┘
Keystone with Miralis
┌────────────────────────────────────┐┌────────────────┐
┌──────────────┐ │ │┌──────────────┐ ┌──────────────┐ ││┌──────────────┐│
│ U-Mode │ │ ││ OpenSBI │ │ App │ │││ E-App ││
└──────────────┘ │ │└─────┬──▲─────┘ └──────────────┘ ││└──────────────┘│
│ │ │ │ untrusted ││ enclave │
┌──────────────┐ │ │ Trap&│ ┌──────────────┐ ││┌──────────────┐│
│ S-Mode │ │ │ │ Emulate │ OS │ │││ RT ││
└──────────────┘ │ │ │ │ └──────▲┌──────┘ ││└──────▲┌──────┘│
│ └──────┼──┼────────────────┼┼Ecall/── └───────┼┼Ecall/─┘
┌──────────────┐ │ ┌─────▼──┴────────────────┘▼────mret─────────┴▼───mret
│ M-Mode │ │ │ Miralis | Security Monitor │
└──────────────┘ │ └────────────────────────────────────────────────────┘
Academic Verification and Industry Impact: From an academic standpoint, if we were to rebuild SM on top of Miralis, it would be advisable to verify its correctness over Miralis as well. Given that SM is approximately 2000 LoC and Miralis is approximately 3000 LoC, with the latter likely to grow, this would be a challenging undertaking. In return, we will receive approximately 5,000 LoC TCB (for two platforms and a limited number of RV64 ISA extensions). From an industry perspective, Keystone's website lists only one company as an "Industry User." It is therefore unclear what impact this will have on the industry.
Available Platforms:
It is not yet clear whether the existing board will work with Keystone. A PR has been submitted which is intended to add support for the VisionFive2 board. Nevertheless, Qemu is already compatible with the master, and further testing can be conducted if necessary.
Engineering Effort: A notable portion of the code in Keystone's SM exhibits functionality comparable to Miralis, or at the very least, similar utility functions. It is to be hoped that a great deal of the existing code can be reused, for example, in the case of a trap handler, CSR read and write functionality or PMP management. However, other elements, such as all ten ECall handlers for RT and OS, the crypto attestation module (which is approximately 3 to 4k LoC in length ^_^) and a small number of additional items would have to be approached from scratch. Additionally, it is probable that we will require a rewrite of the SBI calls to remove OpenSBI from TCB completely. If there are no plans to support the "H" RISC-V extension, the SM code can be simplified.
Documentation and Codebase: In my view, Keystone's (codebase)[https://github.com/keystone-enclave/keystone/tree/master] and documentation represents the lesser of two evils, given that CoVE is still under development (version 0.7 is the latest).
With this one we have quite an interesting story. The documentation seems to be at v0.7, but there is no central repository or any cross-references to other CoVE repos. From what i've grasped from different docs, CoVE is a separate RISC-V extension (dosc), that leverages some other non-ISA RISC-V extensions like SMMTT or IOMMU to implement some of its' CVM capabilities.
The official v0.7 documentation dictates (the models are simplified, please refer to p.30 of specification doc for further details) 3 deployment models:
CoVE default v1
┌─────────────────┐ ┌─────────────────┐
┌───────────────┐ │ │┌───────────────┐│ │┌───────────────┐│
│ (V)U-Mode │ │ ││ App ││ ││ App ││
└───────────────┘ │ │└───────────────┘│ │└───────────────┘│
│ │ host │ │ confidential │
┌───────────────┐ │ │ │ │┌───────────────┐│
│ VS-Mode │ │ │ │ ││ TVM ││
└───────────────┘ │ │ │ │└──────┬─▲──────┘│
│ │ │ │ │ │ │
┌───────────────┐ │ │┌───────────────┐│ │┌──────▼─┴──────┐│
│ HS-Mode │ │ ││ OS ││ ││ TSM ││
└───────────────┘ │ │└──────▲─┬──────┘│ │└──────┬─▲──────┘│
│Ecall/─COVEH-ABI────┘ └────Ecall/───────┘
┌───────────────┐ │ ┌─mret──┴─▼─────────────────────▼mret─────┐
│ M-Mode │ │ │ Firmware + TSM Driver │
└───────────────┘ │ └─────────────────────────────────────────┘
CoVE default v2
┌─────────────────┐ ┌─────────────────┐
┌───────────────┐ │ │┌───────────────┐│ │┌───────────────┐│
│ (V)U-Mode │ │ ││ App ││ ││ App ││
└───────────────┘ │ │└───────────────┘│ │└───────────────┘│
│ │ host │ │ confidential │
┌───────────────┐ │ │┌───────────────┐│ │┌───────────────┐│
│ VS-Mode │ │ ││ OS ││ ││ TVM ││
└───────────────┘ │ │└──────▲─┬──────┘│ │└──────▲─┬──────┘│
│ └─COVEH-ABI/H-ext─┘ Ecall/─COVG-ABI─────┘
┌───────────────┐ │ ┌───────┴─▼───────────────sret──┴─▼───────┐
│ HS-Mode │ │ │ TSM │
└───────────────┘ │ └─────────────────────────────────────────┘
│
┌───────────────┐ │ ┌─────────────────────────────────────────┐
│ M-Mode │ │ │ Firmware + TSM Driver │
└───────────────┘ │ └─────────────────────────────────────────┘
CoVE default v3
┌─────────────────┐ ┌─────────────────┐
┌───────────────┐ │ │┌───────────────┐│ │┌───────────────┐│
│ (V)U-Mode │ │ ││ App ││ ││ App ││
└───────────────┘ │ │└───────────────┘│ │└───────────────┘│
│ │ host │ │ confidential │
┌───────────────┐ │ │ │ │┌───────────────┐│
│ VS-Mode │ │ │ │ ││ TVM ││
└───────────────┘ │ │ │ │└──┬─────Ecall/─┘│
│ │ │ │ │ mret│
┌───────────────┐ │ │┌───────────────┐│ │ │ │
│ HS-Mode │ │ ││ OS ││ │ COVG-ABI │
└───────────────┘ │ │└────────┬──────┘│ │ │ │
│ Ecall/─COVH-ABI────┘ │ │ │
┌───────────────┐ │ ┌──mret───▼─────────────┘ ▼ │
│ M-Mode │ │ │ Firmware + TSM │
└───────────────┘ │ └─────────────────────────────────────────┘
For the 3 official models i believe that adding miralis to the picture would look somewhat similar to Keystone's scheme.
And remember about the unofficial deployment model? Well, in the Rivos repo for CoVE, a model is proposed that allows for the operation of CoVE with Miralis without any modifications.:
CoVE unofficial(trusted firmware)
┌─────────────────┐ ┌─────────────────┐
┌───────────────┐ │ │┌───────────────┐│ │┌───────────────┐│
│ (V)U-Mode │ │ ││ App ││ ││ App ││
└───────────────┘ │ │└───────────────┘│ │└───────────────┘│
│ │ host │ │ confidential │
┌───────────────┐ │ │┌───────────────┐│ │┌───────────────┐│
│ VS-Mode │ │ ││ OS ││ ││ TVM ││
└───────────────┘ │ │└──────┬─▲──────┘│ │└──────┬─▲──────┘│
│ └─────COVH-SBI────┘ └─────COVG-SBI────┘
┌───────────────┐ │ ┌───────▼─┴─────────────────────▼─┴───────┐
│ HS-Mode │ │ │ TSM │
└───────────────┘ │ └───────────────────┬─▲───────────────────┘
│ SBI
┌───────────────┐ │ ┌───────────────────▼─┴───────────────────┐
│ M-Mode │ │ │ Firmware │
└───────────────┘ │ └─────────────────────────────────────────┘
CoVE unofficial with Mirais
┌─────────────────┐ ┌─────────────────┐
┌───────────────┐ │ │┌───────────────┐│ │┌───────────────┐│ ┌────────────────┐
│ (V)U-Mode │ │ ││ App ││ ││ App ││ │ Firmware │
└───────────────┘ │ │└───────────────┘│ │└───────────────┘│ └──────┬─▲───────┘
│ │ host │ │ confidential │ │ │
┌───────────────┐ │ │┌───────────────┐│ │┌───────────────┐│ │ │
│ VS-Mode │ │ ││ OS ││ ││ TVM ││ │ │
└───────────────┘ │ │└──────┬─▲──────┘│ │└──────┬─▲──────┘│ Trap&│
│ └─────COVH-SBI────┘ └─────COVG-SBI────┘ │Emulate
┌───────────────┐ │ ┌───────▼─┴─────────────────────▼─┴───────┐ │ │
│ HS-Mode │ │ │ TSM │ │ │
└───────────────┘ │ └───────────────────┬─▲───────────────────┘ │ │
│ Ecall/ │ │
┌───────────────┐ │ ┌───────────────────▼mret───────────────────────────▼─┴───────┐
│ M-Mode │ │ │ Miralis │
└───────────────┘ │ └─────────────────────────────────────────────────────────────┘
Apparently, there is a RISC-V VM-based TEE from IBM, called ACE, that implements the RISC-V CoVE spec's deployment model 3. The project seems to be supported and constantly updated, unlike Salus, and aims to have a formally verifiable Security Monitor (albeit it's size is ~9000 LoC). For now it seems like it runs only on Qemu, and Miralis's place here would be similar to the Keystone model. I could look into this more thoroughly if that is somewhat viable.
Ho interesting, yes indeed we should probably investigate that project too, good catch 🙂
The primary goal of Miralis is to remove the firmware from the trusted computing base (TCB), so far we mostly tested that firmware and payloads works without modifications but we didn't demonstrate a compelling use case for Miralis yet. The goal of this issue is to investigate different options to built a demonstrator.
The area where Miralis brings the most value is confidential computing, that is where we really care about small and well defined TCB. I have two confidential computing frameworks in mind that would be got fits, so we will need to explore each of those and decide which one we want to go for.
The questions we need to answer for each option are:
In addition we want to collect all relevant links (docs, source code, papers, blog posts, or anything potentially useful).
Keystone
The first is Keystone. Keystone is pretty old and well established now (the paper is from 2020), it is a system that allows to create user-space enclaves on RISC-V by using a M-mode security monitor and a S-mode runtime for the enclaves. Keystone is built on top of OpenSBI, so includes the all of it in the TCB. We could re-build the M-mode portion of Keystone on top of Miralis and push OpenSBI outside of the TCB in vM-mode to offer enclaves without firmware in the TCB.
Links:
CoVE
CoVE is a RISC-V effort to develop an architecture extension that offers support for confidential VMs. This seems to be mostly an industry-lead effort (whereas Keystone is much more academic-focused), it is more recent than keystone and seems to have broader community support. I am not sure if CoVE is the official name, the extension is called
SmMTT
where MTT stands for Memory Tracking Table. Similar to Keystone, the confidential computing capabilities need to be integrated into an existing M-mode software. I don't know if there are existing implementations (maybe in OpenSBI or a fork of it?). I am not sure what is the current state of the proposal (is it ratified, or still evolving?) and support in the ecosystem.Links: