Skip to content

Commit 76dee4a

Browse files
thejhKAGA-KOKO
authored andcommitted
x86/kprobes: Inline kprobe_exceptions_notify() into do_general_protection()
The opaque plumbing of #GP from do_general_protection() through notify_die() into kprobe_exceptions_notify() makes it hard to understand what's going on. Suggested-by: Andy Lutomirski <[email protected]> Signed-off-by: Jann Horn <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Kees Cook <[email protected]> Acked-by: Masami Hiramatsu <[email protected]> Cc: [email protected] Cc: [email protected] Cc: "Naveen N. Rao" <[email protected]> Cc: Anil S Keshavamurthy <[email protected]> Cc: "David S. Miller" <[email protected]> Cc: Alexander Viro <[email protected]> Cc: [email protected] Cc: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent a980c0e commit 76dee4a

File tree

2 files changed

+11
-30
lines changed

2 files changed

+11
-30
lines changed

arch/x86/kernel/kprobes/core.c

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,42 +1028,13 @@ int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
10281028
if (fixup_exception(regs, trapnr))
10291029
return 1;
10301030

1031-
/*
1032-
* fixup routine could not handle it,
1033-
* Let do_page_fault() fix it.
1034-
*/
1031+
/* fixup routine could not handle it. */
10351032
}
10361033

10371034
return 0;
10381035
}
10391036
NOKPROBE_SYMBOL(kprobe_fault_handler);
10401037

1041-
/*
1042-
* Wrapper routine for handling exceptions.
1043-
*/
1044-
int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
1045-
void *data)
1046-
{
1047-
struct die_args *args = data;
1048-
int ret = NOTIFY_DONE;
1049-
1050-
if (args->regs && user_mode(args->regs))
1051-
return ret;
1052-
1053-
if (val == DIE_GPF) {
1054-
/*
1055-
* To be potentially processing a kprobe fault and to
1056-
* trust the result from kprobe_running(), we have
1057-
* be non-preemptible.
1058-
*/
1059-
if (!preemptible() && kprobe_running() &&
1060-
kprobe_fault_handler(args->regs, args->trapnr))
1061-
ret = NOTIFY_STOP;
1062-
}
1063-
return ret;
1064-
}
1065-
NOKPROBE_SYMBOL(kprobe_exceptions_notify);
1066-
10671038
bool arch_within_kprobe_blacklist(unsigned long addr)
10681039
{
10691040
bool is_in_entry_trampoline_section = false;

arch/x86/kernel/traps.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,16 @@ do_general_protection(struct pt_regs *regs, long error_code)
556556

557557
tsk->thread.error_code = error_code;
558558
tsk->thread.trap_nr = X86_TRAP_GP;
559+
560+
/*
561+
* To be potentially processing a kprobe fault and to
562+
* trust the result from kprobe_running(), we have to
563+
* be non-preemptible.
564+
*/
565+
if (!preemptible() && kprobe_running() &&
566+
kprobe_fault_handler(regs, X86_TRAP_GP))
567+
return;
568+
559569
if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
560570
X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
561571
die("general protection fault", regs, error_code);

0 commit comments

Comments
 (0)