Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756068AbZINQWg (ORCPT ); Mon, 14 Sep 2009 12:22:36 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756026AbZINQWa (ORCPT ); Mon, 14 Sep 2009 12:22:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48343 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756015AbZINQW3 (ORCPT ); Mon, 14 Sep 2009 12:22:29 -0400 Message-ID: <4AAE6E85.9020002@redhat.com> Date: Mon, 14 Sep 2009 12:25:41 -0400 From: Masami Hiramatsu User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.1) Gecko/20090814 Fedora/3.0-2.6.b3.fc11 Thunderbird/3.0b3 MIME-Version: 1.0 To: ananth@in.ibm.com CC: Frederic Weisbecker , Steven Rostedt , Ingo Molnar , lkml , systemtap , DLE , Jim Keniston , Andi Kleen , Christoph Hellwig , "Frank Ch. Eigler" , "H. Peter Anvin" , Jason Baron , "K.Prasad" , Lai Jiangshan , Li Zefan , Peter Zijlstra , Srikar Dronamraju , Tom Zanussi Subject: Re: [BUGFIX] kprobes: prevent re-registration of the same kprobe - take2 References: <20090910235258.22412.29317.stgit@dhcp-100-2-132.bos.redhat.com> <20090910235329.22412.94731.stgit@dhcp-100-2-132.bos.redhat.com> <20090911031253.GD16396@nowhere> <20090913100713.GB14251@in.ibm.com> <4AADA0BB.4030307@redhat.com> <20090914100459.GA4446@in.ibm.com> In-Reply-To: <20090914100459.GA4446@in.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3146 Lines: 100 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 > --- > 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/