Skip to content

Conversation

haitaohuang
Copy link
Contributor

This implementation includes:

  1. the reusable Enclave Memory Manager as proposed previously on OE PR: Add SGX Enclave Memory Manager openenclave/openenclave#3991
  2. modifications for the Enclave Common Loader to support both the new kernel EDMM interfaces and legacy out-of-tree driver
  3. integration and tests with Intel SDK and PSW runtime support.
    Please refer to sdk/emm/README.md for a quick guide on build and test as well as a summary of current limitations:

lzha101 and others added 4 commits October 18, 2021 08:31
Signed-off-by: Zhang Lili <lili.z.zhang@intel.com>
Signed-off-by: Haitao Huang <4699115+haitaohuang@users.noreply.github.com>
This avoids a 3-way deadlock for later EMM implementation.

The utility thread is inside enclave setting up TCS, waiting on mm_lock to commit SSA, etc.

Another thread #PF inside sgx_mm functions with mm_lock held, trigger vDSO user handler
which tries to get back into enclave via Enclave::ecall,  which calls acquire_thread
trying to get the m_thread_mutex of CThreadPool

A newly created pthread making ecall also tries to acquire_thread holding the
CThreadPool::m_thread_mutex will wait for the utility thread to finish allocating TCS.

For user handler already has the TCS for current thread, directly use it to enter enclave.

Signed-off-by: Haitao Huang <4699115+haitaohuang@users.noreply.github.com>
Add a runtime agnostic enclave memory manager implementation in sdk/emm.
The EMM APIs are based on design proposed in this PR: openenclave/openenclave#3991

Enclave common loader changes are in psw/enclave_common/sgx_mm_ocalls.cpp, which are basically
OCall support needed for EMM.

Intel SDK runtime specific support are implemented as runtime abstraction layer: sdk/trts/ema_rt.c

Current limitations, steps to build and test are documented in sdk/emm/README.md

Signed-off-by: Haitao Huang <4699115+haitaohuang@users.noreply.github.com>
Signed-off-by: Xiaofeng Xu <20158212+xxu36@users.noreply.github.com>
@johnvenn
Copy link

Another concern is about the dealloc function, in this case:
alloced area 4pages, then mistakenly dealloc 2 pages, the ema node will be split, but we don't know the new addr and size of the new node. looks like user need to track what is allocated/deallocated when the enclave is running. This might be a problem.

@johnvenn
Copy link

per my understanding, the ema node should only exist during the enclave's lifetime, i.e., created/intiliazed on enclave initialization, and released on enclave_destroy, check the code, is there anywhere "destory_ema_root" invoked when enclave is destoryed?

@haitaohuang
Copy link
Contributor Author

Another concern is about the dealloc function, in this case: alloced area 4pages, then mistakenly dealloc 2 pages, the ema node will be split, but we don't know the new addr and size of the new node. looks like user need to track what is allocated/deallocated when the enclave is running. This might be a problem.

It's similar to how mmap works, if user does not track and remove, EMAs(like VMAs) will be kept until enclave dies (like process dies).

Signed-off-by: Haitao Huang <4699115+haitaohuang@users.noreply.github.com>
The ioctl numbers for EDMM functions are shifted in upstream patches:
https://patchwork.kernel.org/project/intel-sgx/cover/cover.1638381245.git.reinette.chatre@intel.com/
Change those definitions accordingly in isgx_user.h

Signed-off-by: Haitao Huang <4699115+haitaohuang@users.noreply.github.com>
Signed-off-by: Haitao Huang <4699115+haitaohuang@users.noreply.github.com>
@haitaohuang
Copy link
Contributor Author

haitaohuang commented Feb 11, 2022

Kernel patch updated to v2: https://github.com/rchatre/linux/tree/sgx/sgx2_submitted_v2_plus_rwx
Please use branch edmm_v2 in this repo for testing.
Closing this PR and create a new one for v2: #794

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants