Skip to content

SGX is_enclave_range/is_user_range overflow checking #76343

@okready

Description

@okready

Currently, the is_enclave_range and is_user_range functions in sgx::os::fortanix_sgx::mem do not perform overflow checks for input memory ranges. While debug builds will panic if an overflow occurs, release builds perform no such checking, which can lead to false positive results from either function for overflowing memory ranges.

One of the typical uses for these functions is to validate memory ranges passed into the enclave from untrusted code. Compromised untrusted code can intentionally pass overflowing ranges to enclave code, and without proper overflow checking, these false positives can potentially result in security vulnerabilities such as leakage of secret data or overwriting of enclave data (including code) with data from the untrusted application layer.

While applications can be left responsible for overflow checking, it is another step that application authors have to consider that is easy to overlook. Additionally, the corresponding sgx_is_within_enclave and sgx_is_outside_enclave functions from the Intel SGX SDK handle overflow checks, so developers migrating from the Intel SGX SDK to x86_64-fortanix-unknown-sgx or referring to existing Intel SGX SDK-based code may not expect overflow handling to be omitted from x86_64-fortanix-unknown-sgx.

Adding overflow checks to is_enclave_range and is_user_range should be relatively low-impact. Breakage of existing code is not expected; ranges that do not trigger overflow with the current implementations should have the same results, while overflowing ranges are more than likely already yielding unexpected behavior and exposing possible security vulnerabilities as described and would benefit from the fix (unless the application is already checking for overflow manually, in which case such checks will simply become redundant). Bringing feature parity with the Intel SGX SDK versions of these functions will also avoid unintentional mistakes from switching over.

Metadata

Metadata

Assignees

No one assigned

    Labels

    O-SGXTarget: SGX

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions