Intel® Software Guard Extensions (Intel® SGX)
Discussion board focused on hardware-based isolation and memory encryption to provide extended code protection in solutions.

SGX memory init

JohnDoe1
Beginner
938 Views

EADD is supposed to copy over the initial code/data.

Suppose the Heap Size is much larger than the EPC total size (<128MB).

How is the heap initialized during enclave creation? If there is an access to heap outside EPC, how is the uninitialized or zeroed out new heap page securely added to the enclave (esp. after EINIT?)

 

In other words, how a heap size in gigabytes is committed before EINIT?

0 Kudos
1 Solution
JesusG_Intel
Moderator
843 Views

Hello JohnDoe1,


All memory pages inside the enclave must be EADD’ed, including the heap. The heap is part of the enclave measurement also. To EADD a heap page, there must be a free Enclave Page Cache (EPC) page available. If a free page already exists, it is immediately used by EADD. If the EPC is already full, a currently in-use page is paged out and freed, then that now free page could be used for the heap page. This page is obviously in the EPC since it’s a newly freed page. In either case, you don’t have to page anything “in”. Then, when the actual EADD occurs, by definition, the page will already be present in the EPC - no paging required.

 

Following the code:

 

  1. First, the SGX signtool is what determines enclave layout. It places the layout information in the metadata. Here is where the heap is added and set to EADD only: manage_metadata#L775
  2. During enclave load, the untrusted Run-time System (uRTS) loader loops through the layout entries and adds appropriately: loader.cpp#L382
  3. Following the code down, each enclave page is added by calling the driver, which calls EADD: loader.cpp#L311


Sincerely,

Jesus G.

Intel Customer Support


View solution in original post

0 Kudos
5 Replies
JesusG_Intel
Moderator
903 Views

Hello JohnDoe1,


While your question sounds simple the answer is quite complex. A thorough answer can be found in SGX Explained, which details how enclave memory is initialized and paged, and much more. Start reading on page 58, section 5 SGX Programming Model.


Sincerely,

Jesus G.

Intel Customer Support


0 Kudos
JohnDoe1
Beginner
894 Views

Thanks. I've already been through that document. It describes the enclave creation but only goes so far to say that functions of EADD "load the initial code and data into the enclave". The document also provides details of paging out existing pages and paging them back in.

However I'm looking for details of how previously unvisited heap pages are paged in, on a first read. I'm looking for a specific piece of information as to how a multi-gigabyte heap is initialized before EINIT is called. I'm wondering as to whether EADD is called or not (any actual data transfer of empty heap area happens or not).

0 Kudos
JesusG_Intel
Moderator
861 Views

Hi JohnDoe1,


I am consulting my resources on your question. We appreciate your patience as we continue investigating. I will respond to you as soon as I have an answer.


Sincerely,

Jesus G.

Intel Customer Support


0 Kudos
JesusG_Intel
Moderator
844 Views

Hello JohnDoe1,


All memory pages inside the enclave must be EADD’ed, including the heap. The heap is part of the enclave measurement also. To EADD a heap page, there must be a free Enclave Page Cache (EPC) page available. If a free page already exists, it is immediately used by EADD. If the EPC is already full, a currently in-use page is paged out and freed, then that now free page could be used for the heap page. This page is obviously in the EPC since it’s a newly freed page. In either case, you don’t have to page anything “in”. Then, when the actual EADD occurs, by definition, the page will already be present in the EPC - no paging required.

 

Following the code:

 

  1. First, the SGX signtool is what determines enclave layout. It places the layout information in the metadata. Here is where the heap is added and set to EADD only: manage_metadata#L775
  2. During enclave load, the untrusted Run-time System (uRTS) loader loops through the layout entries and adds appropriately: loader.cpp#L382
  3. Following the code down, each enclave page is added by calling the driver, which calls EADD: loader.cpp#L311


Sincerely,

Jesus G.

Intel Customer Support


0 Kudos
JesusG_Intel
Moderator
817 Views

This thread has been marked as answered and Intel will no longer monitor this thread. If you want a response from Intel in a follow-up question, please open a new thread.


0 Kudos
Reply