Skip to content

Commit 4a2a8d1

Browse files
committed
SGX-Step v1.0 release.
1 parent 65e05ab commit 4a2a8d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3659
-0
lines changed

.gitmodules

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "linux-sgx"]
2+
path = linux-sgx
3+
url = https://github.com/01org/linux-sgx.git
4+
[submodule "linux-sgx-driver"]
5+
path = linux-sgx-driver
6+
url = https://github.com/01org/linux-sgx-driver.git
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
From 1aa9fb129c350e5995227bc3854e86e714a5875f Mon Sep 17 00:00:00 2001
2+
From: Jo Van Bulck <[email protected]>
3+
Date: Thu, 27 Jul 2017 21:26:44 +0200
4+
Subject: [PATCH 2/2] Add support to retrieve most recently used TCS pointer.
5+
6+
---
7+
common/inc/sgx_urts.h | 2 ++
8+
psw/urts/linux/enter_enclave.S | 23 +++++++++++++++++++++++
9+
psw/urts/linux/urts.cpp | 6 ++++++
10+
psw/urts/linux/urts.lds | 1 +
11+
sdk/simulation/urtssim/urts_deploy.c | 6 ++++++
12+
5 files changed, 38 insertions(+)
13+
14+
diff --git a/common/inc/sgx_urts.h b/common/inc/sgx_urts.h
15+
index 687e7e6..dc413a3 100644
16+
--- a/common/inc/sgx_urts.h
17+
+++ b/common/inc/sgx_urts.h
18+
@@ -57,8 +57,10 @@ sgx_status_t SGXAPI sgx_create_enclave(const char *file_name, const int debug, s
19+
20+
sgx_status_t SGXAPI sgx_destroy_enclave(const sgx_enclave_id_t enclave_id);
21+
22+
+//XXX
23+
void* SGXAPI sgx_get_aep(void);
24+
void SGXAPI sgx_set_aep(void *aep);
25+
+void* SGXAPI sgx_get_tcs(void);
26+
27+
#ifdef __cplusplus
28+
}
29+
diff --git a/psw/urts/linux/enter_enclave.S b/psw/urts/linux/enter_enclave.S
30+
index df200db..85b64d2 100644
31+
--- a/psw/urts/linux/enter_enclave.S
32+
+++ b/psw/urts/linux/enter_enclave.S
33+
@@ -43,6 +43,19 @@ g_aep_pointer:
34+
.word 0x0
35+
.word 0x0
36+
37+
+/* XXX HACK: SGX stores TCS address in rbx on interrupt, but this value is
38+
+ * somehow not properly stored in Linux's pt_regs struct available to our
39+
+ * driver's interrupt handler. We therefore store TCS address here in the
40+
+ * untrusted runtime, so as to be able to explicitly communicate TCS to our
41+
+ * driver...
42+
+ */
43+
+ .data
44+
+g_tcs:
45+
+ .word 0x0
46+
+ .word 0x0
47+
+ .word 0x0
48+
+ .word 0x0
49+
+
50+
/* int __morestack(const tcs_t *tcs, const int fn, const void *ocall_table, const void *ms, CTrustThread *trust_thread); */
51+
.file "enter_enclave.S"
52+
.text
53+
@@ -59,6 +72,8 @@ EENTER_PROLOG
54+
55+
.Ldo_eenter:
56+
mov frame_arg0, %xbx /* tcs addr */
57+
+ lea_pic g_tcs, %xax
58+
+ mov %xbx, (%xax)
59+
/* fetch AEP; init when NULL */
60+
lea_pic g_aep_pointer, %xax
61+
mov (%xax), %xcx /* aep addr */
62+
@@ -139,6 +154,11 @@ DECLARE_GLOBAL_FUNC set_aep
63+
mov naked_arg0, (%xax)
64+
ret
65+
66+
+DECLARE_GLOBAL_FUNC get_tcs
67+
+ lea_pic g_tcs, %xax
68+
+ mov (%xax), %xax
69+
+ ret
70+
+
71+
DECLARE_GLOBAL_FUNC get_eenterp
72+
lea_pic .Leenter_inst, %xax
73+
ret
74+
diff --git a/psw/urts/linux/urts.cpp b/psw/urts/linux/urts.cpp
75+
index 94e1861..f8cb379 100644
76+
--- a/psw/urts/linux/urts.cpp
77+
+++ b/psw/urts/linux/urts.cpp
78+
@@ -74,12 +74,18 @@ extern "C" sgx_status_t sgx_create_enclave(const char *file_name, const int debu
79+
//XXX
80+
extern "C" void *get_aep();
81+
extern "C" void set_aep(void *aep);
82+
+extern "C" void *get_tcs();
83+
84+
extern "C" void* sgx_get_aep(void)
85+
{
86+
return get_aep();
87+
}
88+
89+
+extern "C" void* sgx_get_tcs(void)
90+
+{
91+
+ return get_tcs();
92+
+}
93+
+
94+
extern "C" void sgx_set_aep(void *aep)
95+
{
96+
set_aep(aep);
97+
diff --git a/psw/urts/linux/urts.lds b/psw/urts/linux/urts.lds
98+
index 3e02677..bad727e 100644
99+
--- a/psw/urts/linux/urts.lds
100+
+++ b/psw/urts/linux/urts.lds
101+
@@ -2,6 +2,7 @@
102+
global:
103+
sgx_get_aep;
104+
sgx_set_aep;
105+
+ sgx_get_tcs;
106+
sgx_create_enclave;
107+
sgx_destroy_enclave;
108+
sgx_ecall;
109+
diff --git a/sdk/simulation/urtssim/urts_deploy.c b/sdk/simulation/urtssim/urts_deploy.c
110+
index fbd021b..2f03531 100644
111+
--- a/sdk/simulation/urtssim/urts_deploy.c
112+
+++ b/sdk/simulation/urtssim/urts_deploy.c
113+
@@ -49,6 +49,12 @@ void sgx_set_aep(void* p)
114+
printf("Please use the correct uRTS library from PSW package.\n");
115+
}
116+
117+
+void *sgx_get_tcs(void)
118+
+{
119+
+ printf("Please use the correct uRTS library from PSW package.\n");
120+
+ return NULL;
121+
+}
122+
+
123+
void sgx_debug_load_state_add_element(){};
124+
void sgx_debug_unload_state_remove_element(){};
125+
void sgx_destroy_enclave(){};
126+
--
127+
2.5.0
128+

0 commit comments

Comments
 (0)