kprobes/x86: Use copy_from_kernel_nofault() to read from unsafe address
[sfrench/cifs-2.6.git] / arch / x86 / kernel / kprobes / core.c
index 091b3ab76a1801bbfa1c9f61bdbf45dc95bb8026..d0e49bd7c6f3faced07c7527b3e8df4f0e2dbe79 100644 (file)
@@ -373,7 +373,16 @@ out:
 kprobe_opcode_t *arch_adjust_kprobe_addr(unsigned long addr, unsigned long offset,
                                         bool *on_func_entry)
 {
-       if (is_endbr(*(u32 *)addr)) {
+       u32 insn;
+
+       /*
+        * Since 'addr' is not guaranteed to be safe to access, use
+        * copy_from_kernel_nofault() to read the instruction:
+        */
+       if (copy_from_kernel_nofault(&insn, (void *)addr, sizeof(u32)))
+               return NULL;
+
+       if (is_endbr(insn)) {
                *on_func_entry = !offset || offset == 4;
                if (*on_func_entry)
                        offset = 4;