Skip to content

EACCEPTCOPY

Henk-Jan Lebbink edited this page Jan 28, 2019 · 3 revisions

EACCEPTCOPY — Initialize a Pending Page

Opcode/ Instruction Op/En 64/32 bit Mode Support CPUID Feature Flag Description
EAX = 07H ENCLU[EACCEPTCOPY] IR V/V SGX2 This leaf function initializes a dynamically allocated EPC page from another page in the EPC.

Instruction Operand Encoding

Op/En EAX RBX RCX RDX
IR EACCEPTCOPY (In) Return Error Code (Out) Address of a SECINFO (In) Address of the destina- tion EPC page (In) Address of the source EPC page (In)

Description

This leaf function copies the contents of an existing EPC page into an uninitialized EPC page (created by EAUG). After initialization, the instruction may also modify the access rights associated with the destination EPC page. This instruction leaf can only be executed when inside the enclave.

RBX contains the effective address of a SECINFO structure while RCX and RDX each contain the effective address of an EPC page. The table below provides additional information on the memory parameter of the EACCEPTCOPY leaf function.

EACCEPTCOPY Memory Parameter Semantics

SECINFO EPCPAGE (Destination) EPCPAGE (Source)
Read access permitted by Non Enclave Read/Write access permitted by Enclave Read access permitted by Enclave

The instruction faults if any of the following:

EACCEPTCOPY Faulting Conditions

The operands are not properly aligned. If security attributes of the SECINFO page make the page inaccessible.
The EPC page is locked by another thread. If security attributes of the source EPC page make the page inaccessible.
The EPC page is not valid. RBX does not contain an effective address in an EPC page in the running enclave.
SECINFO contains an invalid request. RCX/RDX does not contain an effective address of an EPC page in the running enclave.

The error codes are:

Table 40-57. EACCEPTCOPY Return Value in RAX

Error Code (see Table 40-4) Description
No Error EACCEPTCOPY successful.
SGX_PAGE_ATTRIBUTES_MISMATCH The attributes of the target EPC page do not match the expected values.

Concurrency Restrictions

Table 40-58. Base Concurrency Restrictions of EACCEPTCOPY

Leaf Parameter Base Concurrency Restrictions
Access On Conflict SGX_CONFLICT VM Exit Qualification
EACCEPTCOPY Target [DS:RCX] Concurrent
Source [DS:RDX] Concurrent
SECINFO [DS:RBX] Concurrent

Table 40-59. Additional Concurrency Restrictions of EACCEPTCOPY

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
EACCEPTCOPY Target [DS:RCX] Exclusive #GP Concurrent Concurrent
Source [DS:RDX] Concurrent Concurrent Concurrent
SECINFO [DS:RBX] Concurrent Concurrent Concurrent

Operation

Temp Variables in EACCEPTCOPY 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>SCRATCH_SECINFO</td>
		<td>SECINFO</td>
		<td>512</td>
		<td>Scratch storage for holding the contents of DS:RBX.</td>
	</tr>
</table>

IF (DS:RBX is not 64Byte Aligned)
    THEN #GP(0); FI;
IF ( (DS:RCX is not 4KByte Aligned) or (DS:RDX is not 4KByte Aligned) )
    THEN #GP(0); FI;
IF ((DS:RBX is not within CR_ELRANGE) or (DS:RCX is not within CR_ELRANGE) or (DS:RDX is not within CR_ELRANGE))
    THEN #GP(0); FI;
IF (DS:RBX does not resolve within an EPC) 
    THEN #PF(DS:RBX); FI;
IF (DS:RCX does not resolve within an EPC) 
    THEN #PF(DS:RCX); FI;
IF (DS:RDX does not resolve within an EPC) 
    THEN #PF(DS:RDX); FI;
IF ( (EPCM(DS:RBX &~FFFH).VALID = 0) or (EPCM(DS:RBX &~FFFH).R = 0) or (EPCM(DS:RBX &~FFFH).PENDING0) or 
    (EPCM(DS:RBX &~FFFH).MODIFIED0) or (EPCM(DS:RBX &~FFFH).BLOCKED0) or (EPCM(DS:RBX &~FFFH).PTPT_REG) or 
    (EPCM(DS:RBX &~FFFH).ENCLAVESECSCR_ACTIVE_SECS) or
    (EPCM(DS:RBX &~FFFH).ENCLAVEADDRESSDS:RBX) )
    THEN #PF(DS:RBX); FI;
