Skip to contentSkip to conversation

lib/kobject.c : check parameter in kobject_init_and_add

PATCH In review yan 2 participants 2 messages Apr 21, 2012 – Apr 23, 2012

Subsystems (2)
lore
Share & tools
lore

yan

author
#0 lore raw

PATCH 4/4 lib/kobject.c : check parameter in kobject_init_and_add

If user turns to the simple interface kobject_init_and_add and gives a null kobject, kobject_init can detect it but just dumps the stack. Then there is:
-->kobject_add_varg
-->kobject_set_name_vargs
In the end, it will reference kobj->name and we have an oops.

Check whether we have a valid kobject in kobject_init_and_add.

---
 lib/kobject.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
lib/kobject.c +3 -0
index dd67855..bc05922 100644
@@ -380,6 +380,9 @@ int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
 	va_list args;
 	int retval;
 
+	if (!kobj)
+		return -EINVAL;
+
 	kobject_init(kobj, ktype);
 
 	va_start(args, fmt);
Signature · 1 line
1.7.5.1
maintainer
#1 lore raw
Quoted 8 lines · yan

If user turns to the simple interface kobject_init_and_add and gives a null kobject, kobject_init can detect it but just dumps the stack. Then there is:
-->kobject_add_varg
-->kobject_set_name_vargs
In the end, it will reference kobj->name and we have an oops.

Check whether we have a valid kobject in kobject_init_and_add.

Why would anyone ever call this function without a valid kobject?

Again, sorry, this patch isn't ok.

greg k-h