x86/extable: Rework the exception table mechanics

The exception table entries contain the instruction address, the fixup
address and the handler address. All addresses are relative. Storing the
handler address has a few downsides:

 1) Most handlers need to be exported

 2) Handlers can be defined everywhere and there is no overview about the
    handler types

 3) MCE needs to check the handler type to decide whether an in kernel #MC
    can be recovered. The functionality of the handler itself is not in any
    way special, but for these checks there need to be separate functions
    which in the worst case have to be exported.

    Some of these 'recoverable' exception fixups are pretty obscure and
    just reuse some other handler to spare code. That obfuscates e.g. the
    #MC safe copy functions. Cleaning that up would require more handlers
    and exports

Rework the exception fixup mechanics by storing a fixup type number instead
of the handler address and invoke the proper handler for each fixup
type. Also teach the extable sort to leave the type field alone.

This makes most handlers static except for special cases like the MCE
MSR fixup and the BPF fixup. This allows to add more types for cleaning up
the obscure places without adding more handler code and exports.

There is a marginal code size reduction for a production config and it
removes _eight_ exported symbols.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lkml.kernel.org/r/20210908132525.211958725@linutronix.de
This commit is contained in:
Thomas Gleixner 2021-09-08 15:29:18 +02:00 committed by Borislav Petkov
parent 083b32d6f4
commit 46d28947d9
12 changed files with 133 additions and 155 deletions

View File

@ -122,14 +122,17 @@
#ifdef __KERNEL__ #ifdef __KERNEL__
# include <asm/extable_fixup_types.h>
/* Exception table entry */ /* Exception table entry */
#ifdef __ASSEMBLY__ #ifdef __ASSEMBLY__
# define _ASM_EXTABLE_HANDLE(from, to, handler) \
# define _ASM_EXTABLE_TYPE(from, to, type) \
.pushsection "__ex_table","a" ; \ .pushsection "__ex_table","a" ; \
.balign 4 ; \ .balign 4 ; \
.long (from) - . ; \ .long (from) - . ; \
.long (to) - . ; \ .long (to) - . ; \
.long (handler) - . ; \ .long type ; \
.popsection .popsection
# ifdef CONFIG_KPROBES # ifdef CONFIG_KPROBES
@ -143,13 +146,13 @@
# endif # endif
#else /* ! __ASSEMBLY__ */ #else /* ! __ASSEMBLY__ */
# define _EXPAND_EXTABLE_HANDLE(x) #x
# define _ASM_EXTABLE_HANDLE(from, to, handler) \ # define _ASM_EXTABLE_TYPE(from, to, type) \
" .pushsection \"__ex_table\",\"a\"\n" \ " .pushsection \"__ex_table\",\"a\"\n" \
" .balign 4\n" \ " .balign 4\n" \
" .long (" #from ") - .\n" \ " .long (" #from ") - .\n" \
" .long (" #to ") - .\n" \ " .long (" #to ") - .\n" \
" .long (" _EXPAND_EXTABLE_HANDLE(handler) ") - .\n" \ " .long " __stringify(type) " \n" \
" .popsection\n" " .popsection\n"
/* For C file, we already have NOKPROBE_SYMBOL macro */ /* For C file, we already have NOKPROBE_SYMBOL macro */
@ -165,17 +168,16 @@ register unsigned long current_stack_pointer asm(_ASM_SP);
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
#define _ASM_EXTABLE(from, to) \ #define _ASM_EXTABLE(from, to) \
_ASM_EXTABLE_HANDLE(from, to, ex_handler_default) _ASM_EXTABLE_TYPE(from, to, EX_TYPE_DEFAULT)
#define _ASM_EXTABLE_UA(from, to) \ #define _ASM_EXTABLE_UA(from, to) \
_ASM_EXTABLE_HANDLE(from, to, ex_handler_uaccess) _ASM_EXTABLE_TYPE(from, to, EX_TYPE_UACCESS)
#define _ASM_EXTABLE_CPY(from, to) \ #define _ASM_EXTABLE_CPY(from, to) \
_ASM_EXTABLE_HANDLE(from, to, ex_handler_copy) _ASM_EXTABLE_TYPE(from, to, EX_TYPE_COPY)
#define _ASM_EXTABLE_FAULT(from, to) \ #define _ASM_EXTABLE_FAULT(from, to) \
_ASM_EXTABLE_HANDLE(from, to, ex_handler_fault) _ASM_EXTABLE_TYPE(from, to, EX_TYPE_FAULT)
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
#endif /* _ASM_X86_ASM_H */ #endif /* _ASM_X86_ASM_H */

