Skip to content

Commit 111a916

Browse files
Yusong-Gaolzha101
authored andcommitted
Fix sgx_create_enclave retry mechanism
Fix sgx_create_enclave retry mechanism when load_enclave just return SGX_ERROR_MEMORY_MAP_FAILURE. Deprecated the SGX_ERROR_MEMORY_MAP_CONFLICT. Make the retry mechanism compatible with new driver and urts. Signed-off-by: gaoyusong <a869920004@163.com>
1 parent 321a658 commit 111a916

File tree

14 files changed

+54
-5
lines changed

14 files changed

+54
-5
lines changed

Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/untrusted/sample.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ static sgx_errlist_t sgx_errlist[] = {
102102
"Can't open enclave file.",
103103
NULL
104104
},
105+
{
106+
SGX_ERROR_MEMORY_MAP_FAILURE,
107+
"Failed to reserve memory for the enclave.",
108+
NULL
109+
},
105110
};
106111

107112
/* Check error conditions for loading enclave */

SampleCode/Cxx11SGXDemo/App/App.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ static sgx_errlist_t sgx_errlist[] = {
132132
"The enclave is signed as product enclave, and can not be created as debuggable enclave.",
133133
NULL
134134
},
135+
{
136+
SGX_ERROR_MEMORY_MAP_FAILURE,
137+
"Failed to reserve memory for the enclave.",
138+
NULL
139+
},
135140
};
136141

137142
/* Check error conditions for loading enclave */

SampleCode/Cxx14SGXDemo/App/App.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ static sgx_errlist_t sgx_errlist[] = {
132132
"The enclave is signed as product enclave, and can not be created as debuggable enclave.",
133133
NULL
134134
},
135+
{
136+
SGX_ERROR_MEMORY_MAP_FAILURE,
137+
"Failed to reserve memory for the enclave.",
138+
NULL
139+
},
135140
};
136141

137142
/* Check error conditions for loading enclave */

SampleCode/PowerTransition/App/ErrorSupport.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static sgx_errlist_t sgx_errlist[] = {
5151
{SGX_ERROR_OUT_OF_EPC, "Out of EPC memory."},
5252
{SGX_ERROR_NO_DEVICE, "Invalid SGX device."},
5353
{SGX_ERROR_MEMORY_MAP_CONFLICT, "Memory map conflicted."},
54+
{SGX_ERROR_MEMORY_MAP_FAILURE, "Failed to reserve memory for the enclave."},
5455
{SGX_ERROR_INVALID_METADATA, "Invalid encalve metadata."},
5556
{SGX_ERROR_DEVICE_BUSY, "SGX device is busy."},
5657
{SGX_ERROR_INVALID_VERSION, "Enclave metadata version is invalid."},

SampleCode/ProtobufSGXDemo/App/App.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ static sgx_errlist_t sgx_errlist[] = {
132132
"The enclave is signed as product enclave, and can not be created as debuggable enclave.",
133133
NULL
134134
},
135+
{
136+
SGX_ERROR_MEMORY_MAP_FAILURE,
137+
"Failed to reserve memory for the enclave.",
138+
NULL
139+
},
135140
};
136141

137142
/* Check error conditions for loading enclave */

SampleCode/SampleDNNL/App/App.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ static sgx_errlist_t sgx_errlist[] = {
134134
"Can't open enclave file.",
135135
NULL
136136
},
137+
{
138+
SGX_ERROR_MEMORY_MAP_FAILURE,
139+
"Failed to reserve memory for the enclave.",
140+
NULL
141+
},
137142
};
138143

139144
/* Check error conditions for loading enclave */

SampleCode/SampleEnclave/App/App.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ static sgx_errlist_t sgx_errlist[] = {
128128
"Can't open enclave file.",
129129
NULL
130130
},
131+
{
132+
SGX_ERROR_MEMORY_MAP_FAILURE,
133+
"Failed to reserve memory for the enclave.",
134+
NULL
135+
},
131136
};
132137

133138
/* Check error conditions for loading enclave */

SampleCode/SampleEnclaveGMIPP/App/App.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ static sgx_errlist_t sgx_errlist[] = {
129129
"Can't open enclave file.",
130130
NULL
131131
},
132+
{
133+
SGX_ERROR_MEMORY_MAP_FAILURE,
134+
"Failed to reserve memory for the enclave.",
135+
NULL
136+
},
132137
};
133138

134139
/* Check error conditions for loading enclave */

SampleCode/SampleEnclavePCL/App/App.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ static sgx_errlist_t sgx_errlist[] = {
158158
"PCL sealed key GUID mismatch.",
159159
NULL
160160
},
161+
{
162+
SGX_ERROR_MEMORY_MAP_FAILURE,
163+
"Failed to reserve memory for the enclave.",
164+
NULL
165+
},
161166
};
162167

