From fc500368485bd2ebafea6a37da30f49c8be75aac Mon Sep 17 00:00:00 2001 From: Raoul Strackx Date: Mon, 21 Oct 2019 15:10:32 +0200 Subject: [PATCH 1/4] fixed ac vulnerability --- src/libstd/sys/sgx/abi/entry.S | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libstd/sys/sgx/abi/entry.S b/src/libstd/sys/sgx/abi/entry.S index c35e49b1dc6ea..4f8673a1907d7 100644 --- a/src/libstd/sys/sgx/abi/entry.S +++ b/src/libstd/sys/sgx/abi/entry.S @@ -121,6 +121,16 @@ sgx_entry: fnstcw %gs:tcsls_user_fcw /* reset user state */ cld /* x86-64 ABI requires DF to be unset at function entry/exit */ + +/* making sure AC flag is not set in rflags */ +/* avoid using the 'clac' instruction to be compatible with older compilers */ + push %rcx + pushfq + popq %rcx + and $0xFFFFFFFFFFFBFFFF, %rcx + push %rcx + popfq + /* check for debug buffer pointer */ testb $0xff,DEBUG(%rip) jz .Lskip_debug_init From d257c20a1dc97631f6c1cf4a22f32ed80f23e4f1 Mon Sep 17 00:00:00 2001 From: Raoul Strackx Date: Fri, 25 Oct 2019 15:27:48 +0200 Subject: [PATCH 2/4] removed unnecessary push --- src/libstd/sys/sgx/abi/entry.S | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libstd/sys/sgx/abi/entry.S b/src/libstd/sys/sgx/abi/entry.S index 4f8673a1907d7..08aee89fe03de 100644 --- a/src/libstd/sys/sgx/abi/entry.S +++ b/src/libstd/sys/sgx/abi/entry.S @@ -124,7 +124,6 @@ sgx_entry: /* making sure AC flag is not set in rflags */ /* avoid using the 'clac' instruction to be compatible with older compilers */ - push %rcx pushfq popq %rcx and $0xFFFFFFFFFFFBFFFF, %rcx From 34f5d5923f3dff832fbc62a61a062643d78e4c03 Mon Sep 17 00:00:00 2001 From: Raoul Strackx Date: Fri, 25 Oct 2019 15:44:07 +0200 Subject: [PATCH 3/4] cleaning up code --- src/libstd/sys/sgx/abi/entry.S | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/libstd/sys/sgx/abi/entry.S b/src/libstd/sys/sgx/abi/entry.S index 08aee89fe03de..f5d9c4338deb5 100644 --- a/src/libstd/sys/sgx/abi/entry.S +++ b/src/libstd/sys/sgx/abi/entry.S @@ -119,16 +119,11 @@ sgx_entry: mov %rbx,%gs:tcsls_tcs_addr stmxcsr %gs:tcsls_user_mxcsr fnstcw %gs:tcsls_user_fcw -/* reset user state */ - cld /* x86-64 ABI requires DF to be unset at function entry/exit */ -/* making sure AC flag is not set in rflags */ -/* avoid using the 'clac' instruction to be compatible with older compilers */ - pushfq - popq %rcx - and $0xFFFFFFFFFFFBFFFF, %rcx - push %rcx - popfq +/* reset user state */ +/* - DF flag: x86-64 ABI requires DF to be unset at function entry/exit */ +/* - AC flag: AEX on misaligned memory accesses leaks side channel info */ + andq $~0x40400, (%rsp) /* check for debug buffer pointer */ testb $0xff,DEBUG(%rip) From 5aafa98562a3bd472ae7934f0d192b9cfcb36254 Mon Sep 17 00:00:00 2001 From: Raoul Strackx Date: Fri, 25 Oct 2019 16:06:13 +0200 Subject: [PATCH 4/4] forgot pushfq/popqfq: fixed --- src/libstd/sys/sgx/abi/entry.S | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libstd/sys/sgx/abi/entry.S b/src/libstd/sys/sgx/abi/entry.S index f5d9c4338deb5..cd26c7ca200b0 100644 --- a/src/libstd/sys/sgx/abi/entry.S +++ b/src/libstd/sys/sgx/abi/entry.S @@ -123,7 +123,9 @@ sgx_entry: /* reset user state */ /* - DF flag: x86-64 ABI requires DF to be unset at function entry/exit */ /* - AC flag: AEX on misaligned memory accesses leaks side channel info */ + pushfq andq $~0x40400, (%rsp) + popfq /* check for debug buffer pointer */ testb $0xff,DEBUG(%rip)