View File

@ -1,12 +1,18 @@
/* SPDX-License-Identifier: GPL-2.0 */ /* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_X86_EXTABLE_H #ifndef _ASM_X86_EXTABLE_H
#define _ASM_X86_EXTABLE_H #define _ASM_X86_EXTABLE_H
#include <asm/extable_fixup_types.h>
/* /*
* The exception table consists of triples of addresses relative to the * The exception table consists of two addresses relative to the
* exception table entry itself. The first address is of an instruction * exception table entry itself and a type selector field.
* that is allowed to fault, the second is the target at which the program *
* should continue. The third is a handler function to deal with the fault * The first address is of an instruction that is allowed to fault, the
* caused by the instruction in the first field. * second is the target at which the program should continue.
*
* The type entry is used by fixup_exception() to select the handler to
* deal with the fault caused by the instruction in the first field.
* *
* All the routines below use bits of fixup code that are out of line * All the routines below use bits of fixup code that are out of line
* with the main instruction path. This means when everything is well, * with the main instruction path. This means when everything is well,
@ -15,7 +21,7 @@
*/ */
struct exception_table_entry { struct exception_table_entry {
int insn, fixup, handler; int insn, fixup, type;
}; };
struct pt_regs; struct pt_regs;
@ -25,21 +31,27 @@ struct pt_regs;
do { \ do { \
(a)->fixup = (b)->fixup + (delta); \ (a)->fixup = (b)->fixup + (delta); \
(b)->fixup = (tmp).fixup - (delta); \ (b)->fixup = (tmp).fixup - (delta); \
(a)->handler = (b)->handler + (delta); \ (a)->type = (b)->type; \
(b)->handler = (tmp).handler - (delta); \ (b)->type = (tmp).type; \
} while (0) } while (0)
enum handler_type {
EX_HANDLER_NONE,
EX_HANDLER_FAULT,
EX_HANDLER_UACCESS,
EX_HANDLER_OTHER
};
extern int fixup_exception(struct pt_regs *regs, int trapnr, extern int fixup_exception(struct pt_regs *regs, int trapnr,
unsigned long error_code, unsigned long fault_addr); unsigned long error_code, unsigned long fault_addr);
extern int fixup_bug(struct pt_regs *regs, int trapnr); extern int fixup_bug(struct pt_regs *regs, int trapnr);
extern enum handler_type ex_get_fault_handler_type(unsigned long ip); extern int ex_get_fixup_type(unsigned long ip);
extern void early_fixup_exception(struct pt_regs *regs, int trapnr); extern void early_fixup_exception(struct pt_regs *regs, int trapnr);
#ifdef CONFIG_X86_MCE
extern void ex_handler_msr_mce(struct pt_regs *regs, bool wrmsr);
#else
static inline void ex_handler_msr_mce(struct pt_regs *regs, bool wrmsr) { }
#endif
#if defined(CONFIG_BPF_JIT) && defined(CONFIG_X86_64)
bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs);
#else
static inline bool ex_handler_bpf(const struct exception_table_entry *x,
struct pt_regs *regs) { return false; }
#endif
#endif #endif

View File

@ -0,0 +1,19 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_X86_EXTABLE_FIXUP_TYPES_H
#define _ASM_X86_EXTABLE_FIXUP_TYPES_H
#define EX_TYPE_NONE 0
#define EX_TYPE_DEFAULT 1
#define EX_TYPE_FAULT 2
#define EX_TYPE_UACCESS 3
#define EX_TYPE_COPY 4
#define EX_TYPE_CLEAR_FS 5
#define EX_TYPE_FPU_RESTORE 6
#define EX_TYPE_WRMSR 7
#define EX_TYPE_RDMSR 8
#define EX_TYPE_BPF 9
#define EX_TYPE_WRMSR_IN_MCE 10
#define EX_TYPE_RDMSR_IN_MCE 11
#endif

