Article ID: 000058511 Content Type: Maintenance & Performance Last Reviewed: 08/10/2021

Passing Large Structures to an Enclave is not Causing Paging in the Enclave Page Cache (EPC)

BUILT IN - ARTICLE INTRO SECOND COMPONENT
Summary

How to copy all of the data in structures from the untrusted domain to the trusted domain of Intel® Software Guard Extensions (Intel® SGX) enclaves

Description

Declared ecall in Enclave Definition Language (EDL) file as:

struct pair_t {
uint32_t key;
uint32_t value;
};

struct table_t {
struct pair_t* pairs;
uint32_t num_pairs;
};

public sgx_status_t ecall_sort_table([in] struct table_t * rel);

The table_t structure is 1.1 GB, which is much larger than the 128-MB EPC. The memory used in the enclave is much less than the allocated memory of the structure in the untrusted application, and there is no paging in the EPC.

Resolution

The above structure and ecall function definitions result in a shallow copy of the structure. A shallow copy copies only the pointer addresses, not the actual data referenced by the pointers. In this case, the pointer address is copied to the enclave's memory space in the EPC, or trusted domain, but the data remains in the untrusted domain. The EPC is not experiencing paging because the majority of the data remains in the untrusted domain.

Below are structure definitions and declarations that achieve a shallow copy and a deep copy. To deep copy the structure data to the EPC, declare the structures in the EDL file using count and size, which are set by the developer.

struct pair_t {
uint32_t key;
uint32_t value;
};

// This structure declaration results in a shallow copy of the pairs structure

struct table_t {
struct pair_t* pairs;
uint32_t num_pairs;
};

// This structure declaration results in a deep copy of the pairs structure

struct deep_table_t {
[count = 1, size = 12] struct pair_t* pairs;
uint32_t num_pairs;
};

 

trusted {

// This function declaration results in a shallow copy of the rel structure

public sgx_status_t ecall_sort_table([in] struct table_t * rel);

// This function declaration results in a deep copy of the rel structure

public sgx_status_t ecall_deep_sort_table([in, count = 1] struct deep_table_t * rel);
};

After compilation, check enclave_t.c to see the generated proxy functions. The function sgx_ecall_deep_sort_table shows the iterative deep copy of the structure from untrusted memory to trusted memory.

Additional information

Refer to the Structures, Enums, and Unions section in the Intel® SGX Developer Reference Guide for Linux* for a full explanation of how to achieve a deep copy of the structure elements into the trusted domain.

NoteThe most recent Intel® Software Guard Extensions (Intel® SGX) Developer Reference Guide for Linux* is in the Documentation section of the latest Intel® Software Guard Extensions Linux Release*.

The edger8 tool automatically generates the proxy functions that marshal data between the untrusted and trusted domains before the code is compiled. The count and size parameters in the EDL file tell the edger8 tool how much memory to copy in the proxy functions.

Related Products

This article applies to 1 products