[Pal/Linux-SGX] Save/restore callee-saved regs on sgx_{ecall,raise}

The EEXIT instruction does not restore registers of untrusted part of
the program. Thus, sgx_ecall() and sgx_raise() functions must save
callee-saved regs before EENTER and restore them after EEXIT. This
fixes the bug of a build with DEBUG=0 when the untrusted part of the
program uses RBP and other regs (in contrast to undefined DEBUG when
these registers are optimized away from the untrusted part).
This commit is contained in:
Isaku Yamahata
2020-02-11 20:33:46 -08:00
committed by Dmitrii Kuvaiskii
parent 4182c29476
commit 4bcf3a6287
+17 -8
View File
@@ -9,13 +9,19 @@
.type sgx_ecall, @function
sgx_ecall:
pushq %rbx
# put entry address in RDX
leaq sgx_entry(%rip), %rdx
leaq .Lsgx_entry(%rip), %rdx
# other arguments: RDI - code, RSI - ms
.Ldo_ecall_callee_save:
pushq %rbx
pushq %rbp
pushq %r12
pushq %r13
pushq %r14
pushq %r15
.Ldo_ecall:
# RBX has to be the TCS of the thread
movq %gs:PAL_TCB_URTS_TCS, %rbx
@@ -27,6 +33,12 @@ sgx_ecall:
ENCLU
# currently only ECALL_THREAD_RESET returns
.Lafter_resume:
popq %r15
popq %r14
popq %r13
popq %r12
popq %rbp
popq %rbx
retq
@@ -41,12 +53,9 @@ async_exit_pointer:
sgx_raise:
leaq .Lafter_resume(%rip), %rdx
jmp .Ldo_ecall
jmp .Ldo_ecall_callee_save
.Lafter_resume:
retq
sgx_entry:
.Lsgx_entry:
# arguments: RDI - code, RSI - ms
.cfi_startproc