Skip to content

Commit

Permalink
SGX-Step v1.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
jovanbulck committed Oct 22, 2017
1 parent 65e05ab commit 4a2a8d1
Show file tree
Hide file tree
Showing 48 changed files with 3,659 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "linux-sgx"]
path = linux-sgx
url = https://github.com/01org/linux-sgx.git
[submodule "linux-sgx-driver"]
path = linux-sgx-driver
url = https://github.com/01org/linux-sgx-driver.git
151 changes: 151 additions & 0 deletions 0001-Support-to-reconfigure-Asynchronous-Exit-Pointer-AEP.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
From 11942c0b1244b28b8f1a2df0966c9fe08ca850de Mon Sep 17 00:00:00 2001
From: Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>
Date: Thu, 27 Jul 2017 21:02:10 +0200
Subject: [PATCH 1/2] Support to reconfigure Asynchronous Exit Pointer (AEP) at
runtime.

This provides a convenient way for an untrusted enclave execution environment
(OS + containing process) to determine whether or not the enclave has been
interrupted, and can be used to execute arbitrary code before ERESUME-ing a
previously interrupted enclave.
---
common/inc/sgx_urts.h | 3 +++
psw/urts/linux/enter_enclave.S | 31 +++++++++++++++++++++++++------
psw/urts/linux/urts.cpp | 14 ++++++++++++++
psw/urts/linux/urts.lds | 2 ++
sdk/simulation/urtssim/urts_deploy.c | 11 +++++++++++
5 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/common/inc/sgx_urts.h b/common/inc/sgx_urts.h
index f90a2d0..687e7e6 100644
--- a/common/inc/sgx_urts.h
+++ b/common/inc/sgx_urts.h
@@ -57,6 +57,9 @@ sgx_status_t SGXAPI sgx_create_enclave(const char *file_name, const int debug, s

sgx_status_t SGXAPI sgx_destroy_enclave(const sgx_enclave_id_t enclave_id);

+void* SGXAPI sgx_get_aep(void);
+void SGXAPI sgx_set_aep(void *aep);
+
#ifdef __cplusplus
}
#endif
diff --git a/psw/urts/linux/enter_enclave.S b/psw/urts/linux/enter_enclave.S
--- a/psw/urts/linux/enter_enclave.S
+++ b/psw/urts/linux/enter_enclave.S
@@ -32,6 +32,16 @@

#include "enter_enclave.h"

+/* XXX runtime reconfigurable indirect Asynchronous Exit Pointer (AEP)
+ * (ld complains when initializing __default_async_exit_pointer here, so we have
+ * to do it at runtime, when EENTERing, below in .Ldo_eenter.
+ */
+ .data
+g_aep_pointer:
+ .word 0x0
+ .word 0x0
+ .word 0x0
+ .word 0x0

/* int __morestack(const tcs_t *tcs, const int fn, const void *ocall_table, const void *ms, CTrustThread *trust_thread); */
.file "enter_enclave.S"
@@ -48,9 +58,15 @@ EENTER_PROLOG
mov frame_arg3, %xsi /* ms */

.Ldo_eenter:
- mov frame_arg0, %xbx /* tcs addr */
- lea_pic .Lasync_exit_pointer, %xcx /* aep addr */
- mov $SE_EENTER, %xax /* EENTER leaf */
+ mov frame_arg0, %xbx /* tcs addr */
+ /* fetch AEP; init when NULL */
+ lea_pic g_aep_pointer, %xax
+ mov (%xax), %xcx /* aep addr */
+ cmp $0x0, %xcx
+ jnz 1f
+ lea_pic __default_async_exit_pointer, %xcx
+ mov %xcx, (%xax)
+1: mov $SE_EENTER, %xax /* EENTER leaf */

.Leenter_inst:
ENCLU
@@ -107,14 +123,20 @@ EENTER_PROLOG
.Loret:
EENTER_EPILOG

-.Lasync_exit_pointer:
+__default_async_exit_pointer:
ENCLU

.size __morestack, .-__morestack


-DECLARE_GLOBAL_FUNC get_aep
- lea_pic .Lasync_exit_pointer, %xax
+ DECLARE_GLOBAL_FUNC get_aep
+ lea_pic g_aep_pointer, %xax
+ mov (%xax), %xax
+ ret
+
+DECLARE_GLOBAL_FUNC set_aep
+ lea_pic g_aep_pointer, %xax
+ mov naked_arg0, (%xax)
ret

DECLARE_GLOBAL_FUNC get_eenterp
diff --git a/psw/urts/linux/urts.cpp b/psw/urts/linux/urts.cpp
--- a/psw/urts/linux/urts.cpp
+++ b/psw/urts/linux/urts.cpp
@@ -70,3 +70,17 @@ extern "C" sgx_status_t sgx_create_enclave(const char *file_name, const int debu

return ret;
}
+
+//XXX
+extern "C" void *get_aep();
+extern "C" void set_aep(void *aep);
+
+extern "C" void* sgx_get_aep(void)
+{
+ return get_aep();
+}
+
+extern "C" void sgx_set_aep(void *aep)
+{
+ set_aep(aep);
+}
diff --git a/psw/urts/linux/urts.lds b/psw/urts/linux/urts.lds
--- a/psw/urts/linux/urts.lds
+++ b/psw/urts/linux/urts.lds
@@ -1,5 +1,7 @@
{
global:
+ sgx_get_aep;
+ sgx_set_aep;
sgx_create_enclave;
sgx_destroy_enclave;
sgx_ecall;
diff --git a/sdk/simulation/urtssim/urts_deploy.c b/sdk/simulation/urtssim/urts_deploy.c
--- a/sdk/simulation/urtssim/urts_deploy.c
+++ b/sdk/simulation/urtssim/urts_deploy.c
@@ -38,6 +38,17 @@ sgx_status_t sgx_create_enclave()
return SGX_ERROR_UNEXPECTED;
}

