Skip to contentSkip to conversation

kobject: Fix kobject_set_name_vargs()

PATCH In review Eric Dumazet 3 participants 4 messages Mar 11, 2010 – Mar 12, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kobject: Fix kobject_set_name_vargs()

In case of kvasprintf() failure, we can leak old kobject name.

---

lib/kobject.c +3 -1
index 8115eb1..1247c57 100644
@@ -222,8 +222,10 @@ int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
 		return 0;
 
 	kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
-	if (!kobj->name)
+	if (!kobj->name) {
+		kobj->name = old_name;
 		return -ENOMEM;
+	}
 
 	/* ewww... some of these buggers have '/' in the name ... */
 	while ((s = strchr(kobj->name, '/')))
#1 lore raw
Quoted 9 lines · Eric Dumazet

In case of kvasprintf() failure, we can leak old kobject name.

---

lib/kobject.c +0 -0
index 8115eb1..1247c57 100644

lib/kobject.c int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, · line 228

Quoted 8 lines
lib/kobject.c +3 -1
@@ -222,8 +222,10 @@ int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
 		return 0;
 
 	kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
-	if (!kobj->name)
+	if (!kobj->name) {
+		kobj->name = old_name;
 		return -ENOMEM;
+	}

Are you sure? I think we've been over this very thing many times in the past...

Kay, I can't recall the issue here, can you?

thanks,

greg k-h

#2 lore raw
Quoted 22 lines · Greg KH
Quoted 9 lines · Eric Dumazet

In case of kvasprintf() failure, we can leak old kobject name.

---

lib/kobject.c +0 -0
index 8115eb1..1247c57 100644

lib/kobject.c int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, · line 228

Quoted 8 lines
lib/kobject.c +3 -1
@@ -222,8 +222,10 @@ int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
               return 0;
 
       kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
-     if (!kobj->name)
+     if (!kobj->name) {
+             kobj->name = old_name;
               return -ENOMEM;
+     }

Are you sure?  I think we've been over this very thing many times in the past...

Quoted 1 line

Kay, I can't recall the issue here, can you?

I think we just lost attention to it, and never made a final decision. There have been some issues, I also don't really remember.

I myself have an unsubmitted patch for this problem here since 9 months:
http://git.kernel.org/?p=linux/kernel/git/kay/patches.git;a=blob;f=kobj-leak.patch;hb=HEAD

Seems, we should start thinking about the problem again. And if we decide to do nothing at least add a comment why we don't. :)

Thanks,
Kay

#3 lore raw
Quoted 25 lines · Kay Sievers
Quoted 22 lines · Greg KH
Quoted 9 lines · Eric Dumazet

In case of kvasprintf() failure, we can leak old kobject name.

---

lib/kobject.c +0 -0
index 8115eb1..1247c57 100644

lib/kobject.c int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, · line 228

Quoted 8 lines
lib/kobject.c +3 -1
@@ -222,8 +222,10 @@ int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
               return 0;
 
       kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
-     if (!kobj->name)
+     if (!kobj->name) {
+             kobj->name = old_name;
               return -ENOMEM;
+     }

Are you sure?  I think we've been over this very thing many times in the past...

Quoted 1 line

Kay, I can't recall the issue here, can you?

Quoted 8 lines

I think we just lost attention to it, and never made a final decision. There have been some issues, I also don't really remember.

I myself have an unsubmitted patch for this problem here since 9 months:
 http://git.kernel.org/?p=linux/kernel/git/kay/patches.git;a=blob;f=kobj-leak.patch;hb=HEAD

Seems, we should start thinking about the problem again. And if we decide to do nothing at least add a comment why we don't. :)

Found the old discussion, which ended in no action:
http://lkml.org/lkml/2009/6/27/160

It was about simplifying the logic and not to allow to set a kobject name several times in a row.

Sounds good to me to try that, and raise a BUG if the name is set a second time. If we don't support that, all can be simplified, and the original issue, that has come up again now, will be gone with that.

Thanks,
Kay