From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757383AbbGGNC7 (ORCPT ); Tue, 7 Jul 2015 09:02:59 -0400 Received: from mail-wi0-f176.google.com ([209.85.212.176]:34419 "EHLO mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756973AbbGGNCu (ORCPT ); Tue, 7 Jul 2015 09:02:50 -0400 Date: Tue, 7 Jul 2015 15:02:45 +0200 From: Anton Arapov To: Oleg Nesterov Cc: Ananth Mavinakayanahalli , David Long , Denys Vlasenko , "Frank Ch. Eigler" , Ingo Molnar , Jan Willeke , Jim Keniston , Mark Wielaard , Pratyush Anand , Srikar Dronamraju , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 07/11] uprobes/x86: Reimplement arch_uretprobe_is_alive() Message-ID: <20150707130245.GG5946@troglodyte.intinfra.com> References: <20150707012210.GA7466@redhat.com> <20150707012258.GA7533@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150707012258.GA7533@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 07, 2015 at 03:22:58AM +0200, Oleg Nesterov wrote: > 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. > > Signed-off-by: Oleg Nesterov Acked-by: Anton Arapov > --- > arch/x86/kernel/uprobes.c | 5 +++++ > include/linux/uprobes.h | 1 + > kernel/events/uprobes.c | 1 + > 3 files changed, 7 insertions(+), 0 deletions(-) > > diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c > index 0b81ad6..9d5f570 100644 > --- a/arch/x86/kernel/uprobes.c > +++ b/arch/x86/kernel/uprobes.c > @@ -993,3 +993,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; > +} > diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h > index 50d2764..7ab6d2c 100644 > --- a/include/linux/uprobes.h > +++ b/include/linux/uprobes.h > @@ -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 */ > > diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c > index 1c71b62..c5f316e 100644 > --- a/kernel/events/uprobes.c > +++ b/kernel/events/uprobes.c > @@ -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; > > -- > 1.5.5.1 >