Microsoft To Harden The Trust Boundary of VBS Enclaves


Microsoft has recently published comprehensive guidance for developers working with Virtualization-Based Security (VBS) enclaves, highlighting critical security measures to strengthen the trust boundary between different virtual trust levels.

The guidance by the Microsoft Security team, addresses fundamental security challenges that arise when implementing VBS enclaves, which use the hypervisor’s virtual trust levels to isolate regions of memory and code execution within user-mode processes.

VBS enclaves provide powerful trusted execution environments (TEEs) that protect sensitive data, such as encryption keys, from access even by malicious administrators.

However, these protections introduce a unique trust boundary between the VTL1 enclave and the VTL0 host process.

Unlike traditional trust boundaries where higher privileged entities are external to lower privileged ones, an enclave exists within its host process, requiring developers to adopt a new security perspective.

The primary security principle emphasized is that enclaves must never trust VTL0.

While host processes cannot read or write in the enclave’s memory region, an enclave can access its host’s memory, creating security vulnerabilities if not properly managed.

While Microsoft researchers noted that one critical recommendation is validating that pointers passed from the host process are outside the address range of the VTL1 enclave.

Capture VTL0 structures in VTL1 before checks (Source – Microsoft)

Microsoft illustrates this vulnerability with code examples showing how malicious hosts could manipulate pointer values. In one example, the host calls an enclave function with a crafted address parameter:-

LPVOID GetState(LPVOID lpParam) {
    State* state = (State*)lpParam;
    if (state == nullptr) {
        return (LPVOID)E_INVALIDARG;
    }
    *state = g_State;
    return (LPVOID)S_OK;
}

Without proper validation, this function could inadvertently allow a host to overwrite sensitive enclave memory.

Secure Implementation Patterns

Developers are advised to use the EnclaveGetEnclaveInformation API during initialization to determine enclave boundaries and verify that all host-provided pointers fall outside these bounds.

CRITICAL_SECTION locks (Source – Microsoft)

Additionally, structures from VTL0 should be copied into VTL1 memory before validation to prevent time-of-check-time-of-use (TOCTOU) attacks.

The guidance emphasizes that secrets should always be generated within the enclave and never exposed outside secure channels.

Developers are warned against reinventing security primitives, suggesting the use of Windows Implementation Library and RAII wrappers.

Interestingly, Microsoft even mentions exploring Rust for enclave development, noting a proof-of-concept developed during a recent MORSE hackathon that leverages the language’s memory safety features.

Collect Threat Intelligence on the Latest Malware and Phishing Attacks with ANY.RUN TI Lookup -> Try for free



Source link