From 7276bb9d78f2fd731a3bd0be6ccd2e13f731969e Mon Sep 17 00:00:00 2001 From: Simon Gaiser Date: Thu, 27 Jun 2019 20:02:25 +0200 Subject: [PATCH] [Pal/Linux-SGX] Correctly clear registers in enclave_entry.S Tiny bug fixes in enclave_entry.S to clear registers: - Do not clear %r11 twice before EEXIT - Simulate CLD (by manually clearing DF flag stored in SGX_GPR_RFLAGS) on interrupt just after EENTER returning from ocall - Simulate CLD (by manually clearing DF flag stored in SGX_GPR_RFLAGS) on preparation for exception handler _DkExceptionHandler() --- Pal/src/host/Linux-SGX/enclave_entry.S | 6 +++--- Pal/src/host/Linux-SGX/sgx_arch.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Pal/src/host/Linux-SGX/enclave_entry.S b/Pal/src/host/Linux-SGX/enclave_entry.S index 856df04f..0c8dad2b 100644 --- a/Pal/src/host/Linux-SGX/enclave_entry.S +++ b/Pal/src/host/Linux-SGX/enclave_entry.S @@ -282,7 +282,7 @@ enclave_entry: movq %rsi, SGX_GPR_RSP(%rbx) movq $0, %gs:SGX_STACK movq $0, %gs:SGX_OCALL_PREPARED - xorq %r11, %r11 + andq $(~RFLAGS_DF), SGX_GPR_RFLAGS(%rbx) jmp .Leexit_exception .Lsetup_exception_handler: @@ -365,8 +365,8 @@ enclave_entry: subq $8, %rsi movq %rsi, SGX_GPR_RSP(%rbx) - # clear rflags to conform the ABI which requires RFLAGS.DF = 0 - movq $0, SGX_GPR_RFLAGS(%rbx) + # Clear RFLAGS.DF to conform to the SysV ABI. + andq $(~RFLAGS_DF), SGX_GPR_RFLAGS(%rbx) # new RIP is the exception handler leaq _DkExceptionHandler(%rip), %rdi diff --git a/Pal/src/host/Linux-SGX/sgx_arch.h b/Pal/src/host/Linux-SGX/sgx_arch.h index e41f1e40..805ad6d0 100644 --- a/Pal/src/host/Linux-SGX/sgx_arch.h +++ b/Pal/src/host/Linux-SGX/sgx_arch.h @@ -288,4 +288,6 @@ typedef uint8_t sgx_arch_key128_t[16] __attribute__((aligned(16))); #define RETURN_FROM_OCALL 0xffffffffffffffff +#define RFLAGS_DF (1<<10) + #endif /* SGX_ARCH_H */