+void *sgx_get_aep(void)
+{
+ printf("Please use the correct uRTS library from PSW package.\n");
+ return NULL;
+}
+
+void sgx_set_aep(void* p)
+{
+ printf("Please use the correct uRTS library from PSW package.\n");
+}
+
void sgx_debug_load_state_add_element(){};
void sgx_debug_unload_state_remove_element(){};
void sgx_destroy_enclave(){};
--
2.5.0

128 changes: 128 additions & 0 deletions 0002-Add-support-to-retrieve-most-recently-used-TCS-point.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
From 1aa9fb129c350e5995227bc3854e86e714a5875f Mon Sep 17 00:00:00 2001
From: Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>
Date: Thu, 27 Jul 2017 21:26:44 +0200
Subject: [PATCH 2/2] Add support to retrieve most recently used TCS pointer.

---
common/inc/sgx_urts.h | 2 ++
psw/urts/linux/enter_enclave.S | 23 +++++++++++++++++++++++
psw/urts/linux/urts.cpp | 6 ++++++
psw/urts/linux/urts.lds | 1 +
sdk/simulation/urtssim/urts_deploy.c | 6 ++++++
5 files changed, 38 insertions(+)

diff --git a/common/inc/sgx_urts.h b/common/inc/sgx_urts.h
index 687e7e6..dc413a3 100644
--- a/common/inc/sgx_urts.h
+++ b/common/inc/sgx_urts.h
@@ -57,8 +57,10 @@ sgx_status_t SGXAPI sgx_create_enclave(const char *file_name, const int debug, s

sgx_status_t SGXAPI sgx_destroy_enclave(const sgx_enclave_id_t enclave_id);

+//XXX
void* SGXAPI sgx_get_aep(void);
void SGXAPI sgx_set_aep(void *aep);
+void* SGXAPI sgx_get_tcs(void);

#ifdef __cplusplus
}
diff --git a/psw/urts/linux/enter_enclave.S b/psw/urts/linux/enter_enclave.S
index df200db..85b64d2 100644
--- a/psw/urts/linux/enter_enclave.S
+++ b/psw/urts/linux/enter_enclave.S
@@ -43,6 +43,19 @@ g_aep_pointer:
.word 0x0
.word 0x0

+/* XXX HACK: SGX stores TCS address in rbx on interrupt, but this value is
+ * somehow not properly stored in Linux's pt_regs struct available to our
+ * driver's interrupt handler. We therefore store TCS address here in the
+ * untrusted runtime, so as to be able to explicitly communicate TCS to our
+ * driver...
+ */
+ .data
+g_tcs:
+ .word 0x0
+ .word 0x0
+ .word 0x0
+ .word 0x0
+
/* int __morestack(const tcs_t *tcs, const int fn, const void *ocall_table, const void *ms, CTrustThread *trust_thread); */
.file "enter_enclave.S"
.text
@@ -59,6 +72,8 @@ EENTER_PROLOG

.Ldo_eenter:
mov frame_arg0, %xbx /* tcs addr */
+ lea_pic g_tcs, %xax
+ mov %xbx, (%xax)
/* fetch AEP; init when NULL */
lea_pic g_aep_pointer, %xax
mov (%xax), %xcx /* aep addr */
@@ -139,6 +154,11 @@ DECLARE_GLOBAL_FUNC set_aep
mov naked_arg0, (%xax)
ret

+DECLARE_GLOBAL_FUNC get_tcs
+ lea_pic g_tcs, %xax
+ mov (%xax), %xax
+ ret
+
DECLARE_GLOBAL_FUNC get_eenterp
lea_pic .Leenter_inst, %xax
ret
diff --git a/psw/urts/linux/urts.cpp b/psw/urts/linux/urts.cpp
index 94e1861..f8cb379 100644
--- a/psw/urts/linux/urts.cpp
+++ b/psw/urts/linux/urts.cpp
@@ -74,12 +74,18 @@ extern "C" sgx_status_t sgx_create_enclave(const char *file_name, const int debu
//XXX
extern "C" void *get_aep();
extern "C" void set_aep(void *aep);
+extern "C" void *get_tcs();

extern "C" void* sgx_get_aep(void)
{
return get_aep();
}

+extern "C" void* sgx_get_tcs(void)
+{
+ return get_tcs();
+}
+
extern "C" void sgx_set_aep(void *aep)
{
set_aep(aep);
diff --git a/psw/urts/linux/urts.lds b/psw/urts/linux/urts.lds
index 3e02677..bad727e 100644
--- a/psw/urts/linux/urts.lds
+++ b/psw/urts/linux/urts.lds
@@ -2,6 +2,7 @@
global:
sgx_get_aep;
sgx_set_aep;
+ sgx_get_tcs;
sgx_create_enclave;
sgx_destroy_enclave;
sgx_ecall;
diff --git a/sdk/simulation/urtssim/urts_deploy.c b/sdk/simulation/urtssim/urts_deploy.c
index fbd021b..2f03531 100644
--- a/sdk/simulation/urtssim/urts_deploy.c
+++ b/sdk/simulation/urtssim/urts_deploy.c
@@ -49,6 +49,12 @@ void sgx_set_aep(void* p)
printf("Please use the correct uRTS library from PSW package.\n");
}

+void *sgx_get_tcs(void)
+{
+ printf("Please use the correct uRTS library from PSW package.\n");
+ return NULL;
+}
+
void sgx_debug_load_state_add_element(){};
void sgx_debug_unload_state_remove_element(){};
void sgx_destroy_enclave(){};
--
2.5.0

Loading

0 comments on commit 4a2a8d1

Please sign in to comment.