(* Copy 64 bytes of contents *)
SCRATCH_SECINFODS:RBX;
(* Check for misconfigured SECINFO flags*)
IF ( (SCRATCH_SECINFO reserved fields are not zero ) or (SCRATCH_SECINFO.FLAGS.R=0) AND(SCRATCH_SECINFO.FLAGS.W0 ) or
    (SCRATCH_SECINFO.FLAGS.PT is not PT_REG) ) 
    THEN #GP(0); FI;
(* Check security attributes of the source EPC page *)
IF ( (EPCM(DS:RDX).VALID = 0) or (EPCM(DS:RCX).R = 0) or (EPCM(DS:RDX).PENDING0) or (EPCM(DS:RDX).MODIFIED0) or 
    (EPCM(DS:RDX).BLOCKED0) or (EPCM(DS:RDX).PTPT_REG) or (EPCM(DS:RDX).ENCLAVESECSCR_ACTIVE_SECS) or
    (EPCM(DS:RDX).ENCLAVEADDRESSDS:RDX))
    THEN #PF(DS:RDX); FI;
(* Check security attributes of the destination EPC page *)
IF ( (EPCM(DS:RCX).VALID = 0) or (EPCM(DS:RCX).PENDING1) or (EPCM(DS:RCX).MODIFIED0) or 
    (EPCM(DS:RDX).BLOCKED0) or (EPCM(DS:RCX).PTPT_REG) or (EPCM(DS:RCX).ENCLAVESECSCR_ACTIVE_SECS) )
    THEN 
        RFLAGS.ZF1;
        RAXSGX_PAGE_ATTRIBUTES_MISMATCH; 
        GOTO DONE;
FI;
(* Check the destination EPC page for concurrency *)
IF (destination EPC page in use ) 
    THEN #GP(0); FI;
(* Re-Check security attributes of the destination EPC page *)
IF ( (EPCM(DS:RCX).VALID = 0) or (EPCM(DS:RCX).PENDING1) or (EPCM(DS:RCX).MODIFIED0) or 
    (EPCM(DS:RCX).R1) or (EPCM(DS:RCX).W1) or (EPCM(DS:RCX).X0) or 
    (EPCM(DS:RCX).PTSCRATCH_SECINFO.FLAGS.PT) or (EPCM(DS:RCX).ENCLAVESECSCR_ACTIVE_SECS) or
    (EPCM(DS:RCX).ENCLAVEADDRESSDS:RCX))
    THEN 
        RFLAGS.ZF1;
        RAXSGX_PAGE_ATTRIBUTES_MISMATCH; 
        GOTO DONE;
FI;
(* Copy 4KBbytes form the source to destination EPC page*)
DS:RCX[32767:0] ← DS:RDX[32767:0];
(* Update EPCM permissions *)
EPCM(DS:RCX).RSCRATCH_SECINFO.FLAGS.R;
EPCM(DS:RCX).WSCRATCH_SECINFO.FLAGS.W;
EPCM(DS:RCX).XSCRATCH_SECINFO.FLAGS.X;
EPCM(DS:RCX).PENDING0;
RFLAGS.ZF0;
RAX0;
DONE:
RFLAGS.CF,PF,AF,OF,SF0;

Flags Affected

Sets ZF if page is not modifiable, otherwise cleared. Clears CF, PF, AF, OF, SF

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 a memory operand is locked.

#PF(error code) If a page fault occurs in accessing memory operands. If a memory operand is not an EPC page. If EPC page has incorrect page type or security attributes.

64-Bit Mode Exceptions

#GP(0) If a memory operand is non-canonical form. If a memory operand is not properly aligned. If a memory operand is locked.

#PF(error code) If a page fault occurs in accessing memory operands. If a memory operand is not an EPC page. If EPC page has incorrect page type or security attributes.


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

Clone this wiki locally