Re: [patch] kobject: don't oops on null kobject.name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jan 13, 2006 at 02:30:13PM -0800, Andrew Morton wrote:
> Chuck Ebbert <[email protected]> wrote:
> >
> > kobject_get_path() will oops if one of the component names is
> > NULL.  Fix that by returning NULL instead of oopsing.
> > 
> > Signed-off-by: Chuck Ebbert <[email protected]>
> > ---
> > 
> > Helge, this fixes your "2.6.15 OOPS while trying to mount cdrom".
> > 
> > Probably not the best fix, but It Works For Me (TM).
> > 
> > --- 2.6.15a.orig/lib/kobject.c
> > +++ 2.6.15a/lib/kobject.c
> > @@ -72,6 +72,8 @@ static int get_kobj_path_length(struct k
> >  	 * Add 1 to strlen for leading '/' of each level.
> >  	 */
> >  	do {
> > +		if (kobject_name(parent) == NULL)
> > +			return 0;
> >  		length += strlen(kobject_name(parent)) + 1;
> >  		parent = parent->parent;
> >  	} while (parent);
> > @@ -107,6 +109,8 @@ char *kobject_get_path(struct kobject *k
> >  	int len;
> >  
> >  	len = get_kobj_path_length(kobj);
> > +	if (len == 0)
> > +		return NULL;
> >  	path = kmalloc(len, gfp_mask);
> >  	if (!path)
> >  		return NULL;
> 
> I'd have thought that we'd want the test right at the start of
> kobject_add() - fail it if ->name is zero.  I don't know if that'd work for
> all callers, but kobject_add() does play around with the ->name field and
> will go oops if ->name==NULL and debugging is enabled.

Something like this instead?  (warning, untested...)

I'll try it out in a reboot cycle...

thanks,

greg k-h


--- gregkh-2.6.orig/lib/kobject.c	2006-01-13 09:15:18.000000000 -0800
+++ gregkh-2.6/lib/kobject.c	2006-01-13 14:54:40.000000000 -0800
@@ -164,6 +164,11 @@ int kobject_add(struct kobject * kobj)
 		return -ENOENT;
 	if (!kobj->k_name)
 		kobj->k_name = kobj->name;
+	if (!kobj->k_name) {
+		pr_debug("kobject attempted to be registered with no name!\n");
+		WARN_ON(1);
+		return -EINVAL;
+	}
 	parent = kobject_get(kobj->parent);
 
 	pr_debug("kobject %s: registering. parent: %s, set: %s\n",
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux