Skip to content

ECREATE

Henk-Jan Lebbink edited this page Jun 5, 2018 · 2 revisions

SGX INSTRUCTION REFERENCES ECREATE — Create an SECS page in the Enclave Page Cache

Opcode/ Instruction Op/En 64/32 bit Mode Support CPUID Feature Flag Description
EAX = 00H ENCLS[ECREATE] IR V/V SGX1 This leaf function begins an enclave build by creating an SECS page in EPC.

Instruction Operand Encoding

Op/En EAX RBX RCX
IR ECREATE (In) Address of a PAGEINFO (In) Address of the destination SECS page (In)

Description

ENCLS[ECREATE] is the first instruction executed in the enclave build process. ECREATE copies an SECS structure outside the EPC into an SECS page inside the EPC. The internal structure of SECS is not accessible to software.

ECREATE will set up fields in the protected SECS and mark the page as valid inside the EPC. ECREATE initializes or checks unused fields.

Software sets the following fields in the source structure: SECS:BASEADDR, SECS:SIZE in bytes, ATTRIBUTES, CONFIGID and CONFIGSVN. SECS:BASEADDR must be naturally aligned on an SECS.SIZE boundary. SECS.SIZE must be at least 2 pages (8192).

The source operand RBX contains an effective address of a PAGEINFO structure. PAGEINFO contains an effective address of a source SECS and an effective address of an SECINFO. The SECS field in PAGEINFO is not used.

The RCX register is the effective address of the destination SECS. It is an address of an empty slot in the EPC. The SECS structure must be page aligned. SECINFO flags must specify the page as an SECS page.

ECREATE Memory Parameter Semantics

PAGEINFO PAGEINFO.SRCPGE PAGEINFO.SECINFO EPCPAGE
Read access permitted by Non Enclave Read access permitted by Non Enclave Read access permitted by Non Enclave Write access permitted by Enclave

ECREATE will fault if the SECS target page is in use; already valid; outside the EPC. It will also fault if addresses are not aligned; unused PAGEINFO fields are not zero.

If the amount of space needed to store the SSA frame is greater than the amount specified in SECS.SSAFRAME- SIZE, a #GP(0) results. The amount of space needed for an SSA frame is computed based on DS:TMP_SECS.ATTRIBUTES.XFRM size. Details of computing the size can be found Section 41.7.

Concurrency Restrictions

Table 40-15. Base Concurrency Restrictions of ECREATE

Leaf Parameter Base Concurrency Restrictions
Access On Conflict SGX_CONFLICT VM Exit Qualification
ECREATE SECS [DS:RCX] Exclusive #GP EPC_PAGE_CONFLICT_EXCEPTION

40-28 Vol. 3D SGX INSTRUCTION REFERENCES

Table 40-16. Additional Concurrency Restrictions of ECREATE

Leaf Parameter Additional Concurrency Restrictions
vs. EACCEPT, EACCEPTCOPY, EMODPE, EMODPR, EMODT vs. EADD, EEXTEND, EINIT vs. ETRACK, ETRACKC
Access On Conflict Access On Conflict Access On Conflict
ECREATE SECS [DS:RCX] Concurrent Concurrent Concurrent

Operation

Temp Variables in ECREATE Operational Flow

<table>
	<tr>
		<td><b>Name</b></td>
		<td><b>Type</b></td>
		<td><b>Size (Bits)</b></td>
		<td><b>Description</b></td>
	</tr>
	<tr>
		<td>TMP_SRCPGE</td>
		<td>Effective Address</td>
		<td>32/64</td>
		<td>Effective address of the SECS source page.</td>
	</tr>
	<tr>
		<td>TMP_SECS</td>
		<td>Effective Address</td>
		<td>32/64</td>
		<td>Effective address of the SECS destination page.</td>
	</tr>
	<tr>
		<td>TMP_SECINFO</td>
		<td>Effective Address</td>
		<td>32/64</td>
		<td>Effective address of an SECINFO structure which contains security attributes of the SECS page to be added.</td>
	</tr>
	<tr>
		<td>TMP_XSIZE</td>
		<td>SSA Size</td>
		<td>64</td>
		<td>The size calculation of SSA frame.</td>
	</tr>
	<tr>
		<td>TMP_MISC_SIZE</td>
		<td>MISC Field Size</td>
		<td>64</td>
		<td>Size of the selected MISC field components.</td>
	</tr>
	<tr>
		<td>TMPUPDATEFIELD</td>
		<td>SHA256 Buffer</td>
		<td>512</td>
		<td>Buffer used to hold data being added to TMP_SECS.MRENCLAVE.</td>
	</tr>
