Skip to content

Commit 88c8bb6

Browse files
authored
Remove SGX uRTS dependency in quote verification library (#193)
* Remove sgx_urts dependency in QVL Signed-off-by: HongyanJiang <hongyan.jiang@intel.com>
1 parent 6cc9b32 commit 88c8bb6

File tree

3 files changed

+90
-18
lines changed

3 files changed

+90
-18
lines changed

QuoteVerification/dcap_quoteverify/inc/sgx_urts_wrapper.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ typedef sgx_status_t (SGXAPI *sgx_create_enclave_func_t)(const char* file_name,
7878
sgx_enclave_id_t* enclave_id,
7979
sgx_misc_attribute_t* misc_attr);
8080

81+
#define SGX_URTS_API_OCALL_PTHREAD_CREATE "pthread_create_ocall"
82+
#define SGX_URTS_API_OCALL_PTHREAD_TIMEOUT "pthread_wait_timeout_ocall"
83+
#define SGX_URTS_API_OCALL_PTHREAD_WAKEUP "pthread_wakeup_ocall"
84+
85+
typedef int (*pthread_create_ocall_func_t)(unsigned long long self);
86+
typedef int (*pthread_wait_timeout_ocall_func_t)(unsigned long long waiter, unsigned long long timeout);
87+
typedef int (*pthread_wakeup_ocall_func_t)(unsigned long long waiter);
88+
8189
#endif
8290

8391
#define SGX_URTS_API_DESTROY_ENCLAVE "sgx_destroy_enclave"
@@ -89,10 +97,9 @@ typedef sgx_status_t (SGXAPI *sgx_create_enclave_func_t)(const char* file_name,
8997
#define SGX_URTS_API_OCALL_SET_MULTIPLE_EVENT "sgx_thread_set_multiple_untrusted_events_ocall"
9098

9199

92-
93100
typedef sgx_status_t (SGXAPI* sgx_destroy_enclave_func_t)(const sgx_enclave_id_t enclave_id);
94101

95-
typedef sgx_status_t(SGXAPI* sgx_ecall_func_t)(const sgx_enclave_id_t eid, const int index, const void* ocall_table, void* ms);
102+
typedef sgx_status_t (SGXAPI* sgx_ecall_func_t)(const sgx_enclave_id_t eid, const int index, const void* ocall_table, void* ms);
96103

97104
typedef void (*sgx_oc_cpuidex_func_t)(int cpuinfo[4], int leaf, int subleaf);
98105

@@ -114,4 +121,3 @@ bool sgx_dcap_load_urts();
114121

115122
#endif /* !_SGX_URTS_WRAPPER_H_*/
116123

117-

QuoteVerification/dcap_quoteverify/linux/config.cpp

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ extern sgx_thread_wait_untrusted_event_ocall_func_t p_sgx_thread_wait_untrusted_
7272
extern sgx_thread_set_untrusted_event_ocall_func_t p_sgx_thread_set_untrusted_event_ocall;
7373
extern sgx_thread_setwait_untrusted_events_ocall_func_t p_sgx_thread_setwait_untrusted_events_ocall;
7474
extern sgx_thread_set_multiple_untrusted_events_ocall_func_t p_sgx_thread_set_multiple_untrusted_events_ocall;
75-
75+
extern pthread_create_ocall_func_t p_pthread_create_ocall;
76+
extern pthread_wait_timeout_ocall_func_t p_pthread_wait_timeout_ocall;
77+
extern pthread_wakeup_ocall_func_t p_pthread_wakeup_ocall_func;
7678

7779

7880
#ifndef MAX_PATH
@@ -252,7 +254,7 @@ bool sgx_dcap_load_urts()
252254

253255
if (g_urts_handle == NULL) {
254256
fputs(dlerror(), stderr);
255-
SE_TRACE(SE_TRACE_ERROR, "Couldn't find urts library: %s\n", SGX_URTS_LIB_FILE_NAME);
257+
SE_TRACE(SE_TRACE_DEBUG, "Couldn't find urts library: %s\n", SGX_URTS_LIB_FILE_NAME);
256258
break;
257259
}
258260

@@ -329,6 +331,32 @@ bool sgx_dcap_load_urts()
329331
break;
330332
}
331333

334+
//search for pthread_create_ocall symbol in urts library
335+
//
336+
p_pthread_create_ocall = (pthread_create_ocall_func_t)dlsym(g_urts_handle, SGX_URTS_API_OCALL_PTHREAD_CREATE);
337+
err = dlerror();
338+
if (p_pthread_create_ocall == NULL || err != NULL) {
339+
SE_TRACE(SE_TRACE_ERROR, "Couldn't locate %s in urts library %s.\n", SGX_URTS_API_OCALL_PTHREAD_CREATE, SGX_URTS_LIB_FILE_NAME);
340+
break;
341+
}
342+
343+
//search for pthread_wait_timeout_ocall symbol in urts library
344+
//
345+
p_pthread_wait_timeout_ocall = (pthread_wait_timeout_ocall_func_t)dlsym(g_urts_handle, SGX_URTS_API_OCALL_PTHREAD_TIMEOUT);
346+
err = dlerror();
347+
if (p_pthread_wait_timeout_ocall == NULL || err != NULL) {
348+
SE_TRACE(SE_TRACE_ERROR, "Couldn't locate %s in urts library %s.\n", SGX_URTS_API_OCALL_PTHREAD_TIMEOUT, SGX_URTS_LIB_FILE_NAME);
349+
break;
350+
}
351+
352+
//search for pthread_wakeup_ocall symbol in urts library
353+
//
354+
p_pthread_wakeup_ocall_func = (pthread_wakeup_ocall_func_t)dlsym(g_urts_handle, SGX_URTS_API_OCALL_PTHREAD_WAKEUP);
355+
err = dlerror();
356+
if (p_pthread_wakeup_ocall_func == NULL || err != NULL) {
357+
SE_TRACE(SE_TRACE_ERROR, "Couldn't locate %s in urts library %s.\n", SGX_URTS_API_OCALL_PTHREAD_WAKEUP, SGX_URTS_LIB_FILE_NAME);
358+
break;
359+
}
332360

333361
ret = true;
334362

@@ -435,6 +463,15 @@ __attribute__((destructor)) void _qv_global_destructor()
435463
if (p_sgx_thread_set_multiple_untrusted_events_ocall)
436464
p_sgx_thread_set_multiple_untrusted_events_ocall = NULL;
437465

466+
if (p_pthread_create_ocall)
467+
p_pthread_create_ocall = NULL;
468+
469+
if (p_pthread_wait_timeout_ocall)
470+
p_pthread_wait_timeout_ocall = NULL;
471+
472+
if (p_pthread_wakeup_ocall_func)
473+
p_pthread_wakeup_ocall_func = NULL;
474+
438475
if (g_urts_handle) {
439476
dlclose(g_urts_handle);
440477
g_urts_handle = NULL;

QuoteVerification/dcap_quoteverify/sgx_dcap_quoteverify.cpp

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,24 @@
3838
#include "sgx_dcap_pcs_com.h"
3939
#include "sgx_dcap_qv_internal.h"
4040
#include "sgx_qve_def.h"
41-
#ifndef _MSC_VER
42-
#include "linux/qve_u.h"
43-
#else //_MSC_VER
44-
#include "win/qve_u.h"
45-
#endif //_MSC_VER
4641
#include <stdlib.h>
4742
#include <stdio.h>
48-
#include <sgx_urts.h>
4943
#include "se_trace.h"
5044
#include "se_thread.h"
5145
#include "se_memcpy.h"
5246
#include "sgx_urts_wrapper.h"
5347

48+
#if defined(_MSC_VER)
49+
#include <tchar.h>
50+
#include "win/qve_u.h"
51+
bool get_qve_path(TCHAR *p_file_path, size_t buf_size);
52+
#else
53+
#include <limits.h>
54+
#include "linux/qve_u.h"
55+
#define MAX_PATH PATH_MAX
56+
bool get_qve_path(char *p_file_path, size_t buf_size);
57+
#endif
58+
5459

5560
sgx_create_enclave_func_t p_sgx_urts_create_enclave = NULL;
5661
sgx_destroy_enclave_func_t p_sgx_urts_destroy_enclave = NULL;
@@ -122,14 +127,38 @@ int sgx_thread_set_multiple_untrusted_events_ocall(const void **waiters, size_t
122127
}
123128

124129

125-
#if defined(_MSC_VER)
126-
#include <tchar.h>
127-
bool get_qve_path(TCHAR *p_file_path, size_t buf_size);
128-
#else
129-
#include <limits.h>
130-
#define MAX_PATH PATH_MAX
131-
bool get_qve_path(char *p_file_path, size_t buf_size);
130+
#ifdef __GNUC__
132131

132+
pthread_create_ocall_func_t p_pthread_create_ocall = NULL;
133+
pthread_wait_timeout_ocall_func_t p_pthread_wait_timeout_ocall = NULL;
134+
pthread_wakeup_ocall_func_t p_pthread_wakeup_ocall_func = NULL;
135+
136+
int pthread_create_ocall(unsigned long long self)
137+
{
138+
if (!sgx_dcap_load_urts()) {
139+
return SGX_ERROR_UNEXPECTED;
140+
}
141+
142+
return p_pthread_create_ocall(self);
143+
}
144+
145+
int pthread_wait_timeout_ocall(unsigned long long waiter, unsigned long long timeout)
146+
{
147+
if (!sgx_dcap_load_urts()) {
148+
return SGX_ERROR_UNEXPECTED;
149+
}
150+
151+
return p_pthread_wait_timeout_ocall(waiter, timeout);
152+
}
153+
154+
int pthread_wakeup_ocall(unsigned long long waiter)
155+
{
156+
if (!sgx_dcap_load_urts()) {
157+
return SGX_ERROR_UNEXPECTED;
158+
}
159+
160+
return p_pthread_wakeup_ocall_func(waiter);
161+
}
133162
#endif
134163

135164
struct QvE_status {

0 commit comments

Comments
 (0)