163168
/* Check error conditions for loading enclave */

SampleCode/SealUnseal/App/ErrorSupport.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static sgx_errlist_t sgx_errlist[] = {
5050
{SGX_ERROR_OUT_OF_EPC, "Out of EPC memory."},
5151
{SGX_ERROR_NO_DEVICE, "Invalid SGX device."},
5252
{SGX_ERROR_MEMORY_MAP_CONFLICT, "Memory map conflicted."},
53+
{SGX_ERROR_MEMORY_MAP_FAILURE, "Failed to reserve memory for the enclave."},
5354
{SGX_ERROR_INVALID_METADATA, "Invalid encalve metadata."},
5455
{SGX_ERROR_DEVICE_BUSY, "SGX device is busy."},
5556
{SGX_ERROR_INVALID_VERSION, "Enclave metadata version is invalid."},

SampleCode/Switchless/App/App.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ static sgx_errlist_t sgx_errlist[] = {
132132
"Can't open enclave file.",
133133
NULL
134134
},
135+
{
136+
SGX_ERROR_MEMORY_MAP_FAILURE,
137+
"Failed to reserve memory for the enclave.",
138+
NULL
139+
},
135140
};
136141

137142
/* Check error conditions for loading enclave */

common/inc/sgx_error.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ typedef enum _status_t
6161
SGX_ERROR_NDEBUG_ENCLAVE = SGX_MK_ERROR(0x2004), /* The enclave is signed as product enclave, and can not be created as debuggable enclave. */
6262
SGX_ERROR_OUT_OF_EPC = SGX_MK_ERROR(0x2005), /* Not enough EPC is available to load the enclave */
6363
SGX_ERROR_NO_DEVICE = SGX_MK_ERROR(0x2006), /* Can't open SGX device */
64-
SGX_ERROR_MEMORY_MAP_CONFLICT= SGX_MK_ERROR(0x2007), /* Page mapping failed in driver */
64+
SGX_ERROR_MEMORY_MAP_CONFLICT= SGX_MK_ERROR(0x2007), /* Page mapping failed in driver. Deprecated */
6565
SGX_ERROR_INVALID_METADATA = SGX_MK_ERROR(0x2009), /* The metadata is incorrect. */
6666
SGX_ERROR_DEVICE_BUSY = SGX_MK_ERROR(0x200c), /* Device is busy, mostly EINIT failed. */
6767
SGX_ERROR_INVALID_VERSION = SGX_MK_ERROR(0x200d), /* Metadata version is inconsistent between uRTS and sgx_sign or uRTS is incompatible with current platform. */

psw/ae/aesm_service/source/oal/linux/internal_log.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ static const char *get_sgx_status_t_string(sgx_status_t status)
468468
CASE_ENUM_RET_STRING(SGX_ERROR_OUT_OF_EPC)
469469
CASE_ENUM_RET_STRING(SGX_ERROR_NO_DEVICE)
470470
CASE_ENUM_RET_STRING(SGX_ERROR_MEMORY_MAP_CONFLICT)
471+
CASE_ENUM_RET_STRING(SGX_ERROR_MEMORY_MAP_FAILURE)
471472
CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_METADATA)
472473
CASE_ENUM_RET_STRING(SGX_ERROR_DEVICE_BUSY)
473474
CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_VERSION)

psw/urts/loader.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ int CLoader::load_enclave(SGXLaunchToken *lc, int debug, const metadata_t *metad
907907

908908
int CLoader::load_enclave_ex(SGXLaunchToken *lc, bool debug, const metadata_t *metadata, sgx_config_id_t *config_id, sgx_config_svn_t config_svn, le_prd_css_file_t *prd_css_file, sgx_misc_attribute_t *misc_attr)
909909
{
910-
unsigned int ret = SGX_SUCCESS, map_conflict_count = 3;
910+
unsigned int ret = SGX_SUCCESS, map_retry_count = 3;
911911
bool retry = true;
912912

913913
while (retry)
@@ -919,12 +919,13 @@ int CLoader::load_enclave_ex(SGXLaunchToken *lc, bool debug, const metadata_t *m
919919
case SGX_ERROR_ENCLAVE_LOST: //caused by loading enclave while power transition occurs
920920
break;
921921

922-
//If memroy map conflict occurs, we only retry 3 times.
922+
//If memory map fail or conflict occurs, we only retry 3 times.
923+
case SGX_ERROR_MEMORY_MAP_FAILURE:
923924
case SGX_ERROR_MEMORY_MAP_CONFLICT:
924-
if(0 == map_conflict_count)
925+
if (0 == map_retry_count)
925926
retry = false;
926927
else
927-
map_conflict_count--;
928+
map_retry_count--;
928929
break;
929930

930931
//We don't re-load enclave due to other error code.

0 commit comments

Comments
 (0)