]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
kprobes: Prohibit probing on BUG() and WARN() address
authorMasami Hiramatsu <mhiramat@kernel.org>
Tue, 3 Sep 2019 11:08:21 +0000 (20:08 +0900)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 16 Oct 2019 09:55:27 +0000 (11:55 +0200)
BugLink: https://bugs.launchpad.net/bugs/1847155
[ Upstream commit e336b4027775cb458dc713745e526fa1a1996b2a ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
include/linux/bug.h
kernel/kprobes.c

index fe5916550da8c5c4da102dd91385eef8123167f6..f639bd0122f3958b28daf0724e5e1a889d7e4a66 100644 (file)
@@ -47,6 +47,11 @@ void generic_bug_clear_once(void);
 
 #else  /* !CONFIG_GENERIC_BUG */
 
+static inline void *find_bug(unsigned long bugaddr)
+{
+       return NULL;
+}
+
 static inline enum bug_trap_type report_bug(unsigned long bug_addr,
                                            struct pt_regs *regs)
 {
index 86e030696c3b7b88bf84812c41090268234aa38b..33cd97c08bbd474cd89434e9be34aab58cdd5e99 100644 (file)
@@ -1499,7 +1499,8 @@ static int check_kprobe_address_safe(struct kprobe *p,
        /* Ensure it is not in reserved area nor out of text */
        if (!kernel_text_address((unsigned long) p->addr) ||
            within_kprobe_blacklist((unsigned long) p->addr) ||
-           jump_label_text_reserved(p->addr, p->addr)) {
+           jump_label_text_reserved(p->addr, p->addr) ||
+           find_bug((unsigned long)p->addr)) {
                ret = -EINVAL;
                goto out;
        }