</table>

IF (DS:RBX is not 32Byte Aligned)
    THEN #GP(0); FI;
IF (DS:RCX is not 4KByte Aligned)
    THEN #GP(0); FI;
IF (DS:RCX does not resolve within an EPC)
    THEN #PF(DS:RCX); FI;
TMP_SRCPGEDS:RBX.SRCPGE;
TMP_SECINFODS:RBX.SECINFO;
IF (DS:TMP_SRCPGE is not 4KByte aligned or DS:TMP_SECINFO is not 64Byte aligned)
    THEN #GP(0); FI;
IF (DS:RBX.LINADDR ! = 0 or DS:RBX.SECS0)
    THEN #GP(0); FI;
(* Check for misconfigured SECINFO flags*)
IF (DS:TMP_SECINFO reserved fields are not zero or DS:TMP_SECINFO.FLAGS.PTPT_SECS) 
    THEN #GP(0); FI;
TMP_SECSRCX;
IF (EPC entry in use) 
    THEN 
        IF (<<VMX non-root operation>> AND <<ENABLE_EPC_VIRTUALIZATION_EXTENSIONS>>)
            THEN
                VMCS.Exit_reasonSGX_CONFLICT;
                            Vol. 3D 40-29
SGX INSTRUCTION REFERENCES
                VMCS.Exit_qualification.codeEPC_PAGE_CONFLICT_EXCEPTION;
                VMCS.Exit_qualification.error0;
                VMCS.Guest-physical_address ← 
                    << translation of DS:TMP_SECS produced by paging >>;
                VMCS.Guest-linear_addressDS:TMP_SECS;
        
            Deliver VMEXIT;
 
            ELSE
                #GP(0);
        FI;
FI;
IF (EPC entry in use) 
    THEN #GP(0); FI;
IF (EPCM(DS:RCX).VALID = 1) 
    THEN #PF(DS:RCX); FI;
(* Copy 4KBytes from source page to EPC page*)
DS:RCX[32767:0] ← DS:TMP_SRCPGE[32767:0];
(* Check lower 2 bits of XFRM are set *)
IF ( ( DS:TMP_SECS.ATTRIBUTES.XFRM BitwiseAND 03H) ≠ 03H) 
    THEN #GP(0); FI;
IF (XFRM is illegal) 
    THEN #GP(0); FI;
(* Make sure that the SECS does not have any unsupported MISCSELECT options*)
IF ( !(CPUID.(EAX=12H, ECX=0):EBX[31:0] & DS:TMP_SECS.MISCSELECT[31:0]) )
    THEN
        EPCM(DS:TMP_SECS).EntryLock.Release();
        #GP(0);
FI;
( * Compute size of MISC area *)
TMP_MISC_SIZEcompute_misc_region_size();
(* Compute the size required to save state of the enclave on async exit, see Section 41.7.2.2*)
TMP_XSIZEcompute_xsave_size(DS:TMP_SECS.ATTRIBUTES.XFRM) + GPR_SIZE + TMP_MISC_SIZE;
(* Ensure that the declared area is large enough to hold XSAVE and GPR stat *)
IF ( DS:TMP_SECS.SSAFRAMESIZE*4096 < TMP_XSIZE) 
    THEN #GP(0); FI;
IF ( (DS:TMP_SECS.ATTRIBUTES.MODE64BIT = 1) and (DS:TMP_SECS.BASEADDR is not canonical) )
    THEN #GP(0); FI;
IF ( (DS:TMP_SECS.ATTRIBUTES.MODE64BIT = 0) and (DS:TMP_SECS.BASEADDR and 0FFFFFFFF00000000H) )
    THEN #GP(0); FI;
IF ( (DS:TMP_SECS.ATTRIBUTES.MODE64BIT = 0) and (DS:TMP_SECS.SIZE2 ^ (CPUID.(EAX=12H, ECX=0):.EDX[7:0]) ) )
    THEN #GP(0); FI;
IF ( (DS:TMP_SECS.ATTRIBUTES.MODE64BIT = 1) and (DS:TMP_SECS.SIZE2 ^ (CPUID.(EAX=12H, ECX=0):.EDX[15:8]) ) )
40-30 Vol. 3D
                            SGX INSTRUCTION REFERENCES
    THEN #GP(0); FI;
