lkml.org 
[lkml]   [2008]   [Feb]   [17]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
DateSun, 17 Feb 2008 19:17:04 +0100 (CET)
FromStefan Richter <>
Subject[PATCH] firewire: fw-sbp2: fix NULL pointer deref in scsi_remove_device
I wrote:
> There is unfortunately another bug.  If the user manually removes the
> scsi_device by writing into its "delete" sysfs attribute, the following
> will happen when the SBP-2 device is plugged out:
> 
> BUG: unable to handle kernel NULL pointer dereference at 00000000000000b8
> IP: [<ffffffff804188c6>] mutex_lock_nested+0x7b/0x270
...
> Call Trace:
>  [<ffffffff8041a305>] ? _spin_unlock_irqrestore+0x49/0x68
>  [<ffffffff8036a670>] ? scsi_remove_device+0x1e/0x33
>  [<ffffffff880ef799>] ? :firewire_sbp2:sbp2_release_target+0x33/0xca
>  [<ffffffff880ef766>] ? :firewire_sbp2:sbp2_release_target+0x0/0xca
>  [<ffffffff802ec6df>] ? kref_put+0x41/0x4c
>  [<ffffffff880ef117>] ? :firewire_sbp2:sbp2_remove+0x10/0x14
...
> ---[ end trace 2a9c61e9883e29d2 ]---
> 

Fix a kernel bug when unplugging an SBP-2 device after having its
scsi_device already removed via the "delete" sysfs attribute.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
---
 drivers/firewire/fw-sbp2.c |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
Index: linux-2.6.25-rc2/drivers/firewire/fw-sbp2.c
===================================================================
--- linux-2.6.25-rc2.orig/drivers/firewire/fw-sbp2.c
+++ linux-2.6.25-rc2/drivers/firewire/fw-sbp2.c
@@ -762,9 +762,10 @@ static void sbp2_release_target(struct k
 	sbp2_unblock(tgt);
 
 	list_for_each_entry_safe(lu, next, &tgt->lu_list, link) {
-		if (lu->sdev)
+		if (lu->sdev) {
 			scsi_remove_device(lu->sdev);
-
+			scsi_device_put(lu->sdev);
+		}
 		sbp2_send_management_orb(lu, tgt->node_id, lu->generation,
 				SBP2_LOGOUT_REQUEST, lu->login_id, NULL);
 
@@ -886,8 +887,6 @@ static void sbp2_login(struct work_struc
 	if (IS_ERR(sdev))
 		goto out_logout_login;
 
-	scsi_device_put(sdev);
-
 	/* Unreported error during __scsi_add_device() */
 	smp_rmb(); /* get current card generation */
 	if (generation != device->card->generation) {
-- 
Stefan Richter
-=====-==--- --=- =---=
http://arcgraph.de/sr/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2008-02-17 19:19    [from the cache]
©2003-2008