|
| 1 | +From 11942c0b1244b28b8f1a2df0966c9fe08ca850de Mon Sep 17 00:00:00 2001 |
| 2 | +From: Jo Van Bulck < [email protected]> |
| 3 | +Date: Thu, 27 Jul 2017 21:02:10 +0200 |
| 4 | +Subject: [PATCH 1/2] Support to reconfigure Asynchronous Exit Pointer (AEP) at |
| 5 | + runtime. |
| 6 | + |
| 7 | +This provides a convenient way for an untrusted enclave execution environment |
| 8 | +(OS + containing process) to determine whether or not the enclave has been |
| 9 | +interrupted, and can be used to execute arbitrary code before ERESUME-ing a |
| 10 | +previously interrupted enclave. |
| 11 | +--- |
| 12 | + common/inc/sgx_urts.h | 3 +++ |
| 13 | + psw/urts/linux/enter_enclave.S | 31 +++++++++++++++++++++++++------ |
| 14 | + psw/urts/linux/urts.cpp | 14 ++++++++++++++ |
| 15 | + psw/urts/linux/urts.lds | 2 ++ |
| 16 | + sdk/simulation/urtssim/urts_deploy.c | 11 +++++++++++ |
| 17 | + 5 files changed, 55 insertions(+), 6 deletions(-) |
| 18 | + |
| 19 | +diff --git a/common/inc/sgx_urts.h b/common/inc/sgx_urts.h |
| 20 | +index f90a2d0..687e7e6 100644 |
| 21 | +--- a/common/inc/sgx_urts.h |
| 22 | ++++ b/common/inc/sgx_urts.h |
| 23 | +@@ -57,6 +57,9 @@ sgx_status_t SGXAPI sgx_create_enclave(const char *file_name, const int debug, s |
| 24 | + |
| 25 | + sgx_status_t SGXAPI sgx_destroy_enclave(const sgx_enclave_id_t enclave_id); |
| 26 | + |
| 27 | ++void* SGXAPI sgx_get_aep(void); |
| 28 | ++void SGXAPI sgx_set_aep(void *aep); |
| 29 | ++ |
| 30 | + #ifdef __cplusplus |
| 31 | + } |
| 32 | + #endif |
| 33 | +diff --git a/psw/urts/linux/enter_enclave.S b/psw/urts/linux/enter_enclave.S |
| 34 | +--- a/psw/urts/linux/enter_enclave.S |
| 35 | ++++ b/psw/urts/linux/enter_enclave.S |
| 36 | +@@ -32,6 +32,16 @@ |
| 37 | + |
| 38 | + #include "enter_enclave.h" |
| 39 | + |
| 40 | ++/* XXX runtime reconfigurable indirect Asynchronous Exit Pointer (AEP) |
| 41 | ++ * (ld complains when initializing __default_async_exit_pointer here, so we have |
| 42 | ++ * to do it at runtime, when EENTERing, below in .Ldo_eenter. |
| 43 | ++ */ |
| 44 | ++ .data |
| 45 | ++g_aep_pointer: |
| 46 | ++ .word 0x0 |
| 47 | ++ .word 0x0 |
| 48 | ++ .word 0x0 |
| 49 | ++ .word 0x0 |
| 50 | + |
| 51 | + /* int __morestack(const tcs_t *tcs, const int fn, const void *ocall_table, const void *ms, CTrustThread *trust_thread); */ |
| 52 | + .file "enter_enclave.S" |
| 53 | +@@ -48,9 +58,15 @@ EENTER_PROLOG |
| 54 | + mov frame_arg3, %xsi /* ms */ |
| 55 | + |
| 56 | + .Ldo_eenter: |
| 57 | +- mov frame_arg0, %xbx /* tcs addr */ |
| 58 | +- lea_pic .Lasync_exit_pointer, %xcx /* aep addr */ |
| 59 | +- mov $SE_EENTER, %xax /* EENTER leaf */ |
| 60 | ++ mov frame_arg0, %xbx /* tcs addr */ |
| 61 | ++ /* fetch AEP; init when NULL */ |
| 62 | ++ lea_pic g_aep_pointer, %xax |
| 63 | ++ mov (%xax), %xcx /* aep addr */ |
| 64 | ++ cmp $0x0, %xcx |
| 65 | ++ jnz 1f |
| 66 | ++ lea_pic __default_async_exit_pointer, %xcx |
| 67 | ++ mov %xcx, (%xax) |
| 68 | ++1: mov $SE_EENTER, %xax /* EENTER leaf */ |
| 69 | + |
| 70 | + .Leenter_inst: |
| 71 | + ENCLU |
| 72 | +@@ -107,14 +123,20 @@ EENTER_PROLOG |
| 73 | + .Loret: |
| 74 | + EENTER_EPILOG |
| 75 | + |
| 76 | +-.Lasync_exit_pointer: |
| 77 | ++__default_async_exit_pointer: |
| 78 | + ENCLU |
| 79 | + |
| 80 | + .size __morestack, .-__morestack |
| 81 | + |
| 82 | + |
| 83 | +-DECLARE_GLOBAL_FUNC get_aep |
| 84 | +- lea_pic .Lasync_exit_pointer, %xax |
| 85 | ++ DECLARE_GLOBAL_FUNC get_aep |
| 86 | ++ lea_pic g_aep_pointer, %xax |
| 87 | ++ mov (%xax), %xax |
| 88 | ++ ret |
| 89 | ++ |
| 90 | ++DECLARE_GLOBAL_FUNC set_aep |
| 91 | ++ lea_pic g_aep_pointer, %xax |
| 92 | ++ mov naked_arg0, (%xax) |
| 93 | + ret |
| 94 | + |
| 95 | + DECLARE_GLOBAL_FUNC get_eenterp |
| 96 | +diff --git a/psw/urts/linux/urts.cpp b/psw/urts/linux/urts.cpp |
| 97 | +--- a/psw/urts/linux/urts.cpp |
| 98 | ++++ b/psw/urts/linux/urts.cpp |
| 99 | +@@ -70,3 +70,17 @@ extern "C" sgx_status_t sgx_create_enclave(const char *file_name, const int debu |
| 100 | + |
| 101 | + return ret; |
| 102 | + } |
| 103 | ++ |
| 104 | ++//XXX |
| 105 | ++extern "C" void *get_aep(); |
| 106 | ++extern "C" void set_aep(void *aep); |
| 107 | ++ |
| 108 | ++extern "C" void* sgx_get_aep(void) |
| 109 | ++{ |
| 110 | ++ return get_aep(); |
| 111 | ++} |
| 112 | ++ |
| 113 | ++extern "C" void sgx_set_aep(void *aep) |
| 114 | ++{ |
| 115 | ++ set_aep(aep); |
| 116 | ++} |
| 117 | +diff --git a/psw/urts/linux/urts.lds b/psw/urts/linux/urts.lds |
| 118 | +--- a/psw/urts/linux/urts.lds |
| 119 | ++++ b/psw/urts/linux/urts.lds |
| 120 | +@@ -1,5 +1,7 @@ |
| 121 | + { |
| 122 | + global: |
| 123 | ++ sgx_get_aep; |
| 124 | ++ sgx_set_aep; |
| 125 | + sgx_create_enclave; |
| 126 | + sgx_destroy_enclave; |
| 127 | + sgx_ecall; |
| 128 | +diff --git a/sdk/simulation/urtssim/urts_deploy.c b/sdk/simulation/urtssim/urts_deploy.c |
| 129 | +--- a/sdk/simulation/urtssim/urts_deploy.c |
| 130 | ++++ b/sdk/simulation/urtssim/urts_deploy.c |
| 131 | +@@ -38,6 +38,17 @@ sgx_status_t sgx_create_enclave() |
| 132 | + return SGX_ERROR_UNEXPECTED; |
| 133 | + } |
| 134 | + |
| 135 | ++void *sgx_get_aep(void) |
| 136 | ++{ |
| 137 | ++ printf("Please use the correct uRTS library from PSW package.\n"); |
| 138 | ++ return NULL; |
| 139 | ++} |
| 140 | ++ |
| 141 | ++void sgx_set_aep(void* p) |
| 142 | ++{ |
| 143 | ++ printf("Please use the correct uRTS library from PSW package.\n"); |
| 144 | ++} |
| 145 | ++ |
| 146 | + void sgx_debug_load_state_add_element(){}; |
| 147 | + void sgx_debug_unload_state_remove_element(){}; |
| 148 | + void sgx_destroy_enclave(){}; |
| 149 | +-- |
| 150 | +2.5.0 |
| 151 | + |
0 commit comments