Skip to content

Commit 0e99648

Browse files
author
Dmitrii Kuvaiskii
committed
fixup! [PAL/Linux-SGX] Add AEX-Notify flows in exception handling
Fixed EDMM issue. Turned out to be a case of too many nested signal handlers inside Gramine's SGX PAL, which overflowed the SGX enclave signal stack. Signed-off-by: Dmitrii Kuvaiskii <[email protected]>
1 parent 4f19422 commit 0e99648

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pal/src/host/linux-sgx/pal_exception.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,27 @@ noreturn static void restore_sgx_context(sgx_cpu_context_t* uc, PAL_XREGS_STATE*
8686
if (xregs_state == NULL)
8787
xregs_state = (PAL_XREGS_STATE*)g_xsave_reset_state;
8888

89-
#ifdef ASAN
90-
/* Unpoison the signal stack before leaving it */
9189
uintptr_t sig_stack_low = GET_ENCLAVE_TCB(sig_stack_low);
9290
uintptr_t sig_stack_high = GET_ENCLAVE_TCB(sig_stack_high);
91+
bool restored_context_is_sighandler = (uc->rsp >= sig_stack_low && uc->rsp < sig_stack_high);
92+
93+
#ifdef ASAN
94+
/* Unpoison the signal stack before leaving it */
9395
asan_unpoison_current_stack(sig_stack_low, sig_stack_high - sig_stack_low);
9496
#endif
9597

9698
if (g_aex_notify_enabled && GET_ENCLAVE_TCB(ready_for_aex_notify)
97-
&& !GET_ENCLAVE_TCB(stopping_aex_notify)) {
99+
&& !GET_ENCLAVE_TCB(stopping_aex_notify) && !restored_context_is_sighandler) {
98100
/*
99101
* AEX-Notify must be re-enabled for this enclave thread before applying any mitigations
100102
* (and consequently before restoring the regular execution of the enclave thread). For
101103
* details, see e.g. the official whitepaper on AEX-Notify from Intel.
104+
*
105+
* Note that we re-enable AEX-Notify only in the outermost signal handler (the one that will
106+
* jump to the application code and stack). Otherwise, AEX-Notify would be enabled while
107+
* inside this Gramine-internal signal handler, and exceptions like #PF would result in
108+
* nested invocations of this signal handler, thus overflowing the signal stack. This is
109+
* especially true for the EDMM flows where #PF exceptions are a norm.
102110
*/
103111
GET_ENCLAVE_TCB(gpr)->aexnotify = 1;
104112
apply_aex_notify_mitigations(uc, xregs_state);

0 commit comments

Comments
 (0)