30.12.2015 Views

Intel SGX Enclave Support in Windows 10 Fall Update (Threshold 2)

1ks6upt

1ks6upt

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The user-mode API does noth<strong>in</strong>g but convert this to the follow<strong>in</strong>g system call:<br />

_Must_<strong>in</strong>spect_result_<br />

NTSYSAPI<br />

NTSTATUS<br />

NTAPI<br />

NtLoad<strong>Enclave</strong>Data (<br />

_In_ HANDLE ProcessHandle,<br />

_In_ PVOID BaseAddress,<br />

_In_reads_bytes_(BufferSize)<br />

CONST VOID *Buffer,<br />

_In_ SIZE_T BufferSize,<br />

_In_ ULONG Protect,<br />

_In_reads_bytes_(PageInformationLength)<br />

CONST VOID *PageInformation,<br />

_In_ ULONG PageInformationLength,<br />

_Out_opt_ PSIZE_T NumberOfBytesWritten,<br />

_Out_opt_ PULONG <strong>Enclave</strong>Error<br />

);<br />

Most of the parameters here should be self-document<strong>in</strong>g. In many ways, this is a comb<strong>in</strong>ation of a<br />

memcpy call with some VirtualAlloc attributes. The second parameter here refers to an address <strong>in</strong>side the<br />

enclave, while the third is a regular buffer that’s <strong>in</strong>side normal address space. Note that the size, <strong>in</strong> the<br />

fourth parameter, must be a page-multiple.<br />

Next, the firth parameter refers to page protection attributes, which accepts the usual PAGE_XXX<br />

attributes from VirtualAlloc. It also, however, accepts PAGE_ENCLAVE_THREAD_CONTROL, which<br />

<strong>in</strong>dicates that the memory is the TCS structure documented <strong>in</strong> the <strong>Intel</strong> <strong>SGX</strong> manual, as well as the<br />

PAGE_ENCLAVE_UNVALIDATED attribute, which <strong>in</strong>dicates that the data <strong>in</strong>side this memory block should<br />

not be measured by the EEXTEND leaf function that <strong>SGX</strong> offers (<strong>SGX</strong> offers its own embedded TPM). The<br />

next two parameters regard<strong>in</strong>g page <strong>in</strong>formation are actually not used for <strong>SGX</strong> purposes, and the f<strong>in</strong>al<br />

two should be self-descriptive.<br />

NtLoad<strong>Enclave</strong>Data will validate the parameters based on MSDN documentation, such as check<strong>in</strong>g the<br />

page alignment of the buffers and their sizes, as well as reject usage of the PageInformation<br />

parameters, which are not currently used. It will then obta<strong>in</strong> a po<strong>in</strong>ter to the EPROCESS object for the<br />

handle, and f<strong>in</strong>ally call MiCopyPagesInto<strong>Enclave</strong>, which will actually perform all of the work.<br />

Before we go <strong>in</strong>to those details, however, it’s important to note that the target enclave address must have<br />

actually been committed first. Recall from the previous discussion that unless the<br />

dwInitialCommitment passed <strong>in</strong> to Create<strong>Enclave</strong> was non-zero, the VAD currently merely describes a<br />

reserved, but not yet committed range. In order to be able to store enclave data <strong>in</strong>to the range, it must<br />

first have been committed, by one of the two mechanisms we’ve already seen.<br />

We return our analysis to MiCopyPagesInto<strong>Enclave</strong>, which provides the bulk implementation of the<br />

NtLoad<strong>Enclave</strong>Data system call that provides the Load<strong>Enclave</strong>Data W<strong>in</strong>32 API backend. The <strong>in</strong>itial work

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!