perf/x86/hw_breakpoints: Disallow kernel breakpoints unless kprobe-safe
[deliverable/linux.git] / arch / x86 / kernel / hw_breakpoint.c
index 7114ba220fd45d64cb24d86f9a3dd5c3bc65bceb..78f3e90c565927591790cadd98f5bacaa14c90a9 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/irqflags.h>
 #include <linux/notifier.h>
 #include <linux/kallsyms.h>
+#include <linux/kprobes.h>
 #include <linux/percpu.h>
 #include <linux/kdebug.h>
 #include <linux/kernel.h>
@@ -243,6 +244,20 @@ static int arch_build_bp_info(struct perf_event *bp)
                info->type = X86_BREAKPOINT_RW;
                break;
        case HW_BREAKPOINT_X:
+               /*
+                * We don't allow kernel breakpoints in places that are not
+                * acceptable for kprobes.  On non-kprobes kernels, we don't
+                * allow kernel breakpoints at all.
+                */
+               if (bp->attr.bp_addr >= TASK_SIZE_MAX) {
+#ifdef CONFIG_KPROBES
+                       if (within_kprobe_blacklist(bp->attr.bp_addr))
+                               return -EINVAL;
+#else
+                       return -EINVAL;
+#endif
+               }
+
                info->type = X86_BREAKPOINT_EXECUTE;
                /*
                 * x86 inst breakpoints need to have a specific undefined len.
This page took 0.027593 seconds and 5 git commands to generate.