public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: Balaji Rao <balajirrao@gmail.com>
Cc: kvm-devel@lists.sourceforge.net,
	Mikael Pettersson <mikpe@it.uu.se>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Mark kobjects as unitialized
Date: Mon, 10 Mar 2008 08:52:00 -0700	[thread overview]
Message-ID: <20080310155200.GA20437@suse.de> (raw)
In-Reply-To: <200803091251.15428.balajirrao@gmail.com>

On Sun, Mar 09, 2008 at 12:51:15PM +0530, Balaji Rao wrote:
> On Sunday 09 March 2008 12:33:07 pm Greg KH wrote:
> <snip>
> > > > > Hi,
> > > > > 
> > > > > This patch does not fix it all! The problem is in fact more involved. I also get these BUG reports when I reload 
> > > kvm-intel.
> > > > > 
> > > > > BUG kmalloc-8: Object already free
> > > > > [  74.696570] -----------------------------------------------------------------------------
> > > > > [   74.696596] 
> > > > > [   74.697310] INFO: Allocated in strndup_user+0x30/0x62 age=587 cpu=2 pid=1439
> > > > > [   74.697845] INFO: Freed in kobject_set_name_vargs+0x29/0x32 age=559 cpu=3 pid=1439
> > > > > [   74.698008] INFO: Slab 0xc16f93a0 used=10 fp=0xf7c9d2d8 flags=0x10000c3
> > > > > [   74.698008] INFO: Object 0xf7c9d1f8 @offset=504 fp=0xf7c9d578
> > > > > 
> > > > > This happens because, sysdev_class_register assigns a name to the
> > > > > kobject, and kfrees the old name if any. The poisoned 'name' object
> > > > > persists in case of statically allocated kobjects and as its passed to
> > > > > kfree again when re registered, we get the above warning.
> > > > > 
> > > > > So, AFAICS the best way to solve this is by fixing the kobject users
> > > > > (kvm, oprofile etc.) to use dynamic kobjects instead of static ones or
> > > > > memset the kobject to zero before passing it to sysdev_register.
> > > > 
> > > > I like the memset idea, how about this patch instead?
> > > > 
> > > > thanks,
> > > > 
> > > > greg k-h
> > > > 
> > > > --- a/drivers/base/sys.c
> > > > +++ b/drivers/base/sys.c
> > > > @@ -133,6 +133,7 @@ int sysdev_class_register(struct sysdev_
> > > >  	pr_debug("Registering sysdev class '%s'\n",
> > > >  		 kobject_name(&cls->kset.kobj));
> > > >  	INIT_LIST_HEAD(&cls->drivers);
> > > > +	memset(&cls->kset.kobj, 0x00, sizeof(struct kobject));
> > > >  	cls->kset.kobj.parent = &system_kset->kobj;
> > > >  	cls->kset.kobj.ktype = &ktype_sysdev_class;
> > > >  	cls->kset.kobj.kset = system_kset;
> > > > 
> > > 
> > > This should work.But I am afraid if we zeroed it, the kfree poison
> > > test wouldn't catch even the genuine cases. Isn't it ?  CMIIW.
> > 
> > What "genuine cases"?  kobjects should always be initialized to zero
> > before they are registered.
> > 
> The cases in which a freed kobject is passed to the register function ? Probably they will be caught when do a memset..
> > > A better fix according to me would be to zero the kobject in the
> > > places where we know it is being re-registered (kvm, oprofile) etc.
> > > This should do for now. But we should fix the sys_device users later,
> > > for the next cycle.
> > 
> > Are you sure you know all of the sysdev_class objects that can be
> > re-registered?
> > 
> Hmm.. Right. No, I only know that KVM and Oprofile use it.
> > Can you test this patch out?
> > 
> Yes the idea works. One more memset is needed in sysdev_register. Here's the final patch.
> 
> diff --git a/drivers/base/sys.c b/drivers/base/sys.c
> index 2f79c55..7c839d9 100644
> --- a/drivers/base/sys.c
> +++ b/drivers/base/sys.c
> @@ -133,6 +133,7 @@ int sysdev_class_register(struct sysdev_class * cls)
>         pr_debug("Registering sysdev class '%s'\n",
>                  kobject_name(&cls->kset.kobj));
>         INIT_LIST_HEAD(&cls->drivers);
> +       memset(&cls->kset.kobj, 0x00, sizeof(struct kobject));
>         cls->kset.kobj.parent = &system_kset->kobj;
>         cls->kset.kobj.ktype = &ktype_sysdev_class;
>         cls->kset.kobj.kset = system_kset;
> @@ -227,6 +228,7 @@ int sysdev_register(struct sys_device * sysdev)
>  
>         pr_debug("Registering sys device '%s'\n", kobject_name(&sysdev->kobj));
>  
> +       memset(&sysdev->kobj, 0x00, sizeof(struct kobject));
>         /* Make sure the kset is set */
>         sysdev->kobj.kset = &cls->kset;

Yes, you're right.

This also means I can drop the kobject_cleanup() patch from you as well,
as that should no longer be needed, right?

thanks,

greg k-h

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

  parent reply	other threads:[~2008-03-10 15:52 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-06 16:53 [PATCH] Mark kobjects as unitialized Balaji Rao
2008-03-06 17:05 ` Greg KH
2008-03-06 17:50   ` Balaji Rao
2008-03-06 18:05     ` Greg KH
2008-03-07  8:56       ` Avi Kivity
2008-03-08 22:07       ` Balaji Rao
2008-03-09  5:06         ` Greg KH
2008-03-09  6:16           ` Greg KH
2008-03-09  6:17           ` Balaji Rao
2008-03-09  6:33         ` Greg KH
2008-03-09  6:36           ` Balaji Rao
2008-03-09  7:03             ` Greg KH
2008-03-09  7:21               ` Balaji Rao
2008-03-09 10:49                 ` Mikael Pettersson
2008-03-10 17:20                   ` Greg KH
2008-03-10 15:52                 ` Greg KH [this message]
2008-03-10 16:05                   ` Balaji Rao
2008-03-10 17:20                     ` Greg KH
2008-03-06 18:34 ` patch kobjects-mark-cleaned-up-kobjects-as-unitialized.patch added to gregkh-2.6 tree gregkh
2008-03-09  4:58 ` patch patches/driver-core/kobjects-mark-cleaned-up-kobjects-as-unitialized.patch " gregkh

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=20080310155200.GA20437@suse.de \
    --to=gregkh@suse.de \
    --cc=balajirrao@gmail.com \
    --cc=kvm-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikpe@it.uu.se \
    /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