Skip to content

Commit 1b2f52c

Browse files
authored
Rollup merge of #73471 - raoulstrackx:raoul/fpu_tag_word, r=jethrogb
Prevent attacker from manipulating FPU tag word used in SGX enclave Insufficient sanitization of the x87 FPU tag word in the trusted enclave runtime allowed unprivileged adversaries in the containing host application to induce incoherent or unexpected results for ABI-compliant compiled enclave application code that uses the x87 FPU. Vulnerability was disclosed to us by Fritz Alder, Jo Van Bulck, David Oswald and Frank Piessens cc: @jethrogb
2 parents 50cbc1a + 33b304c commit 1b2f52c

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

Diff for: src/libstd/sys/sgx/abi/entry.S

+8-12
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,10 @@ IMAGE_BASE:
2626
.Lxsave_clear:
2727
.org .+24
2828
.Lxsave_mxcsr:
29-
.int 0
29+
.short 0x1f80
3030

3131
/* We can store a bunch of data in the gap between MXCSR and the XSAVE header */
3232

33-
/* MXCSR initialization value for ABI */
34-
.Lmxcsr_init:
35-
.int 0x1f80
36-
37-
/* x87 FPU control word initialization value for ABI */
38-
.Lfpucw_init:
39-
.int 0x037f
40-
4133
/* The following symbols point at read-only data that will be filled in by the */
4234
/* post-linker. */
4335

@@ -177,13 +169,17 @@ sgx_entry:
177169
jz .Lskip_debug_init
178170
mov %r10,%gs:tcsls_debug_panic_buf_ptr
179171
.Lskip_debug_init:
172+
/* reset cpu state */
173+
mov %rdx, %r10
174+
mov $-1, %rax
175+
mov $-1, %rdx
176+
xrstor .Lxsave_clear(%rip)
177+
mov %r10, %rdx
178+
180179
/* check if returning from usercall */
181180
mov %gs:tcsls_last_rsp,%r11
182181
test %r11,%r11
183182
jnz .Lusercall_ret
184-
/* reset user state */
185-
ldmxcsr .Lmxcsr_init(%rip)
186-
fldcw .Lfpucw_init(%rip)
187183
/* setup stack */
188184
mov %gs:tcsls_tos,%rsp /* initially, RSP is not set to the correct value */
189185
/* here. This is fixed below under "adjust stack". */

0 commit comments

Comments
 (0)