[SCSI] fix crash when disconnecting usb storage
authorAlexey Kuznetsov <[email protected]>
Tue, 17 Nov 2009 22:10:11 +0000 (14:10 -0800)
committerJames Bottomley <[email protected]>
Thu, 26 Nov 2009 16:04:22 +0000 (10:04 -0600)
__scsi_remove_device() in scsi_forget_host() is executed out of scan_mutex
and races with scsi_destroy_sdev() <- scsi_sysfs_add_devices() <-
scsi_finish_async_scan().  The result is use after free and/or double
free, oops.

The fix is simple, move scsi_forget_host() under scan_mutex.

scsi_forget_host() is just sequence of __scsi_remove_device().  All
another calls of __scsi_remove_device() are made under scan_mutex.  So
that it is safe.

Signed-off-by: Alexey Kuznetsov <[email protected]>
Signed-off-by: Denis V. Lunev <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: James Bottomley <[email protected]>
drivers/scsi/hosts.c

index 5fd2da494d087da334b65b9bd88b2945191184ff..c968cc31cd862514ae432eee7573d6ade5277863 100644 (file)
@@ -164,8 +164,8 @@ void scsi_remove_host(struct Scsi_Host *shost)
                        return;
                }
        spin_unlock_irqrestore(shost->host_lock, flags);
-       mutex_unlock(&shost->scan_mutex);
        scsi_forget_host(shost);
+       mutex_unlock(&shost->scan_mutex);
        scsi_proc_host_rm(shost);
 
        spin_lock_irqsave(shost->host_lock, flags);