View File

@ -126,7 +126,7 @@ extern void save_fpregs_to_fpstate(struct fpu *fpu);
#define kernel_insn(insn, output, input...) \ #define kernel_insn(insn, output, input...) \
asm volatile("1:" #insn "\n\t" \ asm volatile("1:" #insn "\n\t" \
"2:\n" \ "2:\n" \
_ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_fprestore) \ _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_FPU_RESTORE) \
: output : input) : output : input)
static inline int fnsave_to_user_sigframe(struct fregs_state __user *fx) static inline int fnsave_to_user_sigframe(struct fregs_state __user *fx)
@ -253,7 +253,7 @@ static inline void fxsave(struct fxregs_state *fx)
XRSTORS, X86_FEATURE_XSAVES) \ XRSTORS, X86_FEATURE_XSAVES) \
"\n" \ "\n" \
"3:\n" \ "3:\n" \
_ASM_EXTABLE_HANDLE(661b, 3b, ex_handler_fprestore)\ _ASM_EXTABLE_TYPE(661b, 3b, EX_TYPE_FPU_RESTORE) \
: \ : \
: "D" (st), "m" (*st), "a" (lmask), "d" (hmask) \ : "D" (st), "m" (*st), "a" (lmask), "d" (hmask) \
: "memory") : "memory")

View File

@ -92,7 +92,7 @@ static __always_inline unsigned long long __rdmsr(unsigned int msr)
asm volatile("1: rdmsr\n" asm volatile("1: rdmsr\n"
"2:\n" "2:\n"
_ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_rdmsr_unsafe) _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_RDMSR)
: EAX_EDX_RET(val, low, high) : "c" (msr)); : EAX_EDX_RET(val, low, high) : "c" (msr));
return EAX_EDX_VAL(val, low, high); return EAX_EDX_VAL(val, low, high);
@ -102,7 +102,7 @@ static __always_inline void __wrmsr(unsigned int msr, u32 low, u32 high)
{ {
asm volatile("1: wrmsr\n" asm volatile("1: wrmsr\n"
"2:\n" "2:\n"
_ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_wrmsr_unsafe) _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_WRMSR)
: : "c" (msr), "a"(low), "d" (high) : "memory"); : : "c" (msr), "a"(low), "d" (high) : "memory");
} }

View File

@ -339,7 +339,7 @@ static inline void __loadsegment_fs(unsigned short value)
"1: movw %0, %%fs \n" "1: movw %0, %%fs \n"
"2: \n" "2: \n"
_ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_clear_fs) _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_CLEAR_FS)
: : "rm" (value) : "memory"); : : "rm" (value) : "memory");
} }

View File

