All of lore.kernel.org
 help / color / mirror / Atom feed
* on static kobjects and double frees...
@ 2008-06-10 15:58 Arthur Jones
  2008-06-10 16:23 ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Arthur Jones @ 2008-06-10 15:58 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel, Doug Thompson, bluesmoke-devel

Hi Greg,  The edac pci sysfs generic layer uses a static
kobject as a placeholder parent where edac pci drivers
are inserted.  An atomic count is used to know when
to kobject_init_add_add or kobject_put the static kobject.
The issue with this is that the name gets double freed
on the second module load as edac does not clear it, and
kobject_cleanup does not clear it.

The quick fix was to clear the static kobj name before
calling kobject_init, but that seems a bit fragile as it
involves knowing the internals of kobject_put.  Perhaps
the name should be cleared before calling the kobject
release method?  Something like this (not even compile
tested):

diff --git a/lib/kobject.c b/lib/kobject.c
index 718e510..7dfe906 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -552,6 +552,9 @@ static void kobject_cleanup(struct kobject *kobj)
 	if (t && t->release) {
 		pr_debug("kobject: '%s' (%p): calling ktype release\n",
 			 kobject_name(kobj), kobj);
+
+		/* avoid double free with static kobjects... */
+		kobj->name = NULL;
 		t->release(kobj);
 	}
 
What do you think?  I'm happy to implement and test whatever
you think is best...

The edac code in question is drivers/edac/edac_pci_sysfs.c,
the static kobject is called edac_pci_top_main_kobj...

Arthur

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-06-10 21:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-10 15:58 on static kobjects and double frees Arthur Jones
2008-06-10 16:23 ` Greg KH
2008-06-10 16:38   ` Arthur Jones
2008-06-10 16:42     ` Greg KH
2008-06-10 16:58       ` Arthur Jones
2008-06-10 21:14     ` Doug Thompson
2008-06-10 21:39       ` Arthur Jones

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.