Skip to content

Commit 7b868e4

Browse files
oleg-nesterovIngo Molnar
authored andcommitted
uprobes/x86: Reimplement arch_uretprobe_is_alive()
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 <[email protected]> Signed-off-by: Oleg Nesterov <[email protected]> Acked-by: Srikar Dronamraju <[email protected]> Acked-by: Anton Arapov <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 97da897 commit 7b868e4

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

arch/x86/kernel/uprobes.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,3 +985,8 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
985985

986986
return -1;
987987
}
988+
989+
bool arch_uretprobe_is_alive(struct return_instance *ret, struct pt_regs *regs)
990+
{
991+
return regs->sp <= ret->stack;
992+
}

include/linux/uprobes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct uprobe_task {
9595
struct return_instance {
9696
struct uprobe *uprobe;
9797
unsigned long func;
98+
unsigned long stack; /* stack pointer */
9899
unsigned long orig_ret_vaddr; /* original return address */
99100
bool chained; /* true, if instance is nested */
100101

kernel/events/uprobes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,7 @@ static void prepare_uretprobe(struct uprobe *uprobe, struct pt_regs *regs)
15621562

15631563
ri->uprobe = get_uprobe(uprobe);
15641564
ri->func = instruction_pointer(regs);
1565+
ri->stack = user_stack_pointer(regs);
15651566
ri->orig_ret_vaddr = orig_ret_vaddr;
15661567
ri->chained = chained;
15671568

0 commit comments

Comments
 (0)