Sfoglia il codice sorgente

tRTS check the enclave crash state when doing an OCALL. If the enclave is crashed, tRTS unwind the stack to ECALL, and exit the enclave with SGX_ERROR_ENCLAVE_CRASHED.

Signed-off-by: Yu Yuan <yuan.yu@intel.com>
Yu Yuan 8 anni fa
parent
commit
a20449f5f8
2 ha cambiato i file con 12 aggiunte e 0 eliminazioni
  1. 7 0
      sdk/trts/linux/trts_pic.S
  2. 5 0
      sdk/trts/trts_ocall.cpp

+ 7 - 0
sdk/trts/linux/trts_pic.S

@@ -190,6 +190,13 @@ DECLARE_GLOBAL_FUNC enclave_entry
     
     .cfi_endproc
 
+DECLARE_GLOBAL_FUNC force_exit_enclave
+    READ_TD_DATA last_sp
+    sub     $(2*SE_WORDSIZE), %xax
+    mov     %xax, %xbp
+    mov     $SGX_ERROR_ENCLAVE_CRASHED, %xbx
+    jmp     .Lexit_enclave
+
 /* 
  * -------------------------------------------------------------------------
  *  sgx_status_t do_ocall(unsigned int index, void *ms);

+ 5 - 0
sdk/trts/trts_ocall.cpp

@@ -39,6 +39,7 @@
 #include "xsave.h"
 #include "trts_internal.h"
 
+extern "C" void force_exit_enclave();
 extern "C" sgx_status_t asm_oret(uintptr_t sp, void *ms);
 extern "C" sgx_status_t __morestack(const unsigned int index, void *ms);
 #define do_ocall __morestack
@@ -53,6 +54,10 @@ extern "C" sgx_status_t __morestack(const unsigned int index, void *ms);
 //
 sgx_status_t sgx_ocall(const unsigned int index, void *ms)
 {
+    if(get_enclave_state() == ENCLAVE_CRASHED) {
+        force_exit_enclave();
+    }
+
     // sgx_ocall is not allowed during exception handling
     thread_data_t *thread_data = get_thread_data();