@ -373,7 +373,7 @@ static int msr_to_offset(u32 msr)
return -1; return -1;
} }
static void ex_handler_msr_mce(struct pt_regs *regs, bool wrmsr) void ex_handler_msr_mce(struct pt_regs *regs, bool wrmsr)
{ {
if (wrmsr) { if (wrmsr) {
pr_emerg("MSR access error: WRMSR to 0x%x (tried to write 0x%08x%08x) at rIP: 0x%lx (%pS)\n", pr_emerg("MSR access error: WRMSR to 0x%x (tried to write 0x%08x%08x) at rIP: 0x%lx (%pS)\n",
@ -392,15 +392,6 @@ static void ex_handler_msr_mce(struct pt_regs *regs, bool wrmsr)
cpu_relax(); cpu_relax();
} }
__visible bool ex_handler_rdmsr_fault(const struct exception_table_entry *fixup,
struct pt_regs *regs, int trapnr,
unsigned long error_code,
unsigned long fault_addr)
{
ex_handler_msr_mce(regs, false);
return true;
}
/* MSR access wrappers used for error injection */ /* MSR access wrappers used for error injection */
static noinstr u64 mce_rdmsrl(u32 msr) static noinstr u64 mce_rdmsrl(u32 msr)
{ {
@ -430,22 +421,13 @@ static noinstr u64 mce_rdmsrl(u32 msr)
*/ */
asm volatile("1: rdmsr\n" asm volatile("1: rdmsr\n"
"2:\n" "2:\n"
_ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_rdmsr_fault) _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_RDMSR_IN_MCE)
: EAX_EDX_RET(val, low, high) : "c" (msr)); : EAX_EDX_RET(val, low, high) : "c" (msr));
return EAX_EDX_VAL(val, low, high); return EAX_EDX_VAL(val, low, high);
} }
__visible bool ex_handler_wrmsr_fault(const struct exception_table_entry *fixup,
struct pt_regs *regs, int trapnr,
unsigned long error_code,
unsigned long fault_addr)
{
ex_handler_msr_mce(regs, true);
return true;
}
static noinstr void mce_wrmsrl(u32 msr, u64 v) static noinstr void mce_wrmsrl(u32 msr, u64 v)
{ {
u32 low, high; u32 low, high;
@ -470,7 +452,7 @@ static noinstr void mce_wrmsrl(u32 msr, u64 v)
/* See comment in mce_rdmsrl() */ /* See comment in mce_rdmsrl() */
asm volatile("1: wrmsr\n" asm volatile("1: wrmsr\n"
"2:\n" "2:\n"
_ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_wrmsr_fault) _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_WRMSR_IN_MCE)
: : "c" (msr), "a"(low), "d" (high) : "memory"); : : "c" (msr), "a"(low), "d" (high) : "memory");
} }

View File

@ -186,14 +186,4 @@ extern bool amd_filter_mce(struct mce *m);
static inline bool amd_filter_mce(struct mce *m) { return false; } static inline bool amd_filter_mce(struct mce *m) { return false; }
#endif #endif
__visible bool ex_handler_rdmsr_fault(const struct exception_table_entry *fixup,
struct pt_regs *regs, int trapnr,
unsigned long error_code,
unsigned long fault_addr);
__visible bool ex_handler_wrmsr_fault(const struct exception_table_entry *fixup,
struct pt_regs *regs, int trapnr,
unsigned long error_code,
unsigned long fault_addr);
#endif /* __X86_MCE_INTERNAL_H__ */ #endif /* __X86_MCE_INTERNAL_H__ */

View File

@ -265,25 +265,24 @@ static bool is_copy_from_user(struct pt_regs *regs)
*/ */
static int error_context(struct mce *m, struct pt_regs *regs) static int error_context(struct mce *m, struct pt_regs *regs)
{ {
enum handler_type t;
if ((m->cs & 3) == 3) if ((m->cs & 3) == 3)
return IN_USER; return IN_USER;
if (!mc_recoverable(m->mcgstatus)) if (!mc_recoverable(m->mcgstatus))
return IN_KERNEL; return IN_KERNEL;
t = ex_get_fault_handler_type(m->ip); switch (ex_get_fixup_type(m->ip)) {
if (t == EX_HANDLER_FAULT) { case EX_TYPE_UACCESS:
m->kflags |= MCE_IN_KERNEL_RECOV; case EX_TYPE_COPY:
return IN_KERNEL_RECOV; if (!regs || !is_copy_from_user(regs))
} return IN_KERNEL;
if (t == EX_HANDLER_UACCESS && regs && is_copy_from_user(regs)) {
m->kflags |= MCE_IN_KERNEL_RECOV;
m->kflags |= MCE_IN_KERNEL_COPYIN; m->kflags |= MCE_IN_KERNEL_COPYIN;
fallthrough;
case EX_TYPE_FAULT:
m->kflags |= MCE_IN_KERNEL_RECOV;
return IN_KERNEL_RECOV; return IN_KERNEL_RECOV;
default:
return IN_KERNEL;
} }
return IN_KERNEL;
} }
static int mce_severity_amd_smca(struct mce *m, enum context err_ctx) static int mce_severity_amd_smca(struct mce *m, enum context err_ctx)

View File

