intel / intel/confidential-computing.sgx.sdk

Executing ecall can block enclave destruction.

Open
#2 5 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
2
Forks
3
PR merge metrics
No merged PRs in 30d

Description

If an ecall is executing it can block a call to sgx_destroy_enclave. sgx_destroy_enclave evenutally trys to obtain [this write lock](https://github.com/01org/linux-sgx/blob/master/psw/urts/enclave.cpp#L395) which is taken as a read lock on every ecall [here](https://github.com/01org/linux-sgx/blob/master/psw/urts/enclave.cpp#L395).

In an extreme example an ecall which executes a while loop, will deadlock any calls to sgx_destroy_enclave.

In the documentation sgx_destroy_enclave is listed to
> The sgx_destroy_enclave function destroys an enclave and frees its associated resources

but also
> The function will block until no other threads are executing inside the enclave.
>It is highly recommended that the sgx_destroy_enclave function be
called after the application has finished using the enclave to avoid possible
deadlocks

It seems like there should be a definitive way to terminate an enclave and reclaim all its resources with out process termination. I have been working on a way to do this using pthread_cancel to terminate any threads remaining in an enclave before a call to sgx_destroy_enclave but only using the high level calls documented in the Developer Reference or modifying the sdk I have no way to unlock the [readwrite lock](https://github.com/01org/linux-sgx/blob/master/psw/urts/enclave.cpp#L395).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.