Skip to content

Commit a20449f

Browse files
author
Yu Yuan
committed
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 <[email protected]>
1 parent a2f33d8 commit a20449f

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)