Skip to content

Commit df9b032

Browse files
authored
Merge pull request #151 from yuyuany/ocall_exit_enclave
Check for crash in sgx_ocall and exit enclave if enclave is crashed. Signed-off-by: Zhang Lili [email protected]
2 parents a2f33d8 + a20449f commit df9b032

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

sdk/trts/linux/trts_pic.S

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ DECLARE_GLOBAL_FUNC enclave_entry
190190

191191
.cfi_endproc
192192

193+
DECLARE_GLOBAL_FUNC force_exit_enclave
194+
READ_TD_DATA last_sp
195+
sub $(2*SE_WORDSIZE), %xax
196+
mov %xax, %xbp
197+
mov $SGX_ERROR_ENCLAVE_CRASHED, %xbx
198+
jmp .Lexit_enclave
199+
193200
/*
194201
* -------------------------------------------------------------------------
195202
* sgx_status_t do_ocall(unsigned int index, void *ms);

sdk/trts/trts_ocall.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "xsave.h"
4040
#include "trts_internal.h"
4141

42+
extern "C" void force_exit_enclave();
4243
extern "C" sgx_status_t asm_oret(uintptr_t sp, void *ms);
4344
extern "C" sgx_status_t __morestack(const unsigned int index, void *ms);
4445
#define do_ocall __morestack
@@ -53,6 +54,10 @@ extern "C" sgx_status_t __morestack(const unsigned int index, void *ms);
5354
//
5455
sgx_status_t sgx_ocall(const unsigned int index, void *ms)
5556
{
57+
if(get_enclave_state() == ENCLAVE_CRASHED) {
58+
force_exit_enclave();
59+
}
60+
5661
// sgx_ocall is not allowed during exception handling
5762
thread_data_t *thread_data = get_thread_data();
5863

0 commit comments

Comments
 (0)