From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932706AbdBOXkN (ORCPT ); Wed, 15 Feb 2017 18:40:13 -0500 Received: from mail.kernel.org ([198.145.29.136]:44526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755663AbdBOXkJ (ORCPT ); Wed, 15 Feb 2017 18:40:09 -0500 Date: Thu, 16 Feb 2017 08:39:44 +0900 From: Masami Hiramatsu To: "Naveen N. Rao" Cc: Ananth N Mavinakayanahalli , Arnaldo Carvalho de Melo , Ingo Molnar , Namhyung Kim , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] kretprobes: ensure probe location is at function entry Message-Id: <20170216083944.ef84cd2d5cdb271372aef639@kernel.org> In-Reply-To: References: <20170215175346.GE3169@naverao1-tp.localdomain> X-Mailer: Sylpheed 3.5.0 (GTK+ 2.24.30; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 15 Feb 2017 23:47:52 +0530 "Naveen N. Rao" wrote: > 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. > Looks good to me. Acked-by: Masami Hiramatsu Thanks! > Signed-off-by: Naveen N. Rao > --- > powerpc64 ABIv2 will need to use the over-ride as we want to use the > local entry point which will be at an offset of 8 bytes from the > (global) entry point. I have a patch that I will post separately. > > Thanks, > Naveen > > include/linux/kprobes.h | 1 + > kernel/kprobes.c | 13 +++++++++++++ > 2 files changed, 14 insertions(+) > > diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h > index 8f6849084248..0c2489435117 100644 > --- a/include/linux/kprobes.h > +++ b/include/linux/kprobes.h > @@ -266,6 +266,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); > > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index 43460104f119..72ecbf5a6312 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > @@ -1834,12 +1834,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); > -- > 2.11.0 > -- Masami Hiramatsu