uprobes/x86: Reimplement arch_uretprobe_is_alive()
authorOleg Nesterov <oleg@redhat.com>
Tue, 21 Jul 2015 13:40:18 +0000 (15:40 +0200)
committerIngo Molnar <mingo@kernel.org>
Fri, 31 Jul 2015 08:38:05 +0000 (10:38 +0200)
Add the x86 specific version of arch_uretprobe_is_alive()
helper. It returns true if the stack frame mangled by
prepare_uretprobe() is still on stack. So if it returns false,
we know that the probed function has already returned.

We add the new return_instance->stack member and change the
generic code to initialize it in prepare_uretprobe, but it
should be equally useful for other architectures.

TODO: this assumes that the probed application can't use
      multiple stacks (say sigaltstack). We will try to improve
      this logic later.

Tested-by: Pratyush Anand <panand@redhat.com>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Acked-by: Anton Arapov <arapov@gmail.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20150721134018.GA4766@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/kernel/uprobes.c
include/linux/uprobes.h
kernel/events/uprobes.c

index 66476244731ef8fba8fafbe1bb6cbd17f1a18b9c..58e9b842633fe5111cc3cbe50b071ae5eecc15ee 100644 (file)
@@ -985,3 +985,8 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
 
        return -1;
 }
+
+bool arch_uretprobe_is_alive(struct return_instance *ret, struct pt_regs *regs)
+{
+       return regs->sp <= ret->stack;
+}
index 50d2764d66a8cb4307b179cdac4968cf8daacb3c..7ab6d2c8be49c443d504796ca2006178b97f8e3d 100644 (file)
@@ -95,6 +95,7 @@ struct uprobe_task {
 struct return_instance {
        struct uprobe           *uprobe;
        unsigned long           func;
+       unsigned long           stack;          /* stack pointer */
        unsigned long           orig_ret_vaddr; /* original return address */
        bool                    chained;        /* true, if instance is nested */
 
index 1c71b6242a7e617250820d16bb47fc0765ce1758..c5f316e06dc0b486389f9d7aef4ade4e67d364a0 100644 (file)
@@ -1562,6 +1562,7 @@ static void prepare_uretprobe(struct uprobe *uprobe, struct pt_regs *regs)
 
        ri->uprobe = get_uprobe(uprobe);
        ri->func = instruction_pointer(regs);
+       ri->stack = user_stack_pointer(regs);
        ri->orig_ret_vaddr = orig_ret_vaddr;
        ri->chained = chained;