summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasami Hiramatsu <mhiramat@kernel.org>2019-09-03 07:08:21 -0400
committerIngo Molnar <mingo@kernel.org>2019-09-05 04:15:16 -0400
commite336b4027775cb458dc713745e526fa1a1996b2a (patch)
tree5a73f34085d6b815f28ab175c79323f4c187dc77
parentd9f3b450f206332b7ef3d78b5a85b6c20ad00fd2 (diff)
kprobes: Prohibit probing on BUG() and WARN() address
Since BUG() and WARN() may use a trap (e.g. UD2 on x86) to get the address where the BUG() has occurred, kprobes can not do single-step out-of-line that instruction. So prohibit probing on such address. Without this fix, if someone put a kprobe on WARN(), the kernel will crash with invalid opcode error instead of outputing warning message, because kernel can not find correct bug address. Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Acked-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> Cc: David S . Miller <davem@davemloft.net> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Naveen N . Rao <naveen.n.rao@linux.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: https://lkml.kernel.org/r/156750890133.19112.3393666300746167111.stgit@devnote2 Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--include/linux/bug.h5
-rw-r--r--kernel/kprobes.c3
2 files changed, 7 insertions, 1 deletions
diff --git a/include/linux/bug.h b/include/linux/bug.h
index fe5916550da8..f639bd0122f3 100644
--- a/include/linux/bug.h
+++ b/include/linux/bug.h
@@ -47,6 +47,11 @@ void generic_bug_clear_once(void);
47 47
48#else /* !CONFIG_GENERIC_BUG */ 48#else /* !CONFIG_GENERIC_BUG */
49 49
50static inline void *find_bug(unsigned long bugaddr)
51{
52 return NULL;
53}
54
50static inline enum bug_trap_type report_bug(unsigned long bug_addr, 55static inline enum bug_trap_type report_bug(unsigned long bug_addr,
51 struct pt_regs *regs) 56 struct pt_regs *regs)
52{ 57{
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index d9770a5393c8..ebe8315a756a 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1514,7 +1514,8 @@ static int check_kprobe_address_safe(struct kprobe *p,
1514 /* Ensure it is not in reserved area nor out of text */ 1514 /* Ensure it is not in reserved area nor out of text */
1515 if (!kernel_text_address((unsigned long) p->addr) || 1515 if (!kernel_text_address((unsigned long) p->addr) ||
1516 within_kprobe_blacklist((unsigned long) p->addr) || 1516 within_kprobe_blacklist((unsigned long) p->addr) ||
1517 jump_label_text_reserved(p->addr, p->addr)) { 1517 jump_label_text_reserved(p->addr, p->addr) ||
1518 find_bug((unsigned long)p->addr)) {
1518 ret = -EINVAL; 1519 ret = -EINVAL;
1519 goto out; 1520 goto out;
1520 } 1521 }