mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jesper Juhl <jj@chaosbits.net>
To: linux-kernel@vger.kernel.org
Cc: linux-usb@vger.kernel.org, Greg Kroah-Hartman <gregkh@suse.de>,
	Sarah Sharp <sarah.a.sharp@linux.intel.com>,
	Alan Stern <stern@rowland.harvard.edu>,
	Andiry Xu <andiry.xu@amd.com>, Luben Tuikov <ltuikov@yahoo.com>
Subject: [PATCH] USB: Avoid NULL pointer dereference in usb_disconnect()
Date: Mon, 11 Jul 2011 11:21:18 +0200 (CEST)	[thread overview]
Message-ID: <alpine.LNX.2.00.1107111119080.4462@swampdragon.chaosbits.net> (raw)

If, in drivers/usb/core/hub.c::usb_disconnect(), 'udev' is NULL, then
we'll never get to the printing of a debug message and returning from
the function since we'll have already dereferenced the NULL pointer in
the bus_to_hcd(udev->bus) call.
This patch moves the dereference to after the test for NULL, thus
avoiding that potential crash.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 drivers/usb/core/hub.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

 disclaimer: compile tested only.

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index a428aa0..0a98c76 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1634,13 +1634,15 @@ void usb_disconnect(struct usb_device **pdev)
 {
 	struct usb_device	*udev = *pdev;
 	int			i;
-	struct usb_hcd		*hcd = bus_to_hcd(udev->bus);
+	struct usb_hcd		*hcd;
 
 	if (!udev) {
 		pr_debug ("%s nodev\n", __func__);
 		return;
 	}
 
+	hcd = bus_to_hcd(udev->bus);
+
 	/* mark the device as inactive, so any further urb submissions for
 	 * this device (and any of its children) will fail immediately.
 	 * this quiesces everything except pending urbs.
-- 
1.7.6


-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.


             reply	other threads:[~2011-07-11  9:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-11  9:21 Jesper Juhl [this message]
2011-07-11  9:36 ` wangyanqing
2011-07-11  9:47   ` Jesper Juhl
2011-07-11 15:01 ` Alan Stern
2011-07-11 20:59   ` Jesper Juhl
2011-07-12  0:50     ` Alan Stern

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=alpine.LNX.2.00.1107111119080.4462@swampdragon.chaosbits.net \
    --to=jj@chaosbits.net \
    --cc=andiry.xu@amd.com \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=ltuikov@yahoo.com \
    --cc=sarah.a.sharp@linux.intel.com \
    --cc=stern@rowland.harvard.edu \
    /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

all inboxes | Powered by JetHome®