Skip to content

Commit

Permalink
Merge pull request #151 from yuyuany/ocall_exit_enclave
Browse files Browse the repository at this point in the history
Check for crash in sgx_ocall and exit enclave if enclave is crashed.

Signed-off-by: Zhang Lili [email protected]
  • Loading branch information
lzha101 authored Sep 5, 2017
2 parents a2f33d8 + a20449f commit df9b032
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sdk/trts/linux/trts_pic.S
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions sdk/trts/trts_ocall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();

Expand Down

0 comments on commit df9b032

Please sign in to comment.