Skip to content

Commit d40c6af

Browse files
authored
Rollup merge of #65810 - raoulstrackx:ac_mitigation, r=nagisa
SGX: Clear additional flag on enclave entry An attacker could set both the AC flag in CR0 as in rflags. This causes the enclave to perform an AEX upon a misaligned memory access, and an attacker learns some information about the internal enclave state. The AC flag in rflags is copied from userspace upon an enclave entry. Upon AEX it is copied and later restored. This patch forces the rflag.AC bit to be reset right after an enter.
2 parents f0c58e9 + 5aafa98 commit d40c6af

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/libstd/sys/sgx/abi/entry.S

+7-1
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,14 @@ sgx_entry:
119119
mov %rbx,%gs:tcsls_tcs_addr
120120
stmxcsr %gs:tcsls_user_mxcsr
121121
fnstcw %gs:tcsls_user_fcw
122+
122123
/* reset user state */
123-
cld /* x86-64 ABI requires DF to be unset at function entry/exit */
124+
/* - DF flag: x86-64 ABI requires DF to be unset at function entry/exit */
125+
/* - AC flag: AEX on misaligned memory accesses leaks side channel info */
126+
pushfq
127+
andq $~0x40400, (%rsp)
128+
popfq
129+
124130
/* check for debug buffer pointer */
125131
testb $0xff,DEBUG(%rip)
126132
jz .Lskip_debug_init

0 commit comments

Comments
 (0)