[PATCH] base/class.c: prevent ooops due to insert/remove race

Mark Lord <[email protected]>
Newsgroups gmane.linux.usb.devel,gmane.linux.kernel
Message-ID <[email protected]>
(reposting for linux-usb-devel list)

Greg KH wrote:
> On Wed, Nov 28, 2007 at 11:00:36PM -0500, Mark Lord wrote:
>> While doing insert/remove (quickly) tests on USB, I managed to trigger
>> an Oops on 2.6.23.8 on the call to strlen() in make_class_name().
>>
>> This patch prevents this oops.
>>
>> There is still the larger problem of the overall race
>> that caused this in the first place, but much of the rest
>> of the code in class.c appears to also do NULL checks to
>> avoid Oops'ing, so this continues the tradition.
>>
>> Signed-off-by:  Mark Lord <[email protected]>
>
> As this is a bandage over the real problem, I'd prefer to not apply this
> one right now until we find the root cause.
...

Ahh... okay.. but since nobody is actually actively trying
to "find the root cause", there's a problem with that approach.

Rather than have systems continue to crash (reboot required to regain
use of USB after the Oops), here is an improved version of the patch
that addresses Greg's concern.

This version still prevents the Oops, but also flags the BUG so that
it will not go unnoticed.

This should make everyone happier.

* * * *

While doing insert/remove (quickly) tests on USB, I managed to trigger
an Oops on 2.6.23.1 on the call to strlen() in make_class_name().

This patch prevents the oops, but still keeps the bug visible.

There is still the larger problem of the overall race
that caused this in the first place, but much of the rest
of the code in class.c appears to also do NULL checks to
avoid Oops'ing, so this continues the tradition.

Signed-off-by:  Mark Lord <[email protected]> ---

Patch applies to both 2.6.24 and 2.6.23. 


While doing insert/remove (quickly) tests on USB, I managed to trigger
an Oops on 2.6.23.1 on the call to strlen() in make_class_name().

This patch prevents the oops, but still keeps the bug visible.

There is still the larger problem of the overall race
that caused this in the first place, but much of the rest
of the code in class.c appears to also do NULL checks to
avoid Oops'ing, so this continues the tradition.

Signed-off-by:  Mark Lord <[email protected]> 
---

Patch applies to both 2.6.24 and 2.6.23.

--- linux/drivers/base/class.c.orig	2007-11-29 10:51:43.000000000 -0500
+++ linux/drivers/base/class.c	2007-11-29 10:54:42.000000000 -0500
@@ -354,6 +354,10 @@
 	char *class_name;
 	int size;
 
+	if (!name) {
+		BUG_ON(1);
+		return NULL;
+	}
 	size = strlen(name) + strlen(kobject_name(kobj)) + 2;
 
 	class_name = kmalloc(size, GFP_KERNEL);

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.