Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753833AbbEDMuJ (ORCPT ); Mon, 4 May 2015 08:50:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50292 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753799AbbEDMtl (ORCPT ); Mon, 4 May 2015 08:49:41 -0400 Date: Mon, 4 May 2015 14:49:14 +0200 From: Oleg Nesterov To: Ananth N Mavinakayanahalli , Anton Arapov , David Long , Denys Vlasenko , "Frank Ch. Eigler" , Ingo Molnar , Jan Willeke , Jim Keniston , Mark Wielaard , Pratyush Anand , Srikar Dronamraju Cc: linux-kernel@vger.kernel.org Subject: [PATCH 07/10] uprobes/x86: Introduce arch_uretprobe_is_alive() Message-ID: <20150504124914.GA22512@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150504124835.GA22462@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3209 Lines: 86 Add the x86-specific arch_uretprobe_is_alive() helper and define its "weak" version for other architectures. 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 func has already returned. TODO: this assumes that the probed app can't use multiple stacks (say sigaltstack). We will try to improve this logic later. Signed-off-by: Oleg Nesterov --- arch/x86/include/asm/uprobes.h | 1 + arch/x86/kernel/uprobes.c | 6 ++++++ include/linux/uprobes.h | 1 + kernel/events/uprobes.c | 4 ++++ 4 files changed, 12 insertions(+), 0 deletions(-) diff --git a/arch/x86/include/asm/uprobes.h b/arch/x86/include/asm/uprobes.h index f011fd0..60777f3 100644 --- a/arch/x86/include/asm/uprobes.h +++ b/arch/x86/include/asm/uprobes.h @@ -57,6 +57,7 @@ struct arch_uprobe { }; struct arch_uretprobe { + unsigned long sp; }; struct arch_uprobe_task { diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c index 0270315..868dc47 100644 --- a/arch/x86/kernel/uprobes.c +++ b/arch/x86/kernel/uprobes.c @@ -907,6 +907,7 @@ arch_uretprobe_hijack_return_addr(struct arch_uretprobe *auret, int rasize = sizeof_long(), nleft; unsigned long orig_ret_vaddr = 0; /* clear high bits for 32-bit apps */ + auret->sp = regs->sp; if (copy_from_user(&orig_ret_vaddr, (void __user *)regs->sp, rasize)) return -1; @@ -927,3 +928,8 @@ arch_uretprobe_hijack_return_addr(struct arch_uretprobe *auret, return -1; } + +bool arch_uretprobe_is_alive(struct arch_uretprobe *auret, struct pt_regs *regs) +{ + return regs->sp <= auret->sp; +} diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h index 144571b..1ed7502 100644 --- a/include/linux/uprobes.h +++ b/include/linux/uprobes.h @@ -129,6 +129,7 @@ extern int arch_uprobe_exception_notify(struct notifier_block *self, unsigned l extern void arch_uprobe_abort_xol(struct arch_uprobe *aup, struct pt_regs *regs); extern unsigned long arch_uretprobe_hijack_return_addr(struct arch_uretprobe *auret, unsigned long trampoline_vaddr, struct pt_regs *regs); +extern bool arch_uretprobe_is_alive(struct arch_uretprobe *auret, struct pt_regs *regs); extern bool arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs); extern void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr, void *src, unsigned long len); diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 19af44a..0f68ea2 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -1820,6 +1820,10 @@ bool __weak arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs) return false; } +bool __weak arch_uretprobe_is_alive(struct arch_uretprobe *auret, struct pt_regs *regs) +{ + return true; +} /* * Run handler and ask thread to singlestep. * Ensure all non-fatal signals cannot interrupt thread while it singlesteps. -- 1.5.5.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/