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 first th<strong>in</strong>g MiCreate<strong>Enclave</strong> does is allocate the AWE <strong>in</strong>formation structure that Address Widow<strong>in</strong>g<br />

Extension APIs also utilize. This is because similar to the AWE functionality, an enclave allows a user-mode<br />

application to directly have access over physical pages (that is to say, the physical pages that are EPC pages<br />

based on the detection described earlier). Anytime a user-mode application has such direct control over<br />

physical pages, AWE data structures and locks must be used. This data structure is stored <strong>in</strong> the AweInfo<br />

field of EPROCESS.<br />

Next, MiCreate<strong>Enclave</strong> will call MiAllocate<strong>Enclave</strong>Vad. Aga<strong>in</strong>, this is not surpris<strong>in</strong>g for those familiar with<br />

W<strong>in</strong>dows memory management – all user-mode virtual memory allocations require the usage of a Virtual<br />

Address Descriptor, or VAD, to describe them.<br />

This type of VAD is a little different than the usual Short or Long VADs described <strong>in</strong> W<strong>in</strong>dows Internals – it<br />

additional conta<strong>in</strong>s a system PTE (whose use we’ll describe later) as well as the array of PFN entries that<br />

correspond to the underly<strong>in</strong>g EPC pages associated with the enclave (which, at this po<strong>in</strong>t, is empty). We<br />

call this VAD an MMVAD_ENCLAVE and surmise its data structure to be def<strong>in</strong>ed as follows:<br />

typedef struct _MMVAD_ENCLAVE<br />

{<br />

MMVAD_SHORT Core;<br />

PMMPTE SecsSystemPte;<br />

PMMPFN <strong>Enclave</strong>PfnArray;<br />

ULONGLONG <strong>Enclave</strong>PfnCount;<br />

struct<br />

{<br />

ULONG Initialized:1;<br />

ULONG Debuggable:1;<br />

};<br />

} MMVAD_ENCLAVE, *PMMVAD_ENCLAVE;<br />

Additionally, <strong>Enclave</strong> VADs are marked as VadAwe due to the reasons expla<strong>in</strong>ed above. However, a related<br />

bit <strong>in</strong> the MMVAD structure, u.VadFlags.<strong>Enclave</strong>, is also set, allow<strong>in</strong>g differentiation from “true” AWE<br />

memory. F<strong>in</strong>ally, as part of VAD allocation, this is where the user-mode address for the enclave memory<br />

will be chosen, which utilizes the same anonymous-memory ASLR improvements offered by W<strong>in</strong>dows 8.<br />

Next, MiCreate<strong>Enclave</strong> will check if an <strong>in</strong>itial commitment was specified, as per the API documentation.<br />

For now, let’s assume this isn’t the case – we’ll shortly see how to commit enclave memory and what the<br />

effects are.<br />

The last step of the memory manager’s role is to acquire an enclave page regardless of the enclave size or<br />

<strong>in</strong>itial commitment. This is because, as per <strong>Intel</strong>’s <strong>SGX</strong> documentation, all enclaves require at least a onepage<br />

“control structure” to be associated with them. MiGet<strong>Enclave</strong>Page is used to obta<strong>in</strong> the required<br />

allocation. This function simply scans the <strong>Enclave</strong> Page List that was described earlier, and extracts one<br />

page as needed.<br />

With the page returned, remember the system PTE we saw MiAllocate<strong>Enclave</strong>Vad allocate? That PTE will<br />

correspond to the system’s kernel virtual address that will map the enclave page that was just obta<strong>in</strong>ed.

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

Saved successfully!

Ooh no, something went wrong!