mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Lord <lkml@rtr.ca>
To: Greg KH <gregkh@suse.de>
Cc: Linux Kernel <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-usb-devel@lists.sourceforge.net
Subject: [PATCH] base/class.c: prevent ooops due to insert/remove race (v3)
Date: Thu, 29 Nov 2007 13:09:53 -0500	[thread overview]
Message-ID: <474F0071.5010507@rtr.ca> (raw)
In-Reply-To: <474EFBFF.9090400@rtr.ca>

Mark Lord wrote:
> Mark Lord wrote:
>> Mark Lord wrote:
>> ...
>> And here is a "prevented" oops, courtesy of the patch (2.6.23.8).
>> These are easy to reproduce (just jiggle the connection on an
>> attached USB multi-card reader with a CF card inserted):
> ...
>> [  347.099562] usb 5-6: USB disconnect, address 10
>> [  347.101077] BUG: unable to handle kernel NULL pointer dereference 
>> at virtual address 00000000
> 
> ...
> 
> 
> Mmmm.. that's odd.  It *did* Oops there.  I wonder how/why ?
...

Ahh.. it was the *other* call to strlen() that was crapping out.
Here's an updated patch to prevent the Oops:

* * * *

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

USB maintainers can try this themselves, by plugging in an
external USB XX-in-1 flash reader, with a CF card inserted.
Then just jiggle the connection so that the device connects
and disconnects rapidly.  This may not sound realistic,
but there's definitely a race in there, and this is a quick
way to reproduce it if need be.

The patch below prevents the oops, but still keeps the bug visible.

Signed-off-by:  Mark Lord <mlord@pobox.com> 
---

Patch applies to both 2.6.24 and 2.6.23.

--- old/drivers/base/class.c	2007-11-29 10:51:43.000000000 -0500
+++ linux/drivers/base/class.c	2007-11-29 13:00:15.000000000 -0500
@@ -352,9 +352,22 @@
 char *make_class_name(const char *name, struct kobject *kobj)
 {
 	char *class_name;
+	const char *kname;
 	int size;
 
-	size = strlen(name) + strlen(kobject_name(kobj)) + 2;
+	/* Rapidly inserting/removing a USB device (others?)
+	 * can trigger an Oops on the strlen() call.
+	 * Cause unknown yet, so prevent the Oops
+	 * but don't mask the issue.
+	 */
+	kname = kobject_name(kobj);
+	if (!kname || !name) {
+		printk(KERN_ERR "make_class_name: name=%p kname=%p\n",
+						name, kname);
+		BUG_ON(1);
+		return NULL;
+	}
+	size = strlen(name) + strlen(kname) + 2;
 
 	class_name = kmalloc(size, GFP_KERNEL);
 	if (!class_name)

  reply	other threads:[~2007-11-29 18:10 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-29  4:00 [PATCH] base/class.c: prevent ooops due to insert/remove race Mark Lord
2007-11-29  4:33 ` Greg KH
2007-11-29 15:41   ` Mark Lord
2007-11-29 16:27     ` Greg KH
2007-11-29 17:45       ` Mark Lord
2007-11-29 17:48         ` Mark Lord
2007-11-29 17:50           ` Mark Lord
2007-11-29 18:09             ` Mark Lord [this message]
2007-11-29 18:12               ` [PATCH] base/class.c: prevent ooops due to insert/remove race (v3) Mark Lord
2007-11-29 19:20                 ` [linux-usb-devel] " Alan Stern
2007-11-29 20:01                   ` Mark Lord
2007-11-29 20:12                     ` Greg KH
     [not found]                       ` <474F1DB3.4030900@rtr.ca>
2007-11-29 20:25                         ` Mark Lord
2007-11-29 20:32                           ` Greg KH
2007-11-29 20:46                             ` Mark Lord
2007-11-29 21:17                               ` Greg KH
2007-11-29 22:07                               ` Alan Stern
2007-11-29 22:11                                 ` Greg KH
2007-11-29 22:28                                 ` Mark Lord
2007-11-29 22:43                                   ` Alan Stern
2007-11-29 23:09                                 ` Linus Torvalds
2007-11-30  2:58                                   ` Alan Stern
2007-11-29 20:13                     ` Alan Stern
2007-11-29 20:17                       ` Mark Lord
2007-11-29 20:20                       ` Mark Lord
2007-11-29 21:59                         ` Alan Stern
2007-11-29 15:59   ` [PATCH] base/class.c: prevent ooops due to insert/remove race (v2) Mark Lord

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=474F0071.5010507@rtr.ca \
    --to=lkml@rtr.ca \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome