kobject: don't oops on null kobject.name
Subsystems (2)
PATCH 1/1 kobject: don't oops on null kobject.name
kobject_get_path() will oops if one of the component names is NULL. Fix that by returning NULL instead of oopsing.
---
Helge, this fixes your "2.6.15 OOPS while trying to mount cdrom".
Probably not the best fix, but It Works For Me (TM).
lib/kobject.c +4 -0
@@ -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 *kint len; len =get_kobj_path_length (kobj); +if (len ==0 ) +return NULL ; path =kmalloc (len, gfp_mask);if (!path)return NULL ;
Signature · 2 lines
Chuck Currently reading: _Olympos_ by Dan Simmons
Quoted 23 lines · Chuck Ebbert
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).
lib/kobject.c +2
-0@@ -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);
lib/kobject.c char *kobject_get_path(struct kobject *k · line 116
Quoted 8 lines
lib/kobject.c +2
-0@@ -107,6 +109,8 @@ char *kobject_get_path(struct kobject *kint 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.
Why did you choose kobject_get_path()?
Quoted 26 lines · Andrew Morton
Quoted 25 lines · Chuck Ebbert
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).
lib/kobject.c +2
-0@@ -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 *kint len;
Quoted 11 lines
lib/kobject.c char *kobject_get_path(struct kobject *k · line 116
Quoted 6 lines
lib/kobject.c +2
-0len =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, butkobject_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
lib/kobject.c +5 -0
@@ -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",
Quoted 8 lines · Greg KH
Quoted 6 lines
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, butkobject_add()does play around with the ->name field and will go oops if ->name==NULL and debugging is enabled.Something like this instead?
I think so.
Quoted 1 line
(warning, untested...)
Ship it!
Quoted 6 lines
I'll try it out in a reboot cycle...
lib/kobject.c +0
-0@@ -164,6 +164,11 @@ int kobject_add(struct kobject * kobj)return -ENOENT ;
lib/kobject.c int kobject_add(struct kobject * kobj) · line 174
Quoted 10 lines
lib/kobject.c +5
-0if (!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",
It might be worth emitting the warning and then proceeding rather than failing - minimise potential disruption. I guess we'll see...
Quoted 8 lines · Andrew Morton
Quoted 7 lines · Greg KH
Quoted 6 lines
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, butkobject_add()does play around with the ->name field and will go oops if ->name==NULL and debugging is enabled.
Quoted 7 lines
Quoted 1 line
Something like this instead?
I think so.
Quoted 1 line
(warning, untested...)
Ship it!
Heh, it works for me, I'm running with it right now :)
Quoted 16 lines
Quoted 16 lines
I'll try it out in a reboot cycle...
lib/kobject.c +5
-0@@ -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);
Quoted 4 lines
lib/kobject.c int kobject_add(struct kobject * kobj) · line 174
Quoted 1 line
lib/kobject.c +0
-0pr_debug("kobject %s: registering. parent: %s, set: %s\n",It might be worth emitting the warning and then proceeding rather than failing - minimise potential disruption. I guess we'll see...
Hm, I looked at the only user of kobjects in the kernel that I know of that doesn't use sysfs (the cdev code) and even it sets the kobject name to something sane, so I think we should be safe with this.
I'll add it to my tree and let's see what the next -mm causes to pop up :)
thanks,
greg k-h