All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Jiri Kosina <jkosina@suse.cz>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>,
	Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
	linux-kernel@vger.kernel.org, Seth Jennings <sjenning@redhat.com>
Subject: Re: [PATCH] kprobes: add kprobe_is_function_probed()
Date: Tue, 21 Oct 2014 11:43:28 -0500	[thread overview]
Message-ID: <20141021164328.GG3978@treble.redhat.com> (raw)
In-Reply-To: <alpine.LNX.2.00.1410211744550.24255@pobox.suse.cz>

On Tue, Oct 21, 2014 at 05:48:30PM +0200, Jiri Kosina wrote:
> Add a function that allows external users (such as live patching 
> mechanisms) to check whether a given function (identified by symbol name) 
> has a kprobe installed in it.

Functions aren't uniquely identifiable by name.  Perhaps it should be
something like kprobe_is_addr_range_probed()?

Should we refuse to patch a function which has a kprobe installed inside
it?  Is there a race-free way to do that?

> 
> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
> ---
>  include/linux/kprobes.h |  5 +++++
>  kernel/kprobes.c        | 28 ++++++++++++++++++++++++++++
>  2 files changed, 33 insertions(+)
> 
> diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
> index f7296e5..f760555 100644
> --- a/include/linux/kprobes.h
> +++ b/include/linux/kprobes.h
> @@ -384,6 +384,7 @@ int disable_kprobe(struct kprobe *kp);
>  int enable_kprobe(struct kprobe *kp);
>  
>  void dump_kprobe(struct kprobe *kp);
> +bool kprobe_is_function_probed(const char *name);
>  
>  #else /* !CONFIG_KPROBES: */
>  
> @@ -459,6 +460,10 @@ static inline int enable_kprobe(struct kprobe *kp)
>  {
>  	return -ENOSYS;
>  }
> +static inline bool kprobe_is_function_probed(const char *name)
> +{
> +	return false;
> +}
>  #endif /* CONFIG_KPROBES */
>  static inline int disable_kretprobe(struct kretprobe *rp)
>  {
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 3995f54..27e8ddb 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -2036,6 +2036,34 @@ void dump_kprobe(struct kprobe *kp)
>  NOKPROBE_SYMBOL(dump_kprobe);
>  
>  /*
> + * Check whether a given symbol is a probed function
> + */
> +bool kprobe_is_function_probed(const char *name)
> +{
> +	struct hlist_head *head;
> +	struct kprobe *p, *kp;
> +	const char *sym = NULL;
> +	unsigned long offset = 0;
> +	unsigned int i;
> +	char *modname, namebuf[KSYM_NAME_LEN];
> +
> +	preempt_disable();
> +	for (i = 0; i < KPROBE_TABLE_SIZE; i++) {
> +		head = &kprobe_table[i];
> +		hlist_for_each_entry_rcu(p, head, hlist) {
> +			sym = kallsyms_lookup((unsigned long)p->addr,
> +					NULL, &offset, &modname,
> +					namebuf);
> +			if (!strcmp(sym, name))
> +				return true;
> +		}
> +	}
> +	preempt_enable();
> +	return false;
> +}
> +EXPORT_SYMBOL_GPL(kprobe_is_function_probed);
> +
> +/*
>   * Lookup and populate the kprobe_blacklist.
>   *
>   * Unlike the kretprobe blacklist, we'll need to determine
> -- 
> 1.9.2

  reply	other threads:[~2014-10-21 17:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-21 15:48 [PATCH] kprobes: add kprobe_is_function_probed() Jiri Kosina
2014-10-21 16:43 ` Josh Poimboeuf [this message]
2014-10-21 20:19   ` Jiri Kosina
2014-10-21 21:14     ` Josh Poimboeuf
2014-10-21 21:25       ` Jiri Kosina
2014-10-22  2:40         ` Josh Poimboeuf
2014-10-22 14:03           ` Seth Jennings
2014-10-21 16:48 ` Ananth N Mavinakayanahalli
2014-10-22  2:30 ` Masami Hiramatsu
2014-10-22  6:02   ` Jiri Kosina
2014-10-22  6:54     ` 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=20141021164328.GG3978@treble.redhat.com \
    --to=jpoimboe@redhat.com \
    --cc=ananth@in.ibm.com \
    --cc=anil.s.keshavamurthy@intel.com \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=sjenning@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.