Skip to content

Commit 4887b30

Browse files
henrywang8atfbdotcomlzha101
authored andcommitted
Fix pthread_self for untrusted threads that Ecall
Only threads created inside Enclave have pthread_info_tls.m_pthread set. If some untrusted thread does Ecall and then pthread_self() within Enclave, it will return NULL. This errorneous return value ends up causing thread synchronization errors inside the Enclave.
1 parent ced74d6 commit 4887b30

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sdk/pthread/pthread.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,12 @@ int pthread_join(pthread_t thread, void **retval)
364364
*/
365365
pthread_t pthread_self(void)
366366
{
367-
return (pthread_t)(pthread_info_tls.m_pthread);
367+
pthread_t t = (pthread_t)(pthread_info_tls.m_pthread);
368+
// For threads that are created outside enclave t value is NULL
369+
if (!t) {
370+
return (pthread_t)(sgx_thread_self());
371+
}
372+
return t;
368373
}
369374

370375
/*

0 commit comments

Comments
 (0)