Skip to content

Commit bf99907

Browse files
henrywang8atfbdotcomlzha101
authored andcommitted
Do traditional Ocall if g_uswitchless_handle is uninitialized
Global object initialization (init_global_object) happens before g_uswitchless_handle is initialized (via sl_init_switchless). Some ctors invoke syscalls via switchless ocalls. This causes init_tswitchless_ocall_mngr to be invoked with sl_call_once prematurely, returning -1. Subsequent invokations will always return -1, such that switchless ocalls never happen. A simple solution is to fallback to traditional ocalls until g_uswitchless_handle has been initialized.
1 parent e7bbc15 commit bf99907

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

sdk/switchless/sgx_tswitchless/sgx_ocall_switchless.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ sgx_status_t sgx_ocall_switchless(const unsigned int index, void* ms)
8989
if (sgx_is_enclave_crashed())
9090
return SGX_ERROR_ENCLAVE_CRASHED;
9191

92+
/* Global object initialization (init_global_object) happens before
93+
* g_uswitchless_handle is initialized (via sl_init_switchless).
94+
* Some ctors invoke syscalls via switchless ocalls. This causes
95+
* init_tswitchless_ocall_mngr to be invoked with sl_call_once prematurely,
96+
* returning -1. Subsequent invokations will always return -1, such that
97+
* switchless ocalls never happen. A simple solution is to fallback to
98+
* traditional ocalls until g_uswitchless_handle has been initialized. */
99+
if (g_uswitchless_handle == NULL) {
100+
return sgx_ocall(index, ms);
101+
}
102+
92103
/* If Switchless SGX is not enabled at enclave creation, then switchless OCalls
93104
* fallback to the traditional OCalls */
94105
if (sl_call_once(&g_init_ocall_mngr_done, init_tswitchless_ocall_mngr, NULL))

0 commit comments

Comments
 (0)