@@ -144,13 +144,15 @@ elf_entry:
144144
145145/* This code needs to be called *after* the enclave stack has been setup. */
146146/* There are 3 places where this needs to happen, so this is put in a macro. */
147- .macro sanitize_rflags
147+ .macro entry_sanitize_final
148148/* Sanitize rflags received from user */
149149/* - DF flag: x86-64 ABI requires DF to be unset at function entry/exit */
150150/* - AC flag: AEX on misaligned memory accesses leaks side channel info */
151151 pushfq
152152 andq $~0x40400 , (%rsp )
153153 popfq
154+ bt $0 ,.Laborted(%rip )
155+ jc .Lreentry_panic
154156.endm
155157
156158.text
@@ -174,9 +176,6 @@ sgx_entry:
174176 jz .Lskip_debug_init
175177 mov %r10 ,%gs :tcsls_debug_panic_buf_ptr
176178.Lskip_debug_init:
177- /* check for abort */
178- bt $0 ,.Laborted(%rip )
179- jc .Lreentry_panic
180179/* check if returning from usercall */
181180 mov %gs :tcsls_last_rsp,%r11
182181 test %r11 ,%r11
@@ -194,7 +193,7 @@ sgx_entry:
194193 lea IMAGE_BASE(%rip ),%rax
195194 add %rax ,%rsp
196195 mov %rsp ,%gs :tcsls_tos
197- sanitize_rflags
196+ entry_sanitize_final
198197/* call tcs_init */
199198/* store caller-saved registers in callee-saved registers */
200199 mov %rdi ,%rbx
@@ -212,7 +211,7 @@ sgx_entry:
212211 mov %r15 ,%r9
213212 jmp .Lafter_init
214213.Lskip_init:
215- sanitize_rflags
214+ entry_sanitize_final
216215.Lafter_init:
217216/* call into main entry point */
218217 load_tcsls_flag_secondary_bool cx /* RCX = entry() argument: secondary: bool */
@@ -311,10 +310,10 @@ usercall:
311310 movq $0 ,%gs :tcsls_last_rsp
312311/* restore callee-saved state, cf. "save" above */
313312 mov %r11 ,%rsp
314- sanitize_rflags
315313 ldmxcsr (%rsp )
316314 fldcw 4 (%rsp )
317315 add $8 , %rsp
316+ entry_sanitize_final
318317 pop %rbx
319318 pop %rbp
320319 pop %r12
0 commit comments