Overview
HyperEnclave 是一个开放的、跨平台的基于进程的TEE。它对于硬件的依赖很小,只需要平台支持虚拟化扩展 ( virtualization extension ) ,就可以创建隔离的执行环境。它支持灵活的飞地操作模式 ( flexible enclave operation modes ),以满足不同飞地工作负载下的安全和性能需求。原本依赖 SGX 运行的程序,可无痕迁移到 HyperEnclave 上面。(根据论文,估计是蚂蚁将 HyperEnclave 应用到了自己的业务上)
HyperEnclave 中定义了 3 种模式(不是指上面的飞地操作模式)。 HyperEnclave supports the following modes:
- the monitor mode, i.e., VMX root operation mode;
- the normal mode for the primary OS and untrusted part of applications, i.e., ring-0 and ring-3 of the VMX non-root operation mode respectively; and
- the secure mode for the enclave, which could be ring-3 and ring-0 of the VMX non-root operation mode, or ring-3 of the VMX root operation mode, depending on the enclave operation mode.
基于 secure mode 下的三种 CPU mode, 设计了三种 HyperEnclave 的飞地操作模式
- Guest user enclave (GU-Enclave):guest ring-3 of the VMX non-root operation mode.
- Privilege enclaves (P-Enclaves):guest privileged mode, 即 ring-0 of the VMX non-root.
- Host user enclave (HU-Enclave):host user mode, 即 ring-3 of the VMX root.
基本组成
HyperEnclave 由下列组件组成:
- RustMonitor 一个轻量级虚拟机监视器,它管理飞地内存,强制内存隔离,并控制飞地状态转换。( monitor mode )
- Normal VM 是 RustMonitor 创建独特的 guest VM。运行 Primary OS,并在普通模式 ( normal mode ) 下托管应用程序的不受信任部分。
- Applications 应用程序不可信任的部分,它运行在 primary OS 中,同时也是普通模式下 ( normal mode )。
- Enclave 应用程序的受信任部分,它运行在安全模式下 ( secure mode )。
- Kernel module 在 primary OS 中的一个内核模块,用于加载、测量和启动 RustMonitor,以及调用模拟的特权操作 (emulated privileged operations)。
- Enclave SDK 提供 enclave SDK,其API和 Intel SGX SDK 兼容,包括不可信运行时和可信运行时 (SDK uRTS and SDK tRTS)。因此大多数 SGX 程序开源在不修改或少修改源码的情况下运行在 HyperEnclave 中。
度量过程
在系统启动时,一段静态且不可变的代码——CRTM (Core Root of Trust for Measurement),会首先执行以引导构建后续固件和软件的度量链,包括BIOS、grub、主操作系统内核和initramfs。每个组件的度量值全部存在 TPM PCRs 中。
RustMonitor 镜像是被保存在 initramfs 中, kernel module 会度量 RustMonitor 镜像并将值扩展到 TPM PCRs,然后在早期用户空间 (early userspace) 运行 RustMonitor,此时其他依赖磁盘文件系统的用户空间程序 (userspace program) 都还没启动。
RustMonitor 会设置自己的栈,页表,IDT 等上下文,并准备 vCPU 的配置。接着启动一个普通的 VM,同时将 primary OS 降级到 normal mode (即 vmx non-root)。(ps:感觉这里像是将 primary OS 镜像作为 VM 镜像启动?)
最后返回 kernel module 继续启动, kernel module 此时运行在 normal mode 下 (之前是在没有开启 VMX 的环境中运行)。
整个过程中,RustMonitor 像 KVM 一样以 type-2 hypervisor 的方式加载,又像 Xen 一样以 type-1 hypervirsor 的方式运行。
Related
article: HyperEnclave: An Open and Cross-platform Trusted Execution Environment | USENIX
code:
- GitHub - HyperEnclave/hyperenclave: An Open and Cross-platform Trusted Execution Environment (archived)
- GitHub - asterinas/hyperenclave: HyperEnclave is an open and cross-platform trusted execution environment.
论文分享|USENIX ATC 2022:TEE创新研究成果HyperEnclave
本文作者:文七安
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!