From: Masami Hiramatsu <mhiramat@redhat.com>
To: ananth@in.ibm.com
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>, Ingo Molnar <mingo@elte.hu>,
lkml <linux-kernel@vger.kernel.org>,
systemtap <systemtap@sources.redhat.com>,
DLE <dle-develop@lists.sourceforge.net>,
Jim Keniston <jkenisto@us.ibm.com>,
Andi Kleen <ak@linux.intel.com>,
Christoph Hellwig <hch@infradead.org>,
"Frank Ch. Eigler" <fche@redhat.com>,
"H. Peter Anvin" <hpa@zytor.com>, Jason Baron <jbaron@redhat.com>,
"K.Prasad" <prasad@linux.vnet.ibm.com>,
Lai Jiangshan <laijs@cn.fujitsu.com>,
Li Zefan <lizf@cn.fujitsu.com>,
Peter Zijlstra <peterz@infradead.org>,
Srikar Dronamraju <srikar@linux.vnet.ibm.com>,
Tom Zanussi <tzanussi@gmail.com>
Subject: Re: [BUGFIX] kprobes: prevent re-registration of the same kprobe - take2
Date: Mon, 14 Sep 2009 12:25:41 -0400 [thread overview]
Message-ID: <4AAE6E85.9020002@redhat.com> (raw)
In-Reply-To: <20090914100459.GA4446@in.ibm.com>
Ananth N Mavinakayanahalli wrote:
> On Sun, Sep 13, 2009 at 09:47:39PM -0400, Masami Hiramatsu wrote:
>> Ananth N Mavinakayanahalli wrote:
>>> On Fri, Sep 11, 2009 at 05:12:54AM +0200, Frederic Weisbecker wrote:
>>>> On Thu, Sep 10, 2009 at 07:53:30PM -0400, Masami Hiramatsu wrote:
>
> ...
>
>> Hmm, if we catch the second registration here, it's too late. At
>> register_kprobe(), we initialized some field of kprobe before calling
>> register_aggr_kprobe(). Especially kprobe.list is cleared.
>>
>> And this can't check the case that 'p' is already registered on
>> an aggr kprobe.
>
> Agreed. I thought of this case after sending out the earlier patch...
>
>> Thus, I think some initialization paths should be changed (kp.flag
>> field is initialized too early, yearh, that's my mistake),
>> and also, you will need to use get_valid_kprobe() to check the kprobe
>> has not been registered.
>
> __get_valid_kprobe() makes the task easy. We should just prevent
> re-registration whether or not the earlier probe is disabled.
>
> How does this patch look?
>
> ---
> Prevent re-registration of the same kprobe. This situation, though
> unlikely, needs to be flagged since it can lead to a system crash if its
> not handled.
>
> The core change itself is small, but the helper routine needed to be
> moved around a bit; hence the diffstat.
>
> Signed-off-by: Ananth N Mavinakayanahalli<ananth@in.ibm.com>
> ---
> kernel/kprobes.c | 58 ++++++++++++++++++++++++++++++++++++-------------------
> 1 file changed, 38 insertions(+), 20 deletions(-)
>
> Index: linux-2.6.31/kernel/kprobes.c
> ===================================================================
> --- linux-2.6.31.orig/kernel/kprobes.c
> +++ linux-2.6.31/kernel/kprobes.c
> @@ -681,6 +681,40 @@ static kprobe_opcode_t __kprobes *kprobe
> return (kprobe_opcode_t *)(((char *)addr) + p->offset);
> }
>
> +/* Check passed kprobe is valid and return kprobe in kprobe_table. */
> +static struct kprobe * __kprobes __get_valid_kprobe(struct kprobe *p)
> +{
> + struct kprobe *old_p, *list_p;
> +
> + old_p = get_kprobe(p->addr);
> + if (unlikely(!old_p))
> + return NULL;
> +
> + if (p != old_p) {
> + list_for_each_entry_rcu(list_p,&old_p->list, list)
> + if (list_p == p)
> + /* kprobe p is a valid probe */
> + goto valid;
> + return NULL;
> + }
> +valid:
> + return old_p;
> +}
> +
> +/* Return error if the kprobe is being re-registered */
> +static inline int check_kprobe_rereg(struct kprobe *p)
> +{
> + int ret = 0;
> + struct kprobe *old_p;
> +
> + mutex_lock(&kprobe_mutex);
> + old_p = __get_valid_kprobe(p);
> + if (old_p == p)
Here, since __get_valid_kprobe(p) will return aggr_kprobe of 'p',
you just need to check old_p != NULL.
Other parts are OK for me.
Thank you!
--
Masami Hiramatsu
Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division
e-mail: mhiramat@redhat.com
next prev parent reply other threads:[~2009-09-14 16:22 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-10 23:52 [PATCH tracing/kprobes 0/7] tracing/kprobes: kprobe-based event tracer update and perf support Masami Hiramatsu
2009-09-10 23:53 ` [PATCH tracing/kprobes 1/7] x86/ptrace: Fix regs_get_argument_nth() to add correct offset Masami Hiramatsu
2009-09-11 1:43 ` Steven Rostedt
2009-10-17 9:59 ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-09-10 23:53 ` [PATCH tracing/kprobes 2/7] tracing/kprobes: Fix probe offset to be unsigned Masami Hiramatsu
2009-10-17 9:59 ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-09-10 23:53 ` [PATCH tracing/kprobes 3/7] tracing/kprobes: Cleanup kprobe tracer code Masami Hiramatsu
2009-09-11 2:33 ` Daniel Walker
2009-09-11 2:36 ` Frederic Weisbecker
2009-10-17 9:59 ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-09-10 23:53 ` [PATCH tracing/kprobes 4/7] tracing/kprobes: Add event profiling support Masami Hiramatsu
2009-09-11 3:12 ` Frederic Weisbecker
2009-09-11 16:22 ` Masami Hiramatsu
2009-09-14 3:02 ` Frederic Weisbecker
2009-09-14 16:54 ` Masami Hiramatsu
2009-09-14 18:55 ` Frederic Weisbecker
2009-09-14 19:36 ` Masami Hiramatsu
2009-09-14 21:07 ` Frederic Weisbecker
2009-09-15 4:52 ` Ananth N Mavinakayanahalli
2009-09-11 19:30 ` Masami Hiramatsu
2009-09-14 3:08 ` Frederic Weisbecker
2009-09-13 10:07 ` [BUGFIX] kprobes: prevent re-registration of the same kprobe Ananth N Mavinakayanahalli
2009-09-14 1:47 ` Masami Hiramatsu
2009-09-14 10:04 ` [BUGFIX] kprobes: prevent re-registration of the same kprobe - take2 Ananth N Mavinakayanahalli
2009-09-14 16:25 ` Masami Hiramatsu [this message]
2009-09-15 5:13 ` Ananth N Mavinakayanahalli
2009-09-15 13:29 ` Masami Hiramatsu
2009-10-17 10:02 ` [tip:perf/probes] kprobes: Prevent re-registration of the same kprobe tip-bot for Ananth N Mavinakayanahalli
2009-10-17 9:59 ` [tip:perf/probes] tracing/kprobes: Add event profiling support tip-bot for Masami Hiramatsu
2009-09-10 23:53 ` [PATCH tracing/kprobes 5/7] tracing/kprobes: Add argument name support Masami Hiramatsu
2009-09-11 14:07 ` Steven Rostedt
2009-09-11 16:11 ` Masami Hiramatsu
2009-09-11 16:32 ` Masami Hiramatsu
2009-10-17 10:00 ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-09-10 23:53 ` [PATCH tracing/kprobes 6/7] tracing/kprobes: Show event name in trace output Masami Hiramatsu
2009-10-17 10:00 ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-09-10 23:53 ` [PATCH tracing/kprobes 7/7] tracing/kprobes: Support custom subsystem for each kprobe event Masami Hiramatsu
2009-10-17 10:00 ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-09-11 1:33 ` [PATCH tracing/kprobes 0/7] tracing/kprobes: kprobe-based event tracer update and perf support Frederic Weisbecker
2009-09-11 1:45 ` Steven Rostedt
2009-09-11 16:03 ` Masami Hiramatsu
2009-09-14 2:59 ` Frederic Weisbecker
2009-09-14 17:16 ` Masami Hiramatsu
2009-09-14 20:52 ` Frederic Weisbecker
2009-09-14 21:10 ` Masami Hiramatsu
2009-09-14 21:09 ` Frederic Weisbecker
2009-09-11 19:03 ` Frank Ch. Eigler
2009-09-11 19:06 ` Christoph Hellwig
2009-09-11 19:50 ` Mark Wielaard
2009-09-11 20:03 ` Christoph Hellwig
2009-09-12 1:23 ` Masami Hiramatsu
2009-09-11 19:15 ` Frederic Weisbecker
2009-09-11 15:36 ` Frederic Weisbecker
2009-09-11 21:48 ` Masami Hiramatsu
2009-09-14 2:22 ` Frederic Weisbecker
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=4AAE6E85.9020002@redhat.com \
--to=mhiramat@redhat.com \
--cc=ak@linux.intel.com \
--cc=ananth@in.ibm.com \
--cc=dle-develop@lists.sourceforge.net \
--cc=fche@redhat.com \
--cc=fweisbec@gmail.com \
--cc=hch@infradead.org \
--cc=hpa@zytor.com \
--cc=jbaron@redhat.com \
--cc=jkenisto@us.ibm.com \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizf@cn.fujitsu.com \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=prasad@linux.vnet.ibm.com \
--cc=rostedt@goodmis.org \
--cc=srikar@linux.vnet.ibm.com \
--cc=systemtap@sources.redhat.com \
--cc=tzanussi@gmail.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;
as well as URLs for NNTP newsgroup(s).