From 16d829cae4bc3edec7b7cbdc8cba5eb1c2a41bc2 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Mon, 20 May 2019 16:28:20 -0700 Subject: [PATCH] [Pal/Linux-SGX] Fix stack alignment for _DkExceptionHandler() and OCALLs --- Pal/src/host/Linux-SGX/enclave_entry.S | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Pal/src/host/Linux-SGX/enclave_entry.S b/Pal/src/host/Linux-SGX/enclave_entry.S index aa1be260..bdf78c6c 100644 --- a/Pal/src/host/Linux-SGX/enclave_entry.S +++ b/Pal/src/host/Linux-SGX/enclave_entry.S @@ -226,8 +226,12 @@ enclave_entry: # Pass pointer to sgx_context_t to _DkExceptionHandler movq %rsi, SGX_GPR_RSI(%rbx) - # Align the stack for _DkExceptionHandler + # x86-64 sysv abi requires 16B alignment of stack before call instruction + # which implies a (8 mod 16)B alignment on function entry (due to implicit + # push %rip). + # Align the stack for _DkExceptionHandler according to this requirement. andq $STACK_ALIGN, %rsi + subq $8, %rsi movq %rsi, SGX_GPR_RSP(%rbx) # clear rflags to conform the ABI which requires RFLAGS.DF = 0 @@ -396,7 +400,6 @@ sgx_ocall: # mode in-enclave memory can't be accessed. movq %gs:SGX_USTACK, %rsp - andq $STACK_ALIGN, %rsp #ifdef DEBUG # Push %rip of some code inside __morestack() on untrusted stack.