@ -9,40 +9,25 @@
#include <asm/traps.h> #include <asm/traps.h>
#include <asm/kdebug.h> #include <asm/kdebug.h>
typedef bool (*ex_handler_t)(const struct exception_table_entry *,
struct pt_regs *, int, unsigned long,
unsigned long);
static inline unsigned long static inline unsigned long
ex_fixup_addr(const struct exception_table_entry *x) ex_fixup_addr(const struct exception_table_entry *x)
{ {
return (unsigned long)&x->fixup + x->fixup; return (unsigned long)&x->fixup + x->fixup;
} }
static inline ex_handler_t
ex_fixup_handler(const struct exception_table_entry *x)
{
return (ex_handler_t)((unsigned long)&x->handler + x->handler);
}
__visible bool ex_handler_default(const struct exception_table_entry *fixup, static bool ex_handler_default(const struct exception_table_entry *fixup,
struct pt_regs *regs, int trapnr, struct pt_regs *regs)
unsigned long error_code,
unsigned long fault_addr)
{ {
regs->ip = ex_fixup_addr(fixup); regs->ip = ex_fixup_addr(fixup);
return true; return true;
} }
EXPORT_SYMBOL(ex_handler_default);
__visible bool ex_handler_fault(const struct exception_table_entry *fixup, static bool ex_handler_fault(const struct exception_table_entry *fixup,
struct pt_regs *regs, int trapnr, struct pt_regs *regs, int trapnr)
unsigned long error_code,
unsigned long fault_addr)
{ {
regs->ax = trapnr; regs->ax = trapnr;
return ex_handler_default(fixup, regs, trapnr, error_code, fault_addr); return ex_handler_default(fixup, regs);
} }
EXPORT_SYMBOL_GPL(ex_handler_fault);
/* /*
* Handler for when we fail to restore a task's FPU state. We should never get * Handler for when we fail to restore a task's FPU state. We should never get
@ -54,10 +39,8 @@ EXPORT_SYMBOL_GPL(ex_handler_fault);
* of vulnerability by restoring from the initial state (essentially, zeroing * of vulnerability by restoring from the initial state (essentially, zeroing
* out all the FPU registers) if we can't restore from the task's FPU state. * out all the FPU registers) if we can't restore from the task's FPU state.
*/ */
__visible bool ex_handler_fprestore(const struct exception_table_entry *fixup, static bool ex_handler_fprestore(const struct exception_table_entry *fixup,
struct pt_regs *regs, int trapnr, struct pt_regs *regs)
unsigned long error_code,
unsigned long fault_addr)
{ {
regs->ip = ex_fixup_addr(fixup); regs->ip = ex_fixup_addr(fixup);
@ -67,32 +50,23 @@ __visible bool ex_handler_fprestore(const struct exception_table_entry *fixup,
__restore_fpregs_from_fpstate(&init_fpstate, xfeatures_mask_fpstate()); __restore_fpregs_from_fpstate(&init_fpstate, xfeatures_mask_fpstate());
return true; return true;
} }
EXPORT_SYMBOL_GPL(ex_handler_fprestore);
__visible bool ex_handler_uaccess(const struct exception_table_entry *fixup, static bool ex_handler_uaccess(const struct exception_table_entry *fixup,
struct pt_regs *regs, int trapnr, struct pt_regs *regs, int trapnr)
unsigned long error_code,
unsigned long fault_addr)
{ {
WARN_ONCE(trapnr == X86_TRAP_GP, "General protection fault in user access. Non-canonical address?"); WARN_ONCE(trapnr == X86_TRAP_GP, "General protection fault in user access. Non-canonical address?");
return ex_handler_default(fixup, regs, trapnr, error_code, fault_addr); return ex_handler_default(fixup, regs);
} }
EXPORT_SYMBOL(ex_handler_uaccess);
__visible bool ex_handler_copy(const struct exception_table_entry *fixup, static bool ex_handler_copy(const struct exception_table_entry *fixup,
struct pt_regs *regs, int trapnr, struct pt_regs *regs, int trapnr)
unsigned long error_code,
unsigned long fault_addr)
{ {
WARN_ONCE(trapnr == X86_TRAP_GP, "General protection fault in user access. Non-canonical address?"); WARN_ONCE(trapnr == X86_TRAP_GP, "General protection fault in user access. Non-canonical address?");
return ex_handler_fault(fixup, regs, trapnr, error_code, fault_addr); return ex_handler_fault(fixup, regs, trapnr);
} }
EXPORT_SYMBOL(ex_handler_copy);
__visible bool ex_handler_rdmsr_unsafe(const struct exception_table_entry *fixup, static bool ex_handler_rdmsr_unsafe(const struct exception_table_entry *fixup,
struct pt_regs *regs, int trapnr, struct pt_regs *regs)
unsigned long error_code,
unsigned long fault_addr)
{ {
if (pr_warn_once("unchecked MSR access error: RDMSR from 0x%x at rIP: 0x%lx (%pS)\n", if (pr_warn_once("unchecked MSR access error: RDMSR from 0x%x at rIP: 0x%lx (%pS)\n",
(unsigned int)regs->cx, regs->ip, (void *)regs->ip)) (unsigned int)regs->cx, regs->ip, (void *)regs->ip))
@ -101,14 +75,11 @@ __visible bool ex_handler_rdmsr_unsafe(const struct exception_table_entry *fixup
/* Pretend that the read succeeded and returned 0. */ /* Pretend that the read succeeded and returned 0. */
regs->ax = 0; regs->ax = 0;
regs->dx = 0; regs->dx = 0;
return ex_handler_default(fixup, regs, trapnr, error_code, fault_addr); return ex_handler_default(fixup, regs);
} }
EXPORT_SYMBOL(ex_handler_rdmsr_unsafe);
__visible bool ex_handler_wrmsr_unsafe(const struct exception_table_entry *fixup, static bool ex_handler_wrmsr_unsafe(const struct exception_table_entry *fixup,
struct pt_regs *regs, int trapnr, struct pt_regs *regs)
unsigned long error_code,
unsigned long fault_addr)
{ {
if (pr_warn_once("unchecked MSR access error: WRMSR to 0x%x (tried to write 0x%08x%08x) at rIP: 0x%lx (%pS)\n", if (pr_warn_once("unchecked MSR access error: WRMSR to 0x%x (tried to write 0x%08x%08x) at rIP: 0x%lx (%pS)\n",
(unsigned int)regs->cx, (unsigned int)regs->dx, (unsigned int)regs->cx, (unsigned int)regs->dx,
@ -116,44 +87,29 @@ __visible bool ex_handler_wrmsr_unsafe(const struct exception_table_entry *fixup
show_stack_regs(regs); show_stack_regs(regs);
/* Pretend that the write succeeded. */ /* Pretend that the write succeeded. */
return ex_handler_default(fixup, regs, trapnr, error_code, fault_addr); return ex_handler_default(fixup, regs);
} }
EXPORT_SYMBOL(ex_handler_wrmsr_unsafe);
__visible bool ex_handler_clear_fs(const struct exception_table_entry *fixup, static bool ex_handler_clear_fs(const struct exception_table_entry *fixup,
struct pt_regs *regs, int trapnr, struct pt_regs *regs)
unsigned long error_code,
unsigned long fault_addr)
{ {
if (static_cpu_has(X86_BUG_NULL_SEG)) if (static_cpu_has(X86_BUG_NULL_SEG))
asm volatile ("mov %0, %%fs" : : "rm" (__USER_DS)); asm volatile ("mov %0, %%fs" : : "rm" (__USER_DS));
asm volatile ("mov %0, %%fs" : : "rm" (0)); asm volatile ("mov %0, %%fs" : : "rm" (0));
return ex_handler_default(fixup, regs, trapnr, error_code, fault_addr); return ex_handler_default(fixup, regs);
} }
EXPORT_SYMBOL(ex_handler_clear_fs);
enum handler_type ex_get_fault_handler_type(unsigned long ip) int ex_get_fixup_type(unsigned long ip)
{ {
const struct exception_table_entry *e; const struct exception_table_entry *e = search_exception_tables(ip);
ex_handler_t handler;
e = search_exception_tables(ip); return e ? e->type : EX_TYPE_NONE;
if (!e)
return EX_HANDLER_NONE;
handler = ex_fixup_handler(e);
if (handler == ex_handler_fault)
return EX_HANDLER_FAULT;
else if (handler == ex_handler_uaccess || handler == ex_handler_copy)
return EX_HANDLER_UACCESS;
else
return EX_HANDLER_OTHER;
} }
int fixup_exception(struct pt_regs *regs, int trapnr, unsigned long error_code, int fixup_exception(struct pt_regs *regs, int trapnr, unsigned long error_code,
unsigned long fault_addr) unsigned long fault_addr)
{ {
const struct exception_table_entry *e; const struct exception_table_entry *e;
ex_handler_t handler;
#ifdef CONFIG_PNPBIOS #ifdef CONFIG_PNPBIOS
if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) { if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
@ -173,8 +129,33 @@ int fixup_exception(struct pt_regs *regs, int trapnr, unsigned long error_code,
if (!e) if (!e)
return 0; return 0;
handler = ex_fixup_handler(e); switch (e->type) {
return handler(e, regs, trapnr, error_code, fault_addr); case EX_TYPE_DEFAULT:
return ex_handler_default(e, regs);
case EX_TYPE_FAULT:
return ex_handler_fault(e, regs, trapnr);
case EX_TYPE_UACCESS:
return ex_handler_uaccess(e, regs, trapnr);
case EX_TYPE_COPY:
return ex_handler_copy(e, regs, trapnr);
case EX_TYPE_CLEAR_FS:
return ex_handler_clear_fs(e, regs);
case EX_TYPE_FPU_RESTORE:
return ex_handler_fprestore(e, regs);
case EX_TYPE_RDMSR:
return ex_handler_rdmsr_unsafe(e, regs);
case EX_TYPE_WRMSR:
return ex_handler_wrmsr_unsafe(e, regs);
case EX_TYPE_BPF:
return ex_handler_bpf(e, regs);
case EX_TYPE_RDMSR_IN_MCE:
ex_handler_msr_mce(regs, false);
break;
case EX_TYPE_WRMSR_IN_MCE:
ex_handler_msr_mce(regs, true);
break;
}
BUG();
} }
extern unsigned int early_recursion_flag; extern unsigned int early_recursion_flag;

View File

@ -827,9 +827,7 @@ static int emit_atomic(u8 **pprog, u8 atomic_op,
return 0; return 0;
} }
static bool ex_handler_bpf(const struct exception_table_entry *x, bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs)
struct pt_regs *regs, int trapnr,
unsigned long error_code, unsigned long fault_addr)
{ {
u32 reg = x->fixup >> 8; u32 reg = x->fixup >> 8;
@ -1313,12 +1311,7 @@ st: if (is_imm8(insn->off))
} }
ex->insn = delta; ex->insn = delta;
delta = (u8 *)ex_handler_bpf - (u8 *)&ex->handler; ex->type = EX_TYPE_BPF;
if (!is_simm32(delta)) {
pr_err("extable->handler doesn't fit into 32-bit\n");
return -EFAULT;
}
ex->handler = delta;
if (dst_reg > BPF_REG_9) { if (dst_reg > BPF_REG_9) {
pr_err("verifier error\n"); pr_err("verifier error\n");

View File

@ -236,7 +236,7 @@ static void x86_sort_relative_table(char *extab_image, int image_size)
w(r(loc) + i, loc); w(r(loc) + i, loc);
w(r(loc + 1) + i + 4, loc + 1); w(r(loc + 1) + i + 4, loc + 1);
w(r(loc + 2) + i + 8, loc + 2); /* Don't touch the fixup type */
i += sizeof(uint32_t) * 3; i += sizeof(uint32_t) * 3;
} }
@ -249,7 +249,7 @@ static void x86_sort_relative_table(char *extab_image, int image_size)
w(r(loc) - i, loc); w(r(loc) - i, loc);
w(r(loc + 1) - (i + 4), loc + 1); w(r(loc + 1) - (i + 4), loc + 1);
w(r(loc + 2) - (i + 8), loc + 2); /* Don't touch the fixup type */
i += sizeof(uint32_t) * 3; i += sizeof(uint32_t) * 3;
} }