MesaTEE Open-Source Released: A Framework for Universal Secure Computing
By: Baidu Security X-Lab
Tags: Memory Safety, Security, Intel Sgx, Rust, Open Source

Technical Features

Memory Safe

The name “MesaTEE” originates from Memory Safe Trusted Execution Environment. Although hardware Trusted Execution Environments (TEEs) have already provided solid foundation for secure computing (e.g. Intel SGX), they do not guarantee the memory safety. TEEs are still vulnerable to issues such as use after free, double free, and buffer overflow etc. Using formal verification to prove memory safety turns out to be very costly in time and effort. A good example is the seL4 verification, which takes at least 8 person years. And any minor modification resets the verification work back to zero. Obviously it is not acceptable for any practical software development requiring changes back-and-forth.

Therefore, rewriting everything using memory safe languange such as Rust is the optimal choice. It intrinsically guarantees memory and thread safety during compilation, and saves the huge amount of efforts with formal verification. At the same time, the performance is not sacrificed (Rust program is almost equivalent to C/C++ program in performance).

However, rewriting everything in Rust is not an easy task. Sometimes the memory safe components written in Rust have to coexist with unsafe components in C/C++. For that we created Hybrid Memory Safety and the following rule-of-thumbs:

1. Unsafe components should be appropriately isolated and modularized, and the size should be small (or minimized)

2. Unsafe components should not weaken the safe ones, especially public APIs and data structures

3. Unsafe components should be clearly identified and easily upgraded

Non-bypassable Security

Once the memory safety guaranteed, control flow and data flow integrities can be protected. On top of it, MesaTEE further adopts the Non-bypassable Security Paradigm. This ensures that all control/data flows must pass the critical security checkpoints. It significantly reduces the difficulty of audit and access control, minimizes the exposure to attacks, and regulates the deployment of access control policy. It also makes security formal verification more feasible.

Encryption Isolation and Remote Attestation

Traditional cloud computing and blockchain cannot guarantee the integrity and confidentiality of data and codes, which has become the obstacle for users to adopt them. MesaTEE offers a superb solution to this. Using TEE with Intel SGX, it securely isolates and encrypts cloud users’ data and code execution. Even when the operating system, virtual machine manager (VMM/hypervisor), or other adjacent virtual machines are compromised, the integrity and confidentiality of these data/codes can still be protected. Users can also remotely verify the execution environment to ensure the codes executed is as expected. It is worth noting that MesaTEE directly integrates remote attestation into end-to-end encrypted communication, ensuring that the transmission destination is the desired environment while establishing the encrypted channel. Combined with the memory safe and non-bypassable security, MesaTEE minimizes the possibility of attacker penetration to the limit from both outside and inside, from hardware to software, and ensures that once the data is released, regardless of transmission, remote computing, remote storage, it always gets verifiable isolation and encryption protection.

Flexible and Configurable Security Levels

MesaTEE is compatible with a wide range of TEE platforms, including TPM, Intel SGX/MKTME, AMD SEV/SME, ARM TrustZone, Risc-V Key-stone and FPGA etc. It provides different levels of security based on different hardware environments and different needs. Specifically MesaTEE supports 5 security levels:

Unprotected — the legacy mode without trust and security SoftTEE — trust is established purely based on software (SoftTrust), the environment is measured by collecting system metrics, keys are protected via whitebox encryption, anti-debugging methods are deployed, and critical components are obfuscated to defend against reverse engineering. Optionally, security can be further enhanced by incorporating MesaLock Linux (Linux distribution with user space core utils written in memory safe languages) and Non-bypassable Gateway (NBGW). MesaTEE TPM — the Trusted Platform Module (TPM) chip is added to enforce secure boot and measure the system boot chain all the way up to the application logic. However TPM measurement can assure only static trustworthy; users can add MesaLock Linux and NBGW to enhance dynamic security. Meanwhile, for multi-tenants situation, payloads can be further isolated with the help of a light-weighted secure hypervisor (e.g. Kata Containers). MesaTEE SEV/MKTME — the upper layers are the same with the TPM mode except that the physical memory is encrypted automatically by CPU features like AMD SEV or Intel MKTME. This withstands cold boot attack and most software-based attacks. MesaTEE SGX — the ultimate protection, utilizing Remote Attestation and Secure Enclave to isolate and encrypt secrets automatically. MesaTEE SGX adds TPM and MesaLock Linux to ensure that the exterior operating system is also trusted and secure, defends against side channel attack on enclave technology.

Versatile Features and Excellent Performance

MesaTEE does not drop functionality or performance while providing ultimate security. It provides a unified “Function as a Service” (FaaS) abstract API for various TEE platforms. Developers can easily develop a portable TEE program. On top of this, MesaTEE also encapsulates a WebAssembly/Python abstraction layer, to further reduce development requisites and costs, while increasing coding flexibility. Not only that, MesaTEE also presets most common computing modules for encryption and decryption, certificate management, privacy protection set operations, linear regression, GBDT, deep learning and other big data/machine learning applications. User only needs to call the direct interfaces.

The performance of MesaTEE is also superb. For example (the following performance data is collected from Intel NUC8I7HVK Mini PC, the test takes place in MesaTEE’s highest security level Intel SGX mode, data and computing are always isolated and encrypted):