[Pal/Linux-SGX] Fix type cast issue during async signal handling

Untrusted Linux-SGX PAL handles host-level asynchronous signals by
emulating the interrupt (-EINTR) of the pending OCALL. Unfortunately,
there was a type cast issue such that int32_t -EINTR (`-4`) was
casted to a positive uint64_t and then OCALL consumed this positive
number instead of erroring out on -EINTR. This commit adds explicit
type casting to fix this bug.
This commit is contained in:
Dmitrii Kuvaiskii
2020-12-28 01:28:26 -08:00
parent 8c1fc5168e
commit dd85aef596
2 changed files with 8 additions and 13 deletions
+5 -11
View File
@@ -157,21 +157,15 @@ static inline uint64_t pal_ucontext_get_ip(ucontext_t* uc) {
return uc->uc_mcontext.gregs[REG_RIP];
}
static inline void pal_ucontext_set_function_parameters(ucontext_t* uc, void* func, size_t count,
...) {
static inline void pal_ucontext_set_function_parameters(ucontext_t* uc, void* func,
size_t func_args_num, greg_t* func_args) {
const unsigned int param_regs[] = {REG_RDI, REG_RSI, REG_RDX, REG_RCX};
va_list ap;
assert(count <= ARRAY_SIZE(param_regs));
assert(func_args_num <= ARRAY_SIZE(param_regs));
uc->uc_mcontext.gregs[REG_RIP] = (greg_t)func;
va_start(ap, count);
for (size_t i = 0; i < count; i++)
uc->uc_mcontext.gregs[param_regs[i]] = va_arg(ap, greg_t);
va_end(ap);
for (size_t i = 0; i < func_args_num; i++)
uc->uc_mcontext.gregs[param_regs[i]] = func_args[i];
}
#else /* __WORDSIZE == 32 */
+3 -2
View File
@@ -174,10 +174,11 @@ static void handle_async_signal(int signum, siginfo_t* info, struct ucontext* uc
}
/* signal arrived while in untrusted PAL code (during syscall handling), emulate as if syscall
* was interrupted */
* was interrupted by calling sgx_entry_return(syscall_return_value=-EINTR, event) */
/* TODO: we abandon PAL state here (possibly still holding some locks, etc) and return to
* enclave; ideally we must unwind/fix the state and only then jump into enclave */
pal_ucontext_set_function_parameters(uc, sgx_entry_return, 2, -EINTR, event);
greg_t func_args[2] = {-EINTR, event};
pal_ucontext_set_function_parameters(uc, sgx_entry_return, /*func_args_num=*/2, func_args);
}
static void handle_dummy_signal(int signum, siginfo_t* info, struct ucontext* uc) {