(* Enclave size must be at least 8192 bytes and must be power of 2 in bytes*)
IF (DS:TMP_SECS.SIZE < 8192 or popcnt(DS:TMP_SECS.SIZE) > 1) 
    THEN #GP(0); FI;
(* Ensure base address of an enclave is aligned on size*)
IF ( ( DS:TMP_SECS.BASEADDR and (DS:TMP_SECS.SIZE-1) ) )
    THEN #GP(0); FI;
(* Ensure the SECS does not have any unsupported attributes*)
IF ( DS:TMP_SECS.ATTRIBUTES and (~CR_SGX_ATTRIBUTES_MASK) )
    THEN #GP(0); FI;
IF ( DS:TMP_SECS reserved fields are not zero) 
    THEN #GP(0); FI;
(* Verify that CONFIGID/CONFIGSVN are not set with attribute *)
IF ( ((DS:TMP_SECS.CONFIGID0) or (DS:TMP_SECS.CONFIGSVN0)) AND (DS:TMP_SECS.ATTRIBUTES.KSS == 0 ))
    THEN #GP(0); FI;
Clear DS:TMP_SECS to Uninitialized;
DS:TMP_SECS.MRENCLAVESHA256INITIALIZE(DS:TMP_SECS.MRENCLAVE);
DS:TMP_SECS.ISVSVN0;
DS:TMP_SECS.ISVPRODID0;
(* Initialize hash updates etc*)
Initialize enclaves MRENCLAVE update counter;
(* AddECREATEstring and SECS fields to MRENCLAVE *)
TMPUPDATEFIELD[63:0] ← 0045544145524345H; // “ECREATE”
TMPUPDATEFIELD[95:64] ← DS:TMP_SECS.SSAFRAMESIZE;
TMPUPDATEFIELD[159:96] ← DS:TMP_SECS.SIZE;
TMPUPDATEFIELD[511:160] ← 0; 
DS:TMP_SECS.MRENCLAVESHA256UPDATE(DS:TMP_SECS.MRENCLAVE, TMPUPDATEFIELD)
INC enclaves MRENCLAVE update counter;
(* Set EID *)
DS:TMP_SECS.EIDLockedXAdd(CR_NEXT_EID, 1);
(* Initialize the virtual child count to zero *)
DS:TMP_SECS.VIRTCHILDCNT0;
(* Load ENCLAVECONTEXT with Address out of paging of SECS *)
<< store translation of DS:RCX produced by paging in SECS(DS:RCX).ENCLAVECONTEXT >>
(* Set the EPCM entry, first create SECS identifier and store the identifier in EPCM *)
EPCM(DS:TMP_SECS).PTPT_SECS;
EPCM(DS:TMP_SECS).ENCLAVEADDRESS0;
EPCM(DS:TMP_SECS).R0;
EPCM(DS:TMP_SECS).W0;
EPCM(DS:TMP_SECS).X0;
(* Set EPCM entry fields *)
                            Vol. 3D 40-31
SGX INSTRUCTION REFERENCES
EPCM(DS:RCX).BLOCKED0;
EPCM(DS:RCX).PENDING0;
EPCM(DS:RCX).MODIFIED0;
EPCM(DS:RCX).PR0;
EPCM(DS:RCX).VALID1;

Flags Affected

None

Protected Mode Exceptions

#GP(0) If a memory operand effective address is outside the DS segment limit. If a memory operand is not properly aligned. If the reserved fields are not zero. If PAGEINFO.SECS is not zero. If PAGEINFO.LINADDR is not zero. If the SECS destination is locked. If SECS.SSAFRAMESIZE is insufficient.

#PF(error code) If a page fault occurs in accessing memory operands. If the SECS destination is outside the EPC.

64-Bit Mode Exceptions

#GP(0) If a memory address is non-canonical form. If a memory operand is not properly aligned. If the reserved fields are not zero. If PAGEINFO.SECS is not zero. If PAGEINFO.LINADDR is not zero. If the SECS destination is locked. If SECS.SSAFRAMESIZE is insufficient.

#PF(error code) If a page fault occurs in accessing memory operands. If the SECS destination is outside the EPC.

40-32 Vol. 3D


Source: Intel® Architecture Software Developer's Manual (May 2018)
Generated: 5-6-2018

Clone this wiki locally