You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
Merge branch 'perf/kprobes' into perf/core
Conflicts: arch/x86/kernel/traps.c The kprobes enhancements are fully cooked, ship them upstream. Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
@@ -22,8 +22,9 @@ Appendix B: The kprobes sysctl interface
|
|||||||
|
|
||||||
Kprobes enables you to dynamically break into any kernel routine and
|
Kprobes enables you to dynamically break into any kernel routine and
|
||||||
collect debugging and performance information non-disruptively. You
|
collect debugging and performance information non-disruptively. You
|
||||||
can trap at almost any kernel code address, specifying a handler
|
can trap at almost any kernel code address(*), specifying a handler
|
||||||
routine to be invoked when the breakpoint is hit.
|
routine to be invoked when the breakpoint is hit.
|
||||||
|
(*: some parts of the kernel code can not be trapped, see 1.5 Blacklist)
|
||||||
|
|
||||||
There are currently three types of probes: kprobes, jprobes, and
|
There are currently three types of probes: kprobes, jprobes, and
|
||||||
kretprobes (also called return probes). A kprobe can be inserted
|
kretprobes (also called return probes). A kprobe can be inserted
|
||||||
@@ -273,6 +274,19 @@ using one of the following techniques:
|
|||||||
or
|
or
|
||||||
- Execute 'sysctl -w debug.kprobes_optimization=n'
|
- Execute 'sysctl -w debug.kprobes_optimization=n'
|
||||||
|
|
||||||
|
1.5 Blacklist
|
||||||
|
|
||||||
|
Kprobes can probe most of the kernel except itself. This means
|
||||||
|
that there are some functions where kprobes cannot probe. Probing
|
||||||
|
(trapping) such functions can cause a recursive trap (e.g. double
|
||||||
|
fault) or the nested probe handler may never be called.
|
||||||
|
Kprobes manages such functions as a blacklist.
|
||||||
|
If you want to add a function into the blacklist, you just need
|
||||||
|
to (1) include linux/kprobes.h and (2) use NOKPROBE_SYMBOL() macro
|
||||||
|
to specify a blacklisted function.
|
||||||
|
Kprobes checks the given probe address against the blacklist and
|
||||||
|
rejects registering it, if the given address is in the blacklist.
|
||||||
|
|
||||||
2. Architectures Supported
|
2. Architectures Supported
|
||||||
|
|
||||||
Kprobes, jprobes, and return probes are implemented on the following
|
Kprobes, jprobes, and return probes are implemented on the following
|
||||||
|
|||||||
@@ -57,6 +57,12 @@
|
|||||||
.long (from) - . ; \
|
.long (from) - . ; \
|
||||||
.long (to) - . + 0x7ffffff0 ; \
|
.long (to) - . + 0x7ffffff0 ; \
|
||||||
.popsection
|
.popsection
|
||||||
|
|
||||||
|
# define _ASM_NOKPROBE(entry) \
|
||||||
|
.pushsection "_kprobe_blacklist","aw" ; \
|
||||||
|
_ASM_ALIGN ; \
|
||||||
|
_ASM_PTR (entry); \
|
||||||
|
.popsection
|
||||||
#else
|
#else
|
||||||
# define _ASM_EXTABLE(from,to) \
|
# define _ASM_EXTABLE(from,to) \
|
||||||
" .pushsection \"__ex_table\",\"a\"\n" \
|
" .pushsection \"__ex_table\",\"a\"\n" \
|
||||||
@@ -71,6 +77,7 @@
|
|||||||
" .long (" #from ") - .\n" \
|
" .long (" #from ") - .\n" \
|
||||||
" .long (" #to ") - . + 0x7ffffff0\n" \
|
" .long (" #to ") - . + 0x7ffffff0\n" \
|
||||||
" .popsection\n"
|
" .popsection\n"
|
||||||
|
/* For C file, we already have NOKPROBE_SYMBOL macro */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _ASM_X86_ASM_H */
|
#endif /* _ASM_X86_ASM_H */
|
||||||
|
|||||||
@@ -116,4 +116,6 @@ struct kprobe_ctlblk {
|
|||||||
extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
|
extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
|
||||||
extern int kprobe_exceptions_notify(struct notifier_block *self,
|
extern int kprobe_exceptions_notify(struct notifier_block *self,
|
||||||
unsigned long val, void *data);
|
unsigned long val, void *data);
|
||||||
|
extern int kprobe_int3_handler(struct pt_regs *regs);
|
||||||
|
extern int kprobe_debug_handler(struct pt_regs *regs);
|
||||||
#endif /* _ASM_X86_KPROBES_H */
|
#endif /* _ASM_X86_KPROBES_H */
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ dotraplinkage void do_segment_not_present(struct pt_regs *, long);
|
|||||||
dotraplinkage void do_stack_segment(struct pt_regs *, long);
|
dotraplinkage void do_stack_segment(struct pt_regs *, long);
|
||||||
#ifdef CONFIG_X86_64
|
#ifdef CONFIG_X86_64
|
||||||
dotraplinkage void do_double_fault(struct pt_regs *, long);
|
dotraplinkage void do_double_fault(struct pt_regs *, long);
|
||||||
asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *);
|
asmlinkage struct pt_regs *sync_regs(struct pt_regs *);
|
||||||
#endif
|
#endif
|
||||||
dotraplinkage void do_general_protection(struct pt_regs *, long);
|
dotraplinkage void do_general_protection(struct pt_regs *, long);
|
||||||
dotraplinkage void do_page_fault(struct pt_regs *, unsigned long);
|
dotraplinkage void do_page_fault(struct pt_regs *, unsigned long);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include <linux/mutex.h>
|
#include <linux/mutex.h>
|
||||||
#include <linux/list.h>
|
#include <linux/list.h>
|
||||||
#include <linux/stringify.h>
|
#include <linux/stringify.h>
|
||||||
#include <linux/kprobes.h>
|
|
||||||
#include <linux/mm.h>
|
#include <linux/mm.h>
|
||||||
#include <linux/vmalloc.h>
|
#include <linux/vmalloc.h>
|
||||||
#include <linux/memory.h>
|
#include <linux/memory.h>
|
||||||
@@ -551,7 +550,7 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
|
|||||||
*
|
*
|
||||||
* Note: Must be called under text_mutex.
|
* Note: Must be called under text_mutex.
|
||||||
*/
|
*/
|
||||||
void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
|
void *text_poke(void *addr, const void *opcode, size_t len)
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
char *vaddr;
|
char *vaddr;
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ void arch_trigger_all_cpu_backtrace(void)
|
|||||||
smp_mb__after_clear_bit();
|
smp_mb__after_clear_bit();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __kprobes
|
static int
|
||||||
arch_trigger_all_cpu_backtrace_handler(unsigned int cmd, struct pt_regs *regs)
|
arch_trigger_all_cpu_backtrace_handler(unsigned int cmd, struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
int cpu;
|
int cpu;
|
||||||
@@ -80,6 +80,7 @@ arch_trigger_all_cpu_backtrace_handler(unsigned int cmd, struct pt_regs *regs)
|
|||||||
|
|
||||||
return NMI_DONE;
|
return NMI_DONE;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(arch_trigger_all_cpu_backtrace_handler);
|
||||||
|
|
||||||
static int __init register_trigger_all_cpu_backtrace(void)
|
static int __init register_trigger_all_cpu_backtrace(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
#include <linux/sched.h>
|
#include <linux/sched.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
|
#include <linux/kprobes.h>
|
||||||
#include <linux/kgdb.h>
|
#include <linux/kgdb.h>
|
||||||
#include <linux/smp.h>
|
#include <linux/smp.h>
|
||||||
#include <linux/io.h>
|
#include <linux/io.h>
|
||||||
@@ -1160,6 +1161,7 @@ int is_debug_stack(unsigned long addr)
|
|||||||
(addr <= __get_cpu_var(debug_stack_addr) &&
|
(addr <= __get_cpu_var(debug_stack_addr) &&
|
||||||
addr > (__get_cpu_var(debug_stack_addr) - DEBUG_STKSZ));
|
addr > (__get_cpu_var(debug_stack_addr) - DEBUG_STKSZ));
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(is_debug_stack);
|
||||||
|
|
||||||
DEFINE_PER_CPU(u32, debug_idt_ctr);
|
DEFINE_PER_CPU(u32, debug_idt_ctr);
|
||||||
|
|
||||||
@@ -1168,6 +1170,7 @@ void debug_stack_set_zero(void)
|
|||||||
this_cpu_inc(debug_idt_ctr);
|
this_cpu_inc(debug_idt_ctr);
|
||||||
load_current_idt();
|
load_current_idt();
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(debug_stack_set_zero);
|
||||||
|
|
||||||
void debug_stack_reset(void)
|
void debug_stack_reset(void)
|
||||||
{
|
{
|
||||||
@@ -1176,6 +1179,7 @@ void debug_stack_reset(void)
|
|||||||
if (this_cpu_dec_return(debug_idt_ctr) == 0)
|
if (this_cpu_dec_return(debug_idt_ctr) == 0)
|
||||||
load_current_idt();
|
load_current_idt();
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(debug_stack_reset);
|
||||||
|
|
||||||
#else /* CONFIG_X86_64 */
|
#else /* CONFIG_X86_64 */
|
||||||
|
|
||||||
|
|||||||
@@ -1293,7 +1293,7 @@ void perf_events_lapic_init(void)
|
|||||||
apic_write(APIC_LVTPC, APIC_DM_NMI);
|
apic_write(APIC_LVTPC, APIC_DM_NMI);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __kprobes
|
static int
|
||||||
perf_event_nmi_handler(unsigned int cmd, struct pt_regs *regs)
|
perf_event_nmi_handler(unsigned int cmd, struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
u64 start_clock;
|
u64 start_clock;
|
||||||
@@ -1311,6 +1311,7 @@ perf_event_nmi_handler(unsigned int cmd, struct pt_regs *regs)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(perf_event_nmi_handler);
|
||||||
|
|
||||||
struct event_constraint emptyconstraint;
|
struct event_constraint emptyconstraint;
|
||||||
struct event_constraint unconstrained;
|
struct event_constraint unconstrained;
|
||||||
|
|||||||
@@ -593,7 +593,7 @@ out:
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __kprobes
|
static int
|
||||||
perf_ibs_nmi_handler(unsigned int cmd, struct pt_regs *regs)
|
perf_ibs_nmi_handler(unsigned int cmd, struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
int handled = 0;
|
int handled = 0;
|
||||||
@@ -606,6 +606,7 @@ perf_ibs_nmi_handler(unsigned int cmd, struct pt_regs *regs)
|
|||||||
|
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(perf_ibs_nmi_handler);
|
||||||
|
|
||||||
static __init int perf_ibs_pmu_init(struct perf_ibs *perf_ibs, char *name)
|
static __init int perf_ibs_pmu_init(struct perf_ibs *perf_ibs, char *name)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
|
|||||||
static int die_owner = -1;
|
static int die_owner = -1;
|
||||||
static unsigned int die_nest_count;
|
static unsigned int die_nest_count;
|
||||||
|
|
||||||
unsigned __kprobes long oops_begin(void)
|
unsigned long oops_begin(void)
|
||||||
{
|
{
|
||||||
int cpu;
|
int cpu;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
@@ -223,8 +223,9 @@ unsigned __kprobes long oops_begin(void)
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(oops_begin);
|
EXPORT_SYMBOL_GPL(oops_begin);
|
||||||
|
NOKPROBE_SYMBOL(oops_begin);
|
||||||
|
|
||||||
void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
|
void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
|
||||||
{
|
{
|
||||||
if (regs && kexec_should_crash(current))
|
if (regs && kexec_should_crash(current))
|
||||||
crash_kexec(regs);
|
crash_kexec(regs);
|
||||||
@@ -247,8 +248,9 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
|
|||||||
panic("Fatal exception");
|
panic("Fatal exception");
|
||||||
do_exit(signr);
|
do_exit(signr);
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(oops_end);
|
||||||
|
|
||||||
int __kprobes __die(const char *str, struct pt_regs *regs, long err)
|
int __die(const char *str, struct pt_regs *regs, long err)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_X86_32
|
#ifdef CONFIG_X86_32
|
||||||
unsigned short ss;
|
unsigned short ss;
|
||||||
@@ -291,6 +293,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
|
|||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(__die);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is gone through when something in the kernel has done something bad
|
* This is gone through when something in the kernel has done something bad
|
||||||
|
|||||||
@@ -314,10 +314,6 @@ ENTRY(ret_from_kernel_thread)
|
|||||||
CFI_ENDPROC
|
CFI_ENDPROC
|
||||||
ENDPROC(ret_from_kernel_thread)
|
ENDPROC(ret_from_kernel_thread)
|
||||||
|
|
||||||
/*
|
|
||||||
* Interrupt exit functions should be protected against kprobes
|
|
||||||
*/
|
|
||||||
.pushsection .kprobes.text, "ax"
|
|
||||||
/*
|
/*
|
||||||
* Return to user mode is not as complex as all this looks,
|
* Return to user mode is not as complex as all this looks,
|
||||||
* but we want the default path for a system call return to
|
* but we want the default path for a system call return to
|
||||||
@@ -372,10 +368,6 @@ need_resched:
|
|||||||
END(resume_kernel)
|
END(resume_kernel)
|
||||||
#endif
|
#endif
|
||||||
CFI_ENDPROC
|
CFI_ENDPROC
|
||||||
/*
|
|
||||||
* End of kprobes section
|
|
||||||
*/
|
|
||||||
.popsection
|
|
||||||
|
|
||||||
/* SYSENTER_RETURN points to after the "sysenter" instruction in
|
/* SYSENTER_RETURN points to after the "sysenter" instruction in
|
||||||
the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
|
the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
|
||||||
@@ -495,10 +487,6 @@ sysexit_audit:
|
|||||||
PTGS_TO_GS_EX
|
PTGS_TO_GS_EX
|
||||||
ENDPROC(ia32_sysenter_target)
|
ENDPROC(ia32_sysenter_target)
|
||||||
|
|
||||||
/*
|
|
||||||
* syscall stub including irq exit should be protected against kprobes
|
|
||||||
*/
|
|
||||||
.pushsection .kprobes.text, "ax"
|
|
||||||
# system call handler stub
|
# system call handler stub
|
||||||
ENTRY(system_call)
|
ENTRY(system_call)
|
||||||
RING0_INT_FRAME # can't unwind into user space anyway
|
RING0_INT_FRAME # can't unwind into user space anyway
|
||||||
@@ -691,10 +679,6 @@ syscall_badsys:
|
|||||||
jmp resume_userspace
|
jmp resume_userspace
|
||||||
END(syscall_badsys)
|
END(syscall_badsys)
|
||||||
CFI_ENDPROC
|
CFI_ENDPROC
|
||||||
/*
|
|
||||||
* End of kprobes section
|
|
||||||
*/
|
|
||||||
.popsection
|
|
||||||
|
|
||||||
.macro FIXUP_ESPFIX_STACK
|
.macro FIXUP_ESPFIX_STACK
|
||||||
/*
|
/*
|
||||||
@@ -781,10 +765,6 @@ common_interrupt:
|
|||||||
ENDPROC(common_interrupt)
|
ENDPROC(common_interrupt)
|
||||||
CFI_ENDPROC
|
CFI_ENDPROC
|
||||||
|
|
||||||
/*
|
|
||||||
* Irq entries should be protected against kprobes
|
|
||||||
*/
|
|
||||||
.pushsection .kprobes.text, "ax"
|
|
||||||
#define BUILD_INTERRUPT3(name, nr, fn) \
|
#define BUILD_INTERRUPT3(name, nr, fn) \
|
||||||
ENTRY(name) \
|
ENTRY(name) \
|
||||||
RING0_INT_FRAME; \
|
RING0_INT_FRAME; \
|
||||||
@@ -961,10 +941,6 @@ ENTRY(spurious_interrupt_bug)
|
|||||||
jmp error_code
|
jmp error_code
|
||||||
CFI_ENDPROC
|
CFI_ENDPROC
|
||||||
END(spurious_interrupt_bug)
|
END(spurious_interrupt_bug)
|
||||||
/*
|
|
||||||
* End of kprobes section
|
|
||||||
*/
|
|
||||||
.popsection
|
|
||||||
|
|
||||||
#ifdef CONFIG_XEN
|
#ifdef CONFIG_XEN
|
||||||
/* Xen doesn't set %esp to be precisely what the normal sysenter
|
/* Xen doesn't set %esp to be precisely what the normal sysenter
|
||||||
@@ -1239,11 +1215,6 @@ return_to_handler:
|
|||||||
jmp *%ecx
|
jmp *%ecx
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
* Some functions should be protected against kprobes
|
|
||||||
*/
|
|
||||||
.pushsection .kprobes.text, "ax"
|
|
||||||
|
|
||||||
#ifdef CONFIG_TRACING
|
#ifdef CONFIG_TRACING
|
||||||
ENTRY(trace_page_fault)
|
ENTRY(trace_page_fault)
|
||||||
RING0_EC_FRAME
|
RING0_EC_FRAME
|
||||||
@@ -1453,7 +1424,3 @@ ENTRY(async_page_fault)
|
|||||||
END(async_page_fault)
|
END(async_page_fault)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
* End of kprobes section
|
|
||||||
*/
|
|
||||||
.popsection
|
|
||||||
|
|||||||
@@ -487,8 +487,6 @@ ENDPROC(native_usergs_sysret64)
|
|||||||
TRACE_IRQS_OFF
|
TRACE_IRQS_OFF
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
/* save complete stack frame */
|
|
||||||
.pushsection .kprobes.text, "ax"
|
|
||||||
ENTRY(save_paranoid)
|
ENTRY(save_paranoid)
|
||||||
XCPT_FRAME 1 RDI+8
|
XCPT_FRAME 1 RDI+8
|
||||||
cld
|
cld
|
||||||
@@ -517,7 +515,6 @@ ENTRY(save_paranoid)
|
|||||||
1: ret
|
1: ret
|
||||||
CFI_ENDPROC
|
CFI_ENDPROC
|
||||||
END(save_paranoid)
|
END(save_paranoid)
|
||||||
.popsection
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A newly forked process directly context switches into this address.
|
* A newly forked process directly context switches into this address.
|
||||||
@@ -975,10 +972,6 @@ END(interrupt)
|
|||||||
call \func
|
call \func
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
/*
|
|
||||||
* Interrupt entry/exit should be protected against kprobes
|
|
||||||
*/
|
|
||||||
.pushsection .kprobes.text, "ax"
|
|
||||||
/*
|
/*
|
||||||
* The interrupt stubs push (~vector+0x80) onto the stack and
|
* The interrupt stubs push (~vector+0x80) onto the stack and
|
||||||
* then jump to common_interrupt.
|
* then jump to common_interrupt.
|
||||||
@@ -1113,10 +1106,6 @@ ENTRY(retint_kernel)
|
|||||||
|
|
||||||
CFI_ENDPROC
|
CFI_ENDPROC
|
||||||
END(common_interrupt)
|
END(common_interrupt)
|
||||||
/*
|
|
||||||
* End of kprobes section
|
|
||||||
*/
|
|
||||||
.popsection
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* APIC interrupts.
|
* APIC interrupts.
|
||||||
@@ -1477,11 +1466,6 @@ apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
|
|||||||
hyperv_callback_vector hyperv_vector_handler
|
hyperv_callback_vector hyperv_vector_handler
|
||||||
#endif /* CONFIG_HYPERV */
|
#endif /* CONFIG_HYPERV */
|
||||||
|
|
||||||
/*
|
|
||||||
* Some functions should be protected against kprobes
|
|
||||||
*/
|
|
||||||
.pushsection .kprobes.text, "ax"
|
|
||||||
|
|
||||||
paranoidzeroentry_ist debug do_debug DEBUG_STACK
|
paranoidzeroentry_ist debug do_debug DEBUG_STACK
|
||||||
paranoidzeroentry_ist int3 do_int3 DEBUG_STACK
|
paranoidzeroentry_ist int3 do_int3 DEBUG_STACK
|
||||||
paranoiderrorentry stack_segment do_stack_segment
|
paranoiderrorentry stack_segment do_stack_segment
|
||||||
@@ -1898,7 +1882,3 @@ ENTRY(ignore_sysret)
|
|||||||
CFI_ENDPROC
|
CFI_ENDPROC
|
||||||
END(ignore_sysret)
|
END(ignore_sysret)
|
||||||
|
|
||||||
/*
|
|
||||||
* End of kprobes section
|
|
||||||
*/
|
|
||||||
.popsection
|
|
||||||
|
|||||||
@@ -32,7 +32,6 @@
|
|||||||
#include <linux/irqflags.h>
|
#include <linux/irqflags.h>
|
||||||
#include <linux/notifier.h>
|
#include <linux/notifier.h>
|
||||||
#include <linux/kallsyms.h>
|
#include <linux/kallsyms.h>
|
||||||
#include <linux/kprobes.h>
|
|
||||||
#include <linux/percpu.h>
|
#include <linux/percpu.h>
|
||||||
#include <linux/kdebug.h>
|
#include <linux/kdebug.h>
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
@@ -424,7 +423,7 @@ EXPORT_SYMBOL_GPL(hw_breakpoint_restore);
|
|||||||
* NOTIFY_STOP returned for all other cases
|
* NOTIFY_STOP returned for all other cases
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static int __kprobes hw_breakpoint_handler(struct die_args *args)
|
static int hw_breakpoint_handler(struct die_args *args)
|
||||||
{
|
{
|
||||||
int i, cpu, rc = NOTIFY_STOP;
|
int i, cpu, rc = NOTIFY_STOP;
|
||||||
struct perf_event *bp;
|
struct perf_event *bp;
|
||||||
@@ -511,7 +510,7 @@ static int __kprobes hw_breakpoint_handler(struct die_args *args)
|
|||||||
/*
|
/*
|
||||||
* Handle debug exception notifications.
|
* Handle debug exception notifications.
|
||||||
*/
|
*/
|
||||||
int __kprobes hw_breakpoint_exceptions_notify(
|
int hw_breakpoint_exceptions_notify(
|
||||||
struct notifier_block *unused, unsigned long val, void *data)
|
struct notifier_block *unused, unsigned long val, void *data)
|
||||||
{
|
{
|
||||||
if (val != DIE_DEBUG)
|
if (val != DIE_DEBUG)
|
||||||
|
|||||||
@@ -112,7 +112,8 @@ struct kretprobe_blackpoint kretprobe_blacklist[] = {
|
|||||||
|
|
||||||
const int kretprobe_blacklist_size = ARRAY_SIZE(kretprobe_blacklist);
|
const int kretprobe_blacklist_size = ARRAY_SIZE(kretprobe_blacklist);
|
||||||
|
|
||||||
static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
|
static nokprobe_inline void
|
||||||
|
__synthesize_relative_insn(void *from, void *to, u8 op)
|
||||||
{
|
{
|
||||||
struct __arch_relative_insn {
|
struct __arch_relative_insn {
|
||||||
u8 op;
|
u8 op;
|
||||||
@@ -125,21 +126,23 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
|
/* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
|
||||||
void __kprobes synthesize_reljump(void *from, void *to)
|
void synthesize_reljump(void *from, void *to)
|
||||||
{
|
{
|
||||||
__synthesize_relative_insn(from, to, RELATIVEJUMP_OPCODE);
|
__synthesize_relative_insn(from, to, RELATIVEJUMP_OPCODE);
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(synthesize_reljump);
|
||||||
|
|
||||||
/* Insert a call instruction at address 'from', which calls address 'to'.*/
|
/* Insert a call instruction at address 'from', which calls address 'to'.*/
|
||||||
void __kprobes synthesize_relcall(void *from, void *to)
|
void synthesize_relcall(void *from, void *to)
|
||||||
{
|
{
|
||||||
__synthesize_relative_insn(from, to, RELATIVECALL_OPCODE);
|
__synthesize_relative_insn(from, to, RELATIVECALL_OPCODE);
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(synthesize_relcall);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Skip the prefixes of the instruction.
|
* Skip the prefixes of the instruction.
|
||||||
*/
|
*/
|
||||||
static kprobe_opcode_t *__kprobes skip_prefixes(kprobe_opcode_t *insn)
|
static kprobe_opcode_t *skip_prefixes(kprobe_opcode_t *insn)
|
||||||
{
|
{
|
||||||
insn_attr_t attr;
|
insn_attr_t attr;
|
||||||
|
|
||||||
@@ -154,12 +157,13 @@ static kprobe_opcode_t *__kprobes skip_prefixes(kprobe_opcode_t *insn)
|
|||||||
#endif
|
#endif
|
||||||
return insn;
|
return insn;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(skip_prefixes);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns non-zero if opcode is boostable.
|
* Returns non-zero if opcode is boostable.
|
||||||
* RIP relative instructions are adjusted at copying time in 64 bits mode
|
* RIP relative instructions are adjusted at copying time in 64 bits mode
|
||||||
*/
|
*/
|
||||||
int __kprobes can_boost(kprobe_opcode_t *opcodes)
|
int can_boost(kprobe_opcode_t *opcodes)
|
||||||
{
|
{
|
||||||
kprobe_opcode_t opcode;
|
kprobe_opcode_t opcode;
|
||||||
kprobe_opcode_t *orig_opcodes = opcodes;
|
kprobe_opcode_t *orig_opcodes = opcodes;
|
||||||
@@ -260,7 +264,7 @@ unsigned long recover_probed_instruction(kprobe_opcode_t *buf, unsigned long add
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check if paddr is at an instruction boundary */
|
/* Check if paddr is at an instruction boundary */
|
||||||
static int __kprobes can_probe(unsigned long paddr)
|
static int can_probe(unsigned long paddr)
|
||||||
{
|
{
|
||||||
unsigned long addr, __addr, offset = 0;
|
unsigned long addr, __addr, offset = 0;
|
||||||
struct insn insn;
|
struct insn insn;
|
||||||
@@ -299,7 +303,7 @@ static int __kprobes can_probe(unsigned long paddr)
|
|||||||
/*
|
/*
|
||||||
* Returns non-zero if opcode modifies the interrupt flag.
|
* Returns non-zero if opcode modifies the interrupt flag.
|
||||||
*/
|
*/
|
||||||
static int __kprobes is_IF_modifier(kprobe_opcode_t *insn)
|
static int is_IF_modifier(kprobe_opcode_t *insn)
|
||||||
{
|
{
|
||||||
/* Skip prefixes */
|
/* Skip prefixes */
|
||||||
insn = skip_prefixes(insn);
|
insn = skip_prefixes(insn);
|
||||||
@@ -322,7 +326,7 @@ static int __kprobes is_IF_modifier(kprobe_opcode_t *insn)
|
|||||||
* If not, return null.
|
* If not, return null.
|
||||||
* Only applicable to 64-bit x86.
|
* Only applicable to 64-bit x86.
|
||||||
*/
|
*/
|
||||||
int __kprobes __copy_instruction(u8 *dest, u8 *src)
|
int __copy_instruction(u8 *dest, u8 *src)
|
||||||
{
|
{
|
||||||
struct insn insn;
|
struct insn insn;
|
||||||
kprobe_opcode_t buf[MAX_INSN_SIZE];
|
kprobe_opcode_t buf[MAX_INSN_SIZE];
|
||||||
@@ -365,7 +369,7 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
|
|||||||
return insn.length;
|
return insn.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __kprobes arch_copy_kprobe(struct kprobe *p)
|
static int arch_copy_kprobe(struct kprobe *p)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@@ -392,7 +396,7 @@ static int __kprobes arch_copy_kprobe(struct kprobe *p)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int __kprobes arch_prepare_kprobe(struct kprobe *p)
|
int arch_prepare_kprobe(struct kprobe *p)
|
||||||
{
|
{
|
||||||
if (alternatives_text_reserved(p->addr, p->addr))
|
if (alternatives_text_reserved(p->addr, p->addr))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -407,17 +411,17 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
|
|||||||
return arch_copy_kprobe(p);
|
return arch_copy_kprobe(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __kprobes arch_arm_kprobe(struct kprobe *p)
|
void arch_arm_kprobe(struct kprobe *p)
|
||||||
{
|
{
|
||||||
text_poke(p->addr, ((unsigned char []){BREAKPOINT_INSTRUCTION}), 1);
|
text_poke(p->addr, ((unsigned char []){BREAKPOINT_INSTRUCTION}), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __kprobes arch_disarm_kprobe(struct kprobe *p)
|
void arch_disarm_kprobe(struct kprobe *p)
|
||||||
{
|
{
|
||||||
text_poke(p->addr, &p->opcode, 1);
|
text_poke(p->addr, &p->opcode, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __kprobes arch_remove_kprobe(struct kprobe *p)
|
void arch_remove_kprobe(struct kprobe *p)
|
||||||
{
|
{
|
||||||
if (p->ainsn.insn) {
|
if (p->ainsn.insn) {
|
||||||
free_insn_slot(p->ainsn.insn, (p->ainsn.boostable == 1));
|
free_insn_slot(p->ainsn.insn, (p->ainsn.boostable == 1));
|
||||||
@@ -425,7 +429,8 @@ void __kprobes arch_remove_kprobe(struct kprobe *p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
|
static nokprobe_inline void
|
||||||
|
save_previous_kprobe(struct kprobe_ctlblk *kcb)
|
||||||
{
|
{
|
||||||
kcb->prev_kprobe.kp = kprobe_running();
|
kcb->prev_kprobe.kp = kprobe_running();
|
||||||
kcb->prev_kprobe.status = kcb->kprobe_status;
|
kcb->prev_kprobe.status = kcb->kprobe_status;
|
||||||
@@ -433,7 +438,8 @@ static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
|
|||||||
kcb->prev_kprobe.saved_flags = kcb->kprobe_saved_flags;
|
kcb->prev_kprobe.saved_flags = kcb->kprobe_saved_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
|
static nokprobe_inline void
|
||||||
|
restore_previous_kprobe(struct kprobe_ctlblk *kcb)
|
||||||
{
|
{
|
||||||
__this_cpu_write(current_kprobe, kcb->prev_kprobe.kp);
|
__this_cpu_write(current_kprobe, kcb->prev_kprobe.kp);
|
||||||
kcb->kprobe_status = kcb->prev_kprobe.status;
|
kcb->kprobe_status = kcb->prev_kprobe.status;
|
||||||
@@ -441,7 +447,8 @@ static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
|
|||||||
kcb->kprobe_saved_flags = kcb->prev_kprobe.saved_flags;
|
kcb->kprobe_saved_flags = kcb->prev_kprobe.saved_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
|
static nokprobe_inline void
|
||||||
|
set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
|
||||||
struct kprobe_ctlblk *kcb)
|
struct kprobe_ctlblk *kcb)
|
||||||
{
|
{
|
||||||
__this_cpu_write(current_kprobe, p);
|
__this_cpu_write(current_kprobe, p);
|
||||||
@@ -451,7 +458,7 @@ static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
|
|||||||
kcb->kprobe_saved_flags &= ~X86_EFLAGS_IF;
|
kcb->kprobe_saved_flags &= ~X86_EFLAGS_IF;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __kprobes clear_btf(void)
|
static nokprobe_inline void clear_btf(void)
|
||||||
{
|
{
|
||||||
if (test_thread_flag(TIF_BLOCKSTEP)) {
|
if (test_thread_flag(TIF_BLOCKSTEP)) {
|
||||||
unsigned long debugctl = get_debugctlmsr();
|
unsigned long debugctl = get_debugctlmsr();
|
||||||
@@ -461,7 +468,7 @@ static void __kprobes clear_btf(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __kprobes restore_btf(void)
|
static nokprobe_inline void restore_btf(void)
|
||||||
{
|
{
|
||||||
if (test_thread_flag(TIF_BLOCKSTEP)) {
|
if (test_thread_flag(TIF_BLOCKSTEP)) {
|
||||||
unsigned long debugctl = get_debugctlmsr();
|
unsigned long debugctl = get_debugctlmsr();
|
||||||
@@ -471,8 +478,7 @@ static void __kprobes restore_btf(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void __kprobes
|
void arch_prepare_kretprobe(struct kretprobe_instance *ri, struct pt_regs *regs)
|
||||||
arch_prepare_kretprobe(struct kretprobe_instance *ri, struct pt_regs *regs)
|
|
||||||
{
|
{
|
||||||
unsigned long *sara = stack_addr(regs);
|
unsigned long *sara = stack_addr(regs);
|
||||||
|
|
||||||
@@ -481,9 +487,10 @@ arch_prepare_kretprobe(struct kretprobe_instance *ri, struct pt_regs *regs)
|
|||||||
/* Replace the return addr with trampoline addr */
|
/* Replace the return addr with trampoline addr */
|
||||||
*sara = (unsigned long) &kretprobe_trampoline;
|
*sara = (unsigned long) &kretprobe_trampoline;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(arch_prepare_kretprobe);
|
||||||
|
|
||||||
static void __kprobes
|
static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
|
||||||
setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb, int reenter)
|
struct kprobe_ctlblk *kcb, int reenter)
|
||||||
{
|
{
|
||||||
if (setup_detour_execution(p, regs, reenter))
|
if (setup_detour_execution(p, regs, reenter))
|
||||||
return;
|
return;
|
||||||
@@ -519,22 +526,24 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
|
|||||||
else
|
else
|
||||||
regs->ip = (unsigned long)p->ainsn.insn;
|
regs->ip = (unsigned long)p->ainsn.insn;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(setup_singlestep);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We have reentered the kprobe_handler(), since another probe was hit while
|
* We have reentered the kprobe_handler(), since another probe was hit while
|
||||||
* within the handler. We save the original kprobes variables and just single
|
* within the handler. We save the original kprobes variables and just single
|
||||||
* step on the instruction of the new probe without calling any user handlers.
|
* step on the instruction of the new probe without calling any user handlers.
|
||||||
*/
|
*/
|
||||||
static int __kprobes
|
static int reenter_kprobe(struct kprobe *p, struct pt_regs *regs,
|
||||||
reenter_kprobe(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
|
struct kprobe_ctlblk *kcb)
|
||||||
{
|
{
|
||||||
switch (kcb->kprobe_status) {
|
switch (kcb->kprobe_status) {
|
||||||
case KPROBE_HIT_SSDONE:
|
case KPROBE_HIT_SSDONE:
|
||||||
case KPROBE_HIT_ACTIVE:
|
case KPROBE_HIT_ACTIVE:
|
||||||
|
case KPROBE_HIT_SS:
|
||||||
kprobes_inc_nmissed_count(p);
|
kprobes_inc_nmissed_count(p);
|
||||||
setup_singlestep(p, regs, kcb, 1);
|
setup_singlestep(p, regs, kcb, 1);
|
||||||
break;
|
break;
|
||||||
case KPROBE_HIT_SS:
|
case KPROBE_REENTER:
|
||||||
/* A probe has been hit in the codepath leading up to, or just
|
/* A probe has been hit in the codepath leading up to, or just
|
||||||
* after, single-stepping of a probed instruction. This entire
|
* after, single-stepping of a probed instruction. This entire
|
||||||
* codepath should strictly reside in .kprobes.text section.
|
* codepath should strictly reside in .kprobes.text section.
|
||||||
@@ -553,12 +562,13 @@ reenter_kprobe(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(reenter_kprobe);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Interrupts are disabled on entry as trap3 is an interrupt gate and they
|
* Interrupts are disabled on entry as trap3 is an interrupt gate and they
|
||||||
* remain disabled throughout this function.
|
* remain disabled throughout this function.
|
||||||
*/
|
*/
|
||||||
static int __kprobes kprobe_handler(struct pt_regs *regs)
|
int kprobe_int3_handler(struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
kprobe_opcode_t *addr;
|
kprobe_opcode_t *addr;
|
||||||
struct kprobe *p;
|
struct kprobe *p;
|
||||||
@@ -621,12 +631,13 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
|
|||||||
preempt_enable_no_resched();
|
preempt_enable_no_resched();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(kprobe_int3_handler);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* When a retprobed function returns, this code saves registers and
|
* When a retprobed function returns, this code saves registers and
|
||||||
* calls trampoline_handler() runs, which calls the kretprobe's handler.
|
* calls trampoline_handler() runs, which calls the kretprobe's handler.
|
||||||
*/
|
*/
|
||||||
static void __used __kprobes kretprobe_trampoline_holder(void)
|
static void __used kretprobe_trampoline_holder(void)
|
||||||
{
|
{
|
||||||
asm volatile (
|
asm volatile (
|
||||||
".global kretprobe_trampoline\n"
|
".global kretprobe_trampoline\n"
|
||||||
@@ -657,11 +668,13 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
|
|||||||
#endif
|
#endif
|
||||||
" ret\n");
|
" ret\n");
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(kretprobe_trampoline_holder);
|
||||||
|
NOKPROBE_SYMBOL(kretprobe_trampoline);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called from kretprobe_trampoline
|
* Called from kretprobe_trampoline
|
||||||
*/
|
*/
|
||||||
__visible __used __kprobes void *trampoline_handler(struct pt_regs *regs)
|
__visible __used void *trampoline_handler(struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
struct kretprobe_instance *ri = NULL;
|
struct kretprobe_instance *ri = NULL;
|
||||||
struct hlist_head *head, empty_rp;
|
struct hlist_head *head, empty_rp;
|
||||||
@@ -747,6 +760,7 @@ __visible __used __kprobes void *trampoline_handler(struct pt_regs *regs)
|
|||||||
}
|
}
|
||||||
return (void *)orig_ret_address;
|
return (void *)orig_ret_address;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(trampoline_handler);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called after single-stepping. p->addr is the address of the
|
* Called after single-stepping. p->addr is the address of the
|
||||||
@@ -775,8 +789,8 @@ __visible __used __kprobes void *trampoline_handler(struct pt_regs *regs)
|
|||||||
* jump instruction after the copied instruction, that jumps to the next
|
* jump instruction after the copied instruction, that jumps to the next
|
||||||
* instruction after the probepoint.
|
* instruction after the probepoint.
|
||||||
*/
|
*/
|
||||||
static void __kprobes
|
static void resume_execution(struct kprobe *p, struct pt_regs *regs,
|
||||||
resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
|
struct kprobe_ctlblk *kcb)
|
||||||
{
|
{
|
||||||
unsigned long *tos = stack_addr(regs);
|
unsigned long *tos = stack_addr(regs);
|
||||||
unsigned long copy_ip = (unsigned long)p->ainsn.insn;
|
unsigned long copy_ip = (unsigned long)p->ainsn.insn;
|
||||||
@@ -851,12 +865,13 @@ resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
|
|||||||
no_change:
|
no_change:
|
||||||
restore_btf();
|
restore_btf();
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(resume_execution);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Interrupts are disabled on entry as trap1 is an interrupt gate and they
|
* Interrupts are disabled on entry as trap1 is an interrupt gate and they
|
||||||
* remain disabled throughout this function.
|
* remain disabled throughout this function.
|
||||||
*/
|
*/
|
||||||
static int __kprobes post_kprobe_handler(struct pt_regs *regs)
|
int kprobe_debug_handler(struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
struct kprobe *cur = kprobe_running();
|
struct kprobe *cur = kprobe_running();
|
||||||
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
|
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
|
||||||
@@ -891,8 +906,9 @@ out:
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(kprobe_debug_handler);
|
||||||
|
|
||||||
int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
|
int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
|
||||||
{
|
{
|
||||||
struct kprobe *cur = kprobe_running();
|
struct kprobe *cur = kprobe_running();
|
||||||
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
|
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
|
||||||
@@ -949,12 +965,13 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(kprobe_fault_handler);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wrapper routine for handling exceptions.
|
* Wrapper routine for handling exceptions.
|
||||||
*/
|
*/
|
||||||
int __kprobes
|
int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
|
||||||
kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
struct die_args *args = data;
|
struct die_args *args = data;
|
||||||
int ret = NOTIFY_DONE;
|
int ret = NOTIFY_DONE;
|
||||||
@@ -962,22 +979,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
|
|||||||
if (args->regs && user_mode_vm(args->regs))
|
if (args->regs && user_mode_vm(args->regs))
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
switch (val) {
|
if (val == DIE_GPF) {
|
||||||
case DIE_INT3:
|
|
||||||
if (kprobe_handler(args->regs))
|
|
||||||
ret = NOTIFY_STOP;
|
|
||||||
break;
|
|
||||||
case DIE_DEBUG:
|
|
||||||
if (post_kprobe_handler(args->regs)) {
|
|
||||||
/*
|
|
||||||
* Reset the BS bit in dr6 (pointed by args->err) to
|
|
||||||
* denote completion of processing
|
|
||||||
*/
|
|
||||||
(*(unsigned long *)ERR_PTR(args->err)) &= ~DR_STEP;
|
|
||||||
ret = NOTIFY_STOP;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DIE_GPF:
|
|
||||||
/*
|
/*
|
||||||
* To be potentially processing a kprobe fault and to
|
* To be potentially processing a kprobe fault and to
|
||||||
* trust the result from kprobe_running(), we have
|
* trust the result from kprobe_running(), we have
|
||||||
@@ -986,14 +988,12 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
|
|||||||
if (!preemptible() && kprobe_running() &&
|
if (!preemptible() && kprobe_running() &&
|
||||||
kprobe_fault_handler(args->regs, args->trapnr))
|
kprobe_fault_handler(args->regs, args->trapnr))
|
||||||
ret = NOTIFY_STOP;
|
ret = NOTIFY_STOP;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(kprobe_exceptions_notify);
|
||||||
|
|
||||||
int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
|
int setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
struct jprobe *jp = container_of(p, struct jprobe, kp);
|
struct jprobe *jp = container_of(p, struct jprobe, kp);
|
||||||
unsigned long addr;
|
unsigned long addr;
|
||||||
@@ -1017,8 +1017,9 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
|
|||||||
regs->ip = (unsigned long)(jp->entry);
|
regs->ip = (unsigned long)(jp->entry);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(setjmp_pre_handler);
|
||||||
|
|
||||||
void __kprobes jprobe_return(void)
|
void jprobe_return(void)
|
||||||
{
|
{
|
||||||
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
|
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
|
||||||
|
|
||||||
@@ -1034,8 +1035,10 @@ void __kprobes jprobe_return(void)
|
|||||||
" nop \n"::"b"
|
" nop \n"::"b"
|
||||||
(kcb->jprobe_saved_sp):"memory");
|
(kcb->jprobe_saved_sp):"memory");
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(jprobe_return);
|
||||||
|
NOKPROBE_SYMBOL(jprobe_return_end);
|
||||||
|
|
||||||
int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
|
int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
|
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
|
||||||
u8 *addr = (u8 *) (regs->ip - 1);
|
u8 *addr = (u8 *) (regs->ip - 1);
|
||||||
@@ -1063,13 +1066,22 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(longjmp_break_handler);
|
||||||
|
|
||||||
|
bool arch_within_kprobe_blacklist(unsigned long addr)
|
||||||
|
{
|
||||||
|
return (addr >= (unsigned long)__kprobes_text_start &&
|
||||||
|
addr < (unsigned long)__kprobes_text_end) ||
|
||||||
|
(addr >= (unsigned long)__entry_text_start &&
|
||||||
|
addr < (unsigned long)__entry_text_end);
|
||||||
|
}
|
||||||
|
|
||||||
int __init arch_init_kprobes(void)
|
int __init arch_init_kprobes(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int __kprobes arch_trampoline_kprobe(struct kprobe *p)
|
int arch_trampoline_kprobe(struct kprobe *p)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,8 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
static int __skip_singlestep(struct kprobe *p, struct pt_regs *regs,
|
static nokprobe_inline
|
||||||
|
int __skip_singlestep(struct kprobe *p, struct pt_regs *regs,
|
||||||
struct kprobe_ctlblk *kcb)
|
struct kprobe_ctlblk *kcb)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -41,7 +42,7 @@ static int __skip_singlestep(struct kprobe *p, struct pt_regs *regs,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int __kprobes skip_singlestep(struct kprobe *p, struct pt_regs *regs,
|
int skip_singlestep(struct kprobe *p, struct pt_regs *regs,
|
||||||
struct kprobe_ctlblk *kcb)
|
struct kprobe_ctlblk *kcb)
|
||||||
{
|
{
|
||||||
if (kprobe_ftrace(p))
|
if (kprobe_ftrace(p))
|
||||||
@@ -49,9 +50,10 @@ int __kprobes skip_singlestep(struct kprobe *p, struct pt_regs *regs,
|
|||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(skip_singlestep);
|
||||||
|
|
||||||
/* Ftrace callback handler for kprobes */
|
/* Ftrace callback handler for kprobes */
|
||||||
void __kprobes kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
|
void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
|
||||||
struct ftrace_ops *ops, struct pt_regs *regs)
|
struct ftrace_ops *ops, struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
struct kprobe *p;
|
struct kprobe *p;
|
||||||
@@ -84,8 +86,9 @@ void __kprobes kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
|
|||||||
end:
|
end:
|
||||||
local_irq_restore(flags);
|
local_irq_restore(flags);
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(kprobe_ftrace_handler);
|
||||||
|
|
||||||
int __kprobes arch_prepare_kprobe_ftrace(struct kprobe *p)
|
int arch_prepare_kprobe_ftrace(struct kprobe *p)
|
||||||
{
|
{
|
||||||
p->ainsn.insn = NULL;
|
p->ainsn.insn = NULL;
|
||||||
p->ainsn.boostable = -1;
|
p->ainsn.boostable = -1;
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ found:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
|
/* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
|
||||||
static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
|
static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_X86_64
|
#ifdef CONFIG_X86_64
|
||||||
*addr++ = 0x48;
|
*addr++ = 0x48;
|
||||||
@@ -138,7 +138,8 @@ asm (
|
|||||||
#define INT3_SIZE sizeof(kprobe_opcode_t)
|
#define INT3_SIZE sizeof(kprobe_opcode_t)
|
||||||
|
|
||||||
/* Optimized kprobe call back function: called from optinsn */
|
/* Optimized kprobe call back function: called from optinsn */
|
||||||
static void __kprobes optimized_callback(struct optimized_kprobe *op, struct pt_regs *regs)
|
static void
|
||||||
|
optimized_callback(struct optimized_kprobe *op, struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
|
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
@@ -168,8 +169,9 @@ static void __kprobes optimized_callback(struct optimized_kprobe *op, struct pt_
|
|||||||
}
|
}
|
||||||
local_irq_restore(flags);
|
local_irq_restore(flags);
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(optimized_callback);
|
||||||
|
|
||||||
static int __kprobes copy_optimized_instructions(u8 *dest, u8 *src)
|
static int copy_optimized_instructions(u8 *dest, u8 *src)
|
||||||
{
|
{
|
||||||
int len = 0, ret;
|
int len = 0, ret;
|
||||||
|
|
||||||
@@ -189,7 +191,7 @@ static int __kprobes copy_optimized_instructions(u8 *dest, u8 *src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check whether insn is indirect jump */
|
/* Check whether insn is indirect jump */
|
||||||
static int __kprobes insn_is_indirect_jump(struct insn *insn)
|
static int insn_is_indirect_jump(struct insn *insn)
|
||||||
{
|
{
|
||||||
return ((insn->opcode.bytes[0] == 0xff &&
|
return ((insn->opcode.bytes[0] == 0xff &&
|
||||||
(X86_MODRM_REG(insn->modrm.value) & 6) == 4) || /* Jump */
|
(X86_MODRM_REG(insn->modrm.value) & 6) == 4) || /* Jump */
|
||||||
@@ -224,7 +226,7 @@ static int insn_jump_into_range(struct insn *insn, unsigned long start, int len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Decode whole function to ensure any instructions don't jump into target */
|
/* Decode whole function to ensure any instructions don't jump into target */
|
||||||
static int __kprobes can_optimize(unsigned long paddr)
|
static int can_optimize(unsigned long paddr)
|
||||||
{
|
{
|
||||||
unsigned long addr, size = 0, offset = 0;
|
unsigned long addr, size = 0, offset = 0;
|
||||||
struct insn insn;
|
struct insn insn;
|
||||||
@@ -275,7 +277,7 @@ static int __kprobes can_optimize(unsigned long paddr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check optimized_kprobe can actually be optimized. */
|
/* Check optimized_kprobe can actually be optimized. */
|
||||||
int __kprobes arch_check_optimized_kprobe(struct optimized_kprobe *op)
|
int arch_check_optimized_kprobe(struct optimized_kprobe *op)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct kprobe *p;
|
struct kprobe *p;
|
||||||
@@ -290,15 +292,15 @@ int __kprobes arch_check_optimized_kprobe(struct optimized_kprobe *op)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check the addr is within the optimized instructions. */
|
/* Check the addr is within the optimized instructions. */
|
||||||
int __kprobes
|
int arch_within_optimized_kprobe(struct optimized_kprobe *op,
|
||||||
arch_within_optimized_kprobe(struct optimized_kprobe *op, unsigned long addr)
|
unsigned long addr)
|
||||||
{
|
{
|
||||||
return ((unsigned long)op->kp.addr <= addr &&
|
return ((unsigned long)op->kp.addr <= addr &&
|
||||||
(unsigned long)op->kp.addr + op->optinsn.size > addr);
|
(unsigned long)op->kp.addr + op->optinsn.size > addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free optimized instruction slot */
|
/* Free optimized instruction slot */
|
||||||
static __kprobes
|
static
|
||||||
void __arch_remove_optimized_kprobe(struct optimized_kprobe *op, int dirty)
|
void __arch_remove_optimized_kprobe(struct optimized_kprobe *op, int dirty)
|
||||||
{
|
{
|
||||||
if (op->optinsn.insn) {
|
if (op->optinsn.insn) {
|
||||||
@@ -308,7 +310,7 @@ void __arch_remove_optimized_kprobe(struct optimized_kprobe *op, int dirty)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void __kprobes arch_remove_optimized_kprobe(struct optimized_kprobe *op)
|
void arch_remove_optimized_kprobe(struct optimized_kprobe *op)
|
||||||
{
|
{
|
||||||
__arch_remove_optimized_kprobe(op, 1);
|
__arch_remove_optimized_kprobe(op, 1);
|
||||||
}
|
}
|
||||||
@@ -318,7 +320,7 @@ void __kprobes arch_remove_optimized_kprobe(struct optimized_kprobe *op)
|
|||||||
* Target instructions MUST be relocatable (checked inside)
|
* Target instructions MUST be relocatable (checked inside)
|
||||||
* This is called when new aggr(opt)probe is allocated or reused.
|
* This is called when new aggr(opt)probe is allocated or reused.
|
||||||
*/
|
*/
|
||||||
int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
|
int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
|
||||||
{
|
{
|
||||||
u8 *buf;
|
u8 *buf;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -372,7 +374,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
|
|||||||
* Replace breakpoints (int3) with relative jumps.
|
* Replace breakpoints (int3) with relative jumps.
|
||||||
* Caller must call with locking kprobe_mutex and text_mutex.
|
* Caller must call with locking kprobe_mutex and text_mutex.
|
||||||
*/
|
*/
|
||||||
void __kprobes arch_optimize_kprobes(struct list_head *oplist)
|
void arch_optimize_kprobes(struct list_head *oplist)
|
||||||
{
|
{
|
||||||
struct optimized_kprobe *op, *tmp;
|
struct optimized_kprobe *op, *tmp;
|
||||||
u8 insn_buf[RELATIVEJUMP_SIZE];
|
u8 insn_buf[RELATIVEJUMP_SIZE];
|
||||||
@@ -398,7 +400,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Replace a relative jump with a breakpoint (int3). */
|
/* Replace a relative jump with a breakpoint (int3). */
|
||||||
void __kprobes arch_unoptimize_kprobe(struct optimized_kprobe *op)
|
void arch_unoptimize_kprobe(struct optimized_kprobe *op)
|
||||||
{
|
{
|
||||||
u8 insn_buf[RELATIVEJUMP_SIZE];
|
u8 insn_buf[RELATIVEJUMP_SIZE];
|
||||||
|
|
||||||
@@ -424,8 +426,7 @@ extern void arch_unoptimize_kprobes(struct list_head *oplist,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int __kprobes
|
int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
|
||||||
setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
|
|
||||||
{
|
{
|
||||||
struct optimized_kprobe *op;
|
struct optimized_kprobe *op;
|
||||||
|
|
||||||
@@ -441,3 +442,4 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(setup_detour_execution);
|
||||||
|
|||||||
@@ -251,8 +251,9 @@ u32 kvm_read_and_reset_pf_reason(void)
|
|||||||
return reason;
|
return reason;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(kvm_read_and_reset_pf_reason);
|
EXPORT_SYMBOL_GPL(kvm_read_and_reset_pf_reason);
|
||||||
|
NOKPROBE_SYMBOL(kvm_read_and_reset_pf_reason);
|
||||||
|
|
||||||
dotraplinkage void __kprobes
|
dotraplinkage void
|
||||||
do_async_page_fault(struct pt_regs *regs, unsigned long error_code)
|
do_async_page_fault(struct pt_regs *regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
enum ctx_state prev_state;
|
enum ctx_state prev_state;
|
||||||
@@ -276,6 +277,7 @@ do_async_page_fault(struct pt_regs *regs, unsigned long error_code)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(do_async_page_fault);
|
||||||
|
|
||||||
static void __init paravirt_ops_setup(void)
|
static void __init paravirt_ops_setup(void)
|
||||||
{
|
{
|
||||||
|
|||||||
+12
-6
@@ -110,7 +110,7 @@ static void nmi_max_handler(struct irq_work *w)
|
|||||||
a->handler, whole_msecs, decimal_msecs);
|
a->handler, whole_msecs, decimal_msecs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
|
static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
|
||||||
{
|
{
|
||||||
struct nmi_desc *desc = nmi_to_desc(type);
|
struct nmi_desc *desc = nmi_to_desc(type);
|
||||||
struct nmiaction *a;
|
struct nmiaction *a;
|
||||||
@@ -146,6 +146,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
|
|||||||
/* return total number of NMI events handled */
|
/* return total number of NMI events handled */
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(nmi_handle);
|
||||||
|
|
||||||
int __register_nmi_handler(unsigned int type, struct nmiaction *action)
|
int __register_nmi_handler(unsigned int type, struct nmiaction *action)
|
||||||
{
|
{
|
||||||
@@ -208,7 +209,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(unregister_nmi_handler);
|
EXPORT_SYMBOL_GPL(unregister_nmi_handler);
|
||||||
|
|
||||||
static __kprobes void
|
static void
|
||||||
pci_serr_error(unsigned char reason, struct pt_regs *regs)
|
pci_serr_error(unsigned char reason, struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
/* check to see if anyone registered against these types of errors */
|
/* check to see if anyone registered against these types of errors */
|
||||||
@@ -238,8 +239,9 @@ pci_serr_error(unsigned char reason, struct pt_regs *regs)
|
|||||||
reason = (reason & NMI_REASON_CLEAR_MASK) | NMI_REASON_CLEAR_SERR;
|
reason = (reason & NMI_REASON_CLEAR_MASK) | NMI_REASON_CLEAR_SERR;
|
||||||
outb(reason, NMI_REASON_PORT);
|
outb(reason, NMI_REASON_PORT);
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(pci_serr_error);
|
||||||
|
|
||||||
static __kprobes void
|
static void
|
||||||
io_check_error(unsigned char reason, struct pt_regs *regs)
|
io_check_error(unsigned char reason, struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
@@ -269,8 +271,9 @@ io_check_error(unsigned char reason, struct pt_regs *regs)
|
|||||||
reason &= ~NMI_REASON_CLEAR_IOCHK;
|
reason &= ~NMI_REASON_CLEAR_IOCHK;
|
||||||
outb(reason, NMI_REASON_PORT);
|
outb(reason, NMI_REASON_PORT);
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(io_check_error);
|
||||||
|
|
||||||
static __kprobes void
|
static void
|
||||||
unknown_nmi_error(unsigned char reason, struct pt_regs *regs)
|
unknown_nmi_error(unsigned char reason, struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
int handled;
|
int handled;
|
||||||
@@ -298,11 +301,12 @@ unknown_nmi_error(unsigned char reason, struct pt_regs *regs)
|
|||||||
|
|
||||||
pr_emerg("Dazed and confused, but trying to continue\n");
|
pr_emerg("Dazed and confused, but trying to continue\n");
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(unknown_nmi_error);
|
||||||
|
|
||||||
static DEFINE_PER_CPU(bool, swallow_nmi);
|
static DEFINE_PER_CPU(bool, swallow_nmi);
|
||||||
static DEFINE_PER_CPU(unsigned long, last_nmi_rip);
|
static DEFINE_PER_CPU(unsigned long, last_nmi_rip);
|
||||||
|
|
||||||
static __kprobes void default_do_nmi(struct pt_regs *regs)
|
static void default_do_nmi(struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
unsigned char reason = 0;
|
unsigned char reason = 0;
|
||||||
int handled;
|
int handled;
|
||||||
@@ -401,6 +405,7 @@ static __kprobes void default_do_nmi(struct pt_regs *regs)
|
|||||||
else
|
else
|
||||||
unknown_nmi_error(reason, regs);
|
unknown_nmi_error(reason, regs);
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(default_do_nmi);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NMIs can hit breakpoints which will cause it to lose its
|
* NMIs can hit breakpoints which will cause it to lose its
|
||||||
@@ -520,7 +525,7 @@ static inline void nmi_nesting_postprocess(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dotraplinkage notrace __kprobes void
|
dotraplinkage notrace void
|
||||||
do_nmi(struct pt_regs *regs, long error_code)
|
do_nmi(struct pt_regs *regs, long error_code)
|
||||||
{
|
{
|
||||||
nmi_nesting_preprocess(regs);
|
nmi_nesting_preprocess(regs);
|
||||||
@@ -537,6 +542,7 @@ do_nmi(struct pt_regs *regs, long error_code)
|
|||||||
/* On i386, may loop back to preprocess */
|
/* On i386, may loop back to preprocess */
|
||||||
nmi_nesting_postprocess();
|
nmi_nesting_postprocess();
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(do_nmi);
|
||||||
|
|
||||||
void stop_nmi(void)
|
void stop_nmi(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <linux/efi.h>
|
#include <linux/efi.h>
|
||||||
#include <linux/bcd.h>
|
#include <linux/bcd.h>
|
||||||
#include <linux/highmem.h>
|
#include <linux/highmem.h>
|
||||||
|
#include <linux/kprobes.h>
|
||||||
|
|
||||||
#include <asm/bug.h>
|
#include <asm/bug.h>
|
||||||
#include <asm/paravirt.h>
|
#include <asm/paravirt.h>
|
||||||
@@ -389,6 +390,11 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
|
|||||||
.end_context_switch = paravirt_nop,
|
.end_context_switch = paravirt_nop,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* At this point, native_get/set_debugreg has real function entries */
|
||||||
|
NOKPROBE_SYMBOL(native_get_debugreg);
|
||||||
|
NOKPROBE_SYMBOL(native_set_debugreg);
|
||||||
|
NOKPROBE_SYMBOL(native_load_idt);
|
||||||
|
|
||||||
struct pv_apic_ops pv_apic_ops = {
|
struct pv_apic_ops pv_apic_ops = {
|
||||||
#ifdef CONFIG_X86_LOCAL_APIC
|
#ifdef CONFIG_X86_LOCAL_APIC
|
||||||
.startup_ipi_hook = paravirt_nop,
|
.startup_ipi_hook = paravirt_nop,
|
||||||
|
|||||||
+25
-10
@@ -107,7 +107,7 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
|
|||||||
preempt_count_dec();
|
preempt_count_dec();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __kprobes
|
static nokprobe_inline int
|
||||||
do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
|
do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
|
||||||
struct pt_regs *regs, long error_code)
|
struct pt_regs *regs, long error_code)
|
||||||
{
|
{
|
||||||
@@ -168,7 +168,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __kprobes
|
static void
|
||||||
do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
|
do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
|
||||||
long error_code, siginfo_t *info)
|
long error_code, siginfo_t *info)
|
||||||
{
|
{
|
||||||
@@ -202,6 +202,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
|
|||||||
|
|
||||||
force_sig_info(signr, info ?: SEND_SIG_PRIV, tsk);
|
force_sig_info(signr, info ?: SEND_SIG_PRIV, tsk);
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(do_trap);
|
||||||
|
|
||||||
static void do_error_trap(struct pt_regs *regs, long error_code, char *str,
|
static void do_error_trap(struct pt_regs *regs, long error_code, char *str,
|
||||||
unsigned long trapnr, int signr)
|
unsigned long trapnr, int signr)
|
||||||
@@ -277,7 +278,7 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dotraplinkage void __kprobes
|
dotraplinkage void
|
||||||
do_general_protection(struct pt_regs *regs, long error_code)
|
do_general_protection(struct pt_regs *regs, long error_code)
|
||||||
{
|
{
|
||||||
struct task_struct *tsk;
|
struct task_struct *tsk;
|
||||||
@@ -323,9 +324,10 @@ do_general_protection(struct pt_regs *regs, long error_code)
|
|||||||
exit:
|
exit:
|
||||||
exception_exit(prev_state);
|
exception_exit(prev_state);
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(do_general_protection);
|
||||||
|
|
||||||
/* May run on IST stack. */
|
/* May run on IST stack. */
|
||||||
dotraplinkage void __kprobes notrace do_int3(struct pt_regs *regs, long error_code)
|
dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code)
|
||||||
{
|
{
|
||||||
enum ctx_state prev_state;
|
enum ctx_state prev_state;
|
||||||
|
|
||||||
@@ -341,13 +343,18 @@ dotraplinkage void __kprobes notrace do_int3(struct pt_regs *regs, long error_co
|
|||||||
if (poke_int3_handler(regs))
|
if (poke_int3_handler(regs))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
prev_state = exception_enter();
|
|
||||||
#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
|
#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
|
||||||
if (kgdb_ll_trap(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP,
|
if (kgdb_ll_trap(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP,
|
||||||
SIGTRAP) == NOTIFY_STOP)
|
SIGTRAP) == NOTIFY_STOP)
|
||||||
goto exit;
|
goto exit;
|
||||||
#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
|
#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
|
||||||
|
|
||||||
|
#ifdef CONFIG_KPROBES
|
||||||
|
if (kprobe_int3_handler(regs))
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
prev_state = exception_enter();
|
||||||
|
|
||||||
if (notify_die(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP,
|
if (notify_die(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP,
|
||||||
SIGTRAP) == NOTIFY_STOP)
|
SIGTRAP) == NOTIFY_STOP)
|
||||||
goto exit;
|
goto exit;
|
||||||
@@ -364,6 +371,7 @@ dotraplinkage void __kprobes notrace do_int3(struct pt_regs *regs, long error_co
|
|||||||
exit:
|
exit:
|
||||||
exception_exit(prev_state);
|
exception_exit(prev_state);
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(do_int3);
|
||||||
|
|
||||||
#ifdef CONFIG_X86_64
|
#ifdef CONFIG_X86_64
|
||||||
/*
|
/*
|
||||||
@@ -371,7 +379,7 @@ exit:
|
|||||||
* for scheduling or signal handling. The actual stack switch is done in
|
* for scheduling or signal handling. The actual stack switch is done in
|
||||||
* entry.S
|
* entry.S
|
||||||
*/
|
*/
|
||||||
asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs)
|
asmlinkage struct pt_regs *sync_regs(struct pt_regs *eregs)
|
||||||
{
|
{
|
||||||
struct pt_regs *regs = eregs;
|
struct pt_regs *regs = eregs;
|
||||||
/* Did already sync */
|
/* Did already sync */
|
||||||
@@ -390,6 +398,7 @@ asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs)
|
|||||||
*regs = *eregs;
|
*regs = *eregs;
|
||||||
return regs;
|
return regs;
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(sync_regs);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -416,7 +425,7 @@ asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs)
|
|||||||
*
|
*
|
||||||
* May run on IST stack.
|
* May run on IST stack.
|
||||||
*/
|
*/
|
||||||
dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
|
dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
|
||||||
{
|
{
|
||||||
struct task_struct *tsk = current;
|
struct task_struct *tsk = current;
|
||||||
enum ctx_state prev_state;
|
enum ctx_state prev_state;
|
||||||
@@ -424,8 +433,6 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
|
|||||||
unsigned long dr6;
|
unsigned long dr6;
|
||||||
int si_code;
|
int si_code;
|
||||||
|
|
||||||
prev_state = exception_enter();
|
|
||||||
|
|
||||||
get_debugreg(dr6, 6);
|
get_debugreg(dr6, 6);
|
||||||
|
|
||||||
/* Filter out all the reserved bits which are preset to 1 */
|
/* Filter out all the reserved bits which are preset to 1 */
|
||||||
@@ -454,6 +461,12 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
|
|||||||
/* Store the virtualized DR6 value */
|
/* Store the virtualized DR6 value */
|
||||||
tsk->thread.debugreg6 = dr6;
|
tsk->thread.debugreg6 = dr6;
|
||||||
|
|
||||||
|
#ifdef CONFIG_KPROBES
|
||||||
|
if (kprobe_debug_handler(regs))
|
||||||
|
goto exit;
|
||||||
|
#endif
|
||||||
|
prev_state = exception_enter();
|
||||||
|
|
||||||
if (notify_die(DIE_DEBUG, "debug", regs, (long)&dr6, error_code,
|
if (notify_die(DIE_DEBUG, "debug", regs, (long)&dr6, error_code,
|
||||||
SIGTRAP) == NOTIFY_STOP)
|
SIGTRAP) == NOTIFY_STOP)
|
||||||
goto exit;
|
goto exit;
|
||||||
@@ -496,6 +509,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
|
|||||||
exit:
|
exit:
|
||||||
exception_exit(prev_state);
|
exception_exit(prev_state);
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(do_debug);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note that we play around with the 'TS' bit in an attempt to get
|
* Note that we play around with the 'TS' bit in an attempt to get
|
||||||
@@ -667,7 +681,7 @@ void math_state_restore(void)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(math_state_restore);
|
EXPORT_SYMBOL_GPL(math_state_restore);
|
||||||
|
|
||||||
dotraplinkage void __kprobes
|
dotraplinkage void
|
||||||
do_device_not_available(struct pt_regs *regs, long error_code)
|
do_device_not_available(struct pt_regs *regs, long error_code)
|
||||||
{
|
{
|
||||||
enum ctx_state prev_state;
|
enum ctx_state prev_state;
|
||||||
@@ -693,6 +707,7 @@ do_device_not_available(struct pt_regs *regs, long error_code)
|
|||||||
#endif
|
#endif
|
||||||
exception_exit(prev_state);
|
exception_exit(prev_state);
|
||||||
}
|
}
|
||||||
|
NOKPROBE_SYMBOL(do_device_not_available);
|
||||||
|
|
||||||
#ifdef CONFIG_X86_32
|
#ifdef CONFIG_X86_32
|
||||||
dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code)
|
dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user