Skip to content

Commit a980c0e

Browse files
thejhKAGA-KOKO
authored andcommitted
x86/kprobes: Refactor kprobes_fault() like kprobe_exceptions_notify()
This is an extension of commit b506a9d ("x86: code clarification patch to Kprobes arch code"). As that commit explains, even though kprobe_running() can't be called with preemption enabled, preemption does not need to be disabled. If preemption is enabled, then this can't be originate from a kprobe. Also, use X86_TRAP_PF instead of 14. 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: Andy Lutomirski <[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 60c1f89 commit a980c0e

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

arch/x86/mm/fault.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,19 @@ kmmio_fault(struct pt_regs *regs, unsigned long addr)
4444

4545
static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
4646
{
47-
int ret = 0;
48-
49-
/* kprobe_running() needs smp_processor_id() */
50-
if (kprobes_built_in() && !user_mode(regs)) {
51-
preempt_disable();
52-
if (kprobe_running() && kprobe_fault_handler(regs, 14))
53-
ret = 1;
54-
preempt_enable();
55-
}
56-
57-
return ret;
47+
if (!kprobes_built_in())
48+
return 0;
49+
if (user_mode(regs))
50+
return 0;
51+
/*
52+
* To be potentially processing a kprobe fault and to be allowed to call
53+
* kprobe_running(), we have to be non-preemptible.
54+
*/
55+
if (preemptible())
56+
return 0;
57+
if (!kprobe_running())
58+
return 0;
59+
return kprobe_fault_handler(regs, X86_TRAP_PF);
5860
}
5961

6062
/*

0 commit comments

Comments
 (0)