@@ -134,6 +134,17 @@ elf_entry:
134
134
ud2 /* should not be reached */
135
135
/* end elf_entry */
136
136
137
+ /* This code needs to be called *after* the enclave stack has been setup. */
138
+ /* There are 3 places where this needs to happen, so this is put in a macro. */
139
+ .macro sanitize_rflags
140
+ /* Sanitize rflags received from user */
141
+ /* - DF flag: x86-64 ABI requires DF to be unset at function entry/exit */
142
+ /* - AC flag: AEX on misaligned memory accesses leaks side channel info */
143
+ pushfq
144
+ andq $~0x40400 , (%rsp )
145
+ popfq
146
+ .endm
147
+
137
148
.text
138
149
.global sgx_entry
139
150
.type sgx_entry,function
@@ -150,13 +161,6 @@ sgx_entry:
150
161
stmxcsr %gs :tcsls_user_mxcsr
151
162
fnstcw %gs :tcsls_user_fcw
152
163
153
- /* reset user state */
154
- /* - DF flag: x86-64 ABI requires DF to be unset at function entry/exit */
155
- /* - AC flag: AEX on misaligned memory accesses leaks side channel info */
156
- pushfq
157
- andq $~0x40400 , (%rsp )
158
- popfq
159
-
160
164
/* check for debug buffer pointer */
161
165
testb $0xff ,DEBUG(%rip )
162
166
jz .Lskip_debug_init
@@ -179,6 +183,7 @@ sgx_entry:
179
183
lea IMAGE_BASE(%rip ),%rax
180
184
add %rax ,%rsp
181
185
mov %rsp ,%gs :tcsls_tos
186
+ sanitize_rflags
182
187
/* call tcs_init */
183
188
/* store caller-saved registers in callee-saved registers */
184
189
mov %rdi ,%rbx
@@ -194,7 +199,10 @@ sgx_entry:
194
199
mov %r13 ,%rdx
195
200
mov %r14 ,%r8
196
201
mov %r15 ,%r9
202
+ jmp .Lafter_init
197
203
.Lskip_init:
204
+ sanitize_rflags
205
+ .Lafter_init:
198
206
/* call into main entry point */
199
207
load_tcsls_flag_secondary_bool cx /* RCX = entry() argument: secondary: bool */
200
208
call entry /* RDI, RSI, RDX, R8, R9 passed in from userspace */
@@ -292,6 +300,7 @@ usercall:
292
300
movq $0 ,%gs :tcsls_last_rsp
293
301
/* restore callee-saved state, cf. "save" above */
294
302
mov %r11 ,%rsp
303
+ sanitize_rflags
295
304
ldmxcsr (%rsp )
296
305
fldcw 4 (%rsp )
297
306
add $8 , %rsp
0 commit comments