Explorar o código

[Pal/Linux-SGX] Fix stack alignment for _DkExceptionHandler() and OCALLs

Isaku Yamahata %!s(int64=6) %!d(string=hai) anos
pai
achega
16d829cae4
Modificáronse 1 ficheiros con 5 adicións e 2 borrados
  1. 5 2
      Pal/src/host/Linux-SGX/enclave_entry.S

+ 5 - 2
Pal/src/host/Linux-SGX/enclave_entry.S

@@ -226,8 +226,12 @@ enclave_entry:
 	# Pass pointer to sgx_context_t to _DkExceptionHandler
 	# Pass pointer to sgx_context_t to _DkExceptionHandler
 	movq %rsi, SGX_GPR_RSI(%rbx)
 	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
 	andq $STACK_ALIGN, %rsi
+	subq $8, %rsi
 	movq %rsi, SGX_GPR_RSP(%rbx)
 	movq %rsi, SGX_GPR_RSP(%rbx)
 
 
 	# clear rflags to conform the ABI which requires RFLAGS.DF = 0
 	# 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.
 	# mode in-enclave memory can't be accessed.
 
 
 	movq %gs:SGX_USTACK, %rsp
 	movq %gs:SGX_USTACK, %rsp
-	andq $STACK_ALIGN, %rsp
 
 
 #ifdef DEBUG
 #ifdef DEBUG
 	# Push %rip of some code inside __morestack() on untrusted stack.
 	# Push %rip of some code inside __morestack() on untrusted stack.