Enclave Lifecycle
The lifecycle of an enclave is managed by system software and is coupled with the management of EPC pages.
An enclave is created with the ECREATE command and transforms a free EPC page into the SECS by copying the contents of a non-EPC page into the EPC. Since the system software is in the threat model, the CPU validates the content and throws an error if the check fails. If all checks pass, any further SGX instructions issued will trust the validity of the SECS.
After ECREATE, the SECS is set to uninitialized. While the SECS is set to uninitialized, the system software can load the enclave data and code and create TCS and regular pages using the EADD instruction. This is also done by copying the contents of a non-EPC page to an EPC page. The system software selects a virtual address in ELRANGE that is mapped to an EPC page. Each EPC page is associated with access rights that can be specified and stored in the EPCM. Each EADD operation performed by the system software is validated by the CPU before the data is placed in an EPC page. Validation checks performed are, for example, that the targeted EPC page is not already assigned to another enclave, that the virtual address is in the ELRANGE, and that the SECS is not initialized.
EINIT is then called to initialize the SECS. After the SECS is initialized, the EADD instruction is disallowed for that particular enclave. Now the execution of the data begins.
To remove an enclave, the EREMOVE command is used. To release the SECS, all EPC pages linked to the enclave are referencing it in the EPCM and must be released first. However, before an EPC page can be released, the CPU checks that no processor is currently executing any of the code it contains.
Last updated