[PATCH] firewire: fw-sbp2: fix NULL pointer deref inscsi_remove_device

From: Stefan Richter
Date: Sun Feb 17 2008 - 13:17:30 EST


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@xxxxxxxxxxxxxxxxx>
---
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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/