]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
kretprobes: Ensure probe location is at function entry
authorNaveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Wed, 22 Feb 2017 13:53:37 +0000 (19:23 +0530)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 3 Mar 2017 22:07:17 +0000 (19:07 -0300)
kretprobes can be registered by specifying an absolute address or by
specifying offset to a symbol. However, we need to ensure this falls at
function entry so as to be able to determine the return address.

Validate the same during kretprobe registration. By default, there
should not be any offset from a function entry, as determined through a
kallsyms_lookup(). Introduce arch_function_offset_within_entry() as a
way for architectures to override this.

Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: linuxppc-dev@lists.ozlabs.org
Link: http://lkml.kernel.org/r/f1583bc4839a3862cfc2acefcc56f9c8837fa2ba.1487770934.git.naveen.n.rao@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
include/linux/kprobes.h
kernel/kprobes.c

index c328e4f7dcadb4276bddcfbcc97caa323c48a0a3..177bdf6c6aeb082369280b61d4167c60ca33c9e4 100644 (file)
@@ -267,6 +267,7 @@ extern int arch_init_kprobes(void);
 extern void show_registers(struct pt_regs *regs);
 extern void kprobes_inc_nmissed_count(struct kprobe *p);
 extern bool arch_within_kprobe_blacklist(unsigned long addr);
+extern bool arch_function_offset_within_entry(unsigned long offset);
 
 extern bool within_kprobe_blacklist(unsigned long addr);
 
index 699c5bc51a9219d664578e4d7978dee94d291c82..448759d4a263fd5d7051015bcad5ba701abb7b64 100644 (file)
@@ -1875,12 +1875,25 @@ static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs)
 }
 NOKPROBE_SYMBOL(pre_handler_kretprobe);
 
+bool __weak arch_function_offset_within_entry(unsigned long offset)
+{
+       return !offset;
+}
+
 int register_kretprobe(struct kretprobe *rp)
 {
        int ret = 0;
        struct kretprobe_instance *inst;
        int i;
        void *addr;
+       unsigned long offset;
+
+       addr = kprobe_addr(&rp->kp);
+       if (!kallsyms_lookup_size_offset((unsigned long)addr, NULL, &offset))
+               return -EINVAL;
+
+       if (!arch_function_offset_within_entry(offset))
+               return -EINVAL;
 
        if (kretprobe_blacklist_size) {
                addr = kprobe_addr(&rp->kp);