mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Ingo Molnar <mingo@redhat.com>,
	Namhyung Kim <namhyung@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] kretprobes: ensure probe location is at function entry
Date: Thu, 16 Feb 2017 08:39:44 +0900	[thread overview]
Message-ID: <20170216083944.ef84cd2d5cdb271372aef639@kernel.org> (raw)
In-Reply-To: <dbb93084a6bc96d44cf7436ab6d5f9c8c72b6a39.1487181941.git.naveen.n.rao@linux.vnet.ibm.com>

On Wed, 15 Feb 2017 23:47:52 +0530
"Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> 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 <mhiramat@kernel.org>

Thanks!

> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> ---
> 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 <mhiramat@kernel.org>

  parent reply	other threads:[~2017-02-15 23:40 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-14  8:31 [PATCH] kretprobes: reject registration if a symbol offset is specified Naveen N. Rao
2017-02-14  8:41 ` Ananth N Mavinakayanahalli
2017-02-14 10:32 ` Masami Hiramatsu
2017-02-15 17:53   ` Naveen N. Rao
2017-02-15 18:17     ` [PATCH 1/3] kretprobes: ensure probe location is at function entry Naveen N. Rao
2017-02-15 18:17       ` [PATCH 2/3] trace/kprobes: allow return probes with offsets and absolute addresses Naveen N. Rao
2017-02-15 23:43         ` Masami Hiramatsu
2017-02-15 18:17       ` [PATCH 3/3] perf: revert "perf probe: Fix probing kretprobes" Naveen N. Rao
2017-02-15 23:43         ` Masami Hiramatsu
2017-02-15 23:39       ` Masami Hiramatsu [this message]
2017-02-16  7:51         ` [PATCH 1/3] kretprobes: ensure probe location is at function entry Naveen N. Rao
2017-02-16  8:17       ` [PATCH 0/2] powerpc: kretprobe updates Naveen N. Rao
2017-02-16  8:17         ` [PATCH 1/2] powerpc: kretprobes: override default function entry offset Naveen N. Rao
2017-02-16  8:17         ` [PATCH 2/2] perf: powerpc: choose LEP with kretprobes Naveen N. Rao
2017-02-17 10:44         ` [PATCH 0/2] powerpc: kretprobe updates Masami Hiramatsu
2017-02-17 20:42           ` Arnaldo Carvalho de Melo
2017-02-19  4:42             ` Masami Hiramatsu
2017-02-20  9:50               ` Naveen N. Rao
2017-02-21 13:07                 ` Masami Hiramatsu
2017-02-22 13:39                   ` Naveen N. Rao
2017-02-20  9:46             ` Naveen N. Rao
2017-02-20 11:43             ` Naveen N. Rao
2017-02-21 13:06               ` Masami Hiramatsu
2017-02-15 23:28     ` [PATCH] kretprobes: reject registration if a symbol offset is specified Masami Hiramatsu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170216083944.ef84cd2d5cdb271372aef639@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=acme@kernel.org \
    --cc=ananth@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=naveen.n.rao@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome