Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 334872a

Browse files
Sean Christophersonsuryasaimadhu
authored andcommitted
x86/traps: Attempt to fixup exceptions in vDSO before signaling
vDSO functions can now leverage an exception fixup mechanism similar to kernel exception fixup. For vDSO exception fixup, the initial user is Intel's Software Guard Extensions (SGX), which will wrap the low-level transitions to/from the enclave, i.e. EENTER and ERESUME instructions, in a vDSO function and leverage fixup to intercept exceptions that would otherwise generate a signal. This allows the vDSO wrapper to return the fault information directly to its caller, obviating the need for SGX applications and libraries to juggle signal handlers. Attempt to fixup vDSO exceptions immediately prior to populating and sending signal information. Except for the delivery mechanism, an exception in a vDSO function should be treated like any other exception in userspace, e.g. any fault that is successfully handled by the kernel should not be directly visible to userspace. Although it's debatable whether or not all exceptions are of interest to enclaves, defer to the vDSO fixup to decide whether to do fixup or generate a signal. Future users of vDSO fixup, if there ever are any, will undoubtedly have different requirements than SGX enclaves, e.g. the fixup vs. signal logic can be made function specific if/when necessary. Suggested-by: Andy Lutomirski <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Acked-by: Jethro Beekman <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent cd072da commit 334872a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

arch/x86/kernel/traps.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include <asm/umip.h>
6161
#include <asm/insn.h>
6262
#include <asm/insn-eval.h>
63+
#include <asm/vdso.h>
6364

6465
#ifdef CONFIG_X86_64
6566
#include <asm/x86_init.h>
@@ -117,6 +118,9 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
117118
tsk->thread.error_code = error_code;
118119
tsk->thread.trap_nr = trapnr;
119120
die(str, regs, error_code);
121+
} else {
122+
if (fixup_vdso_exception(regs, trapnr, error_code, 0))
123+
return 0;
120124
}
121125

122126
/*
@@ -550,6 +554,9 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection)
550554
tsk->thread.error_code = error_code;
551555
tsk->thread.trap_nr = X86_TRAP_GP;
552556

557+
if (fixup_vdso_exception(regs, X86_TRAP_GP, error_code, 0))
558+
return;
559+
553560
show_signal(tsk, SIGSEGV, "", desc, regs, error_code);
554561
force_sig(SIGSEGV);
555562
goto exit;
@@ -1048,6 +1055,9 @@ static void math_error(struct pt_regs *regs, int trapnr)
10481055
if (!si_code)
10491056
goto exit;
10501057

1058+
if (fixup_vdso_exception(regs, trapnr, 0, 0))
1059+
return;
1060+
10511061
force_sig_fault(SIGFPE, si_code,
10521062
(void __user *)uprobe_get_trap_addr(regs));
10531063
exit:

arch/x86/mm/fault.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <asm/cpu_entry_area.h> /* exception stack */
3131
#include <asm/pgtable_areas.h> /* VMALLOC_START, ... */
3232
#include <asm/kvm_para.h> /* kvm_handle_async_pf */
33+
#include <asm/vdso.h> /* fixup_vdso_exception() */
3334

3435
#define CREATE_TRACE_POINTS
3536
#include <asm/trace/exceptions.h>
@@ -814,6 +815,9 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
814815

815816
sanitize_error_code(address, &error_code);
816817

818+
if (fixup_vdso_exception(regs, X86_TRAP_PF, error_code, address))
819+
return;
820+
817821
if (likely(show_unhandled_signals))
818822
show_signal_msg(regs, error_code, address, tsk);
819823

@@ -933,6 +937,9 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
933937

934938
sanitize_error_code(address, &error_code);
935939

940+
if (fixup_vdso_exception(regs, X86_TRAP_PF, error_code, address))
941+
return;
942+
936943
set_signal_archinfo(address, error_code);
937944

938945
#ifdef CONFIG_MEMORY_FAILURE

0 commit comments

Comments
 (0)