Commit 4e46bf89972b9d98a9f282a9fed2359756a5e34e

Authored by Alexey Kuznetsov
Committed by James Bottomley
1 parent 860dc73608

[SCSI] fix crash when disconnecting usb storage

__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 <kuznet@ms2.inr.ac.ru>
Signed-off-by: Denis V. Lunev <den@openvz.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>

Showing 1 changed file with 1 additions and 1 deletions Side-by-side Diff

drivers/scsi/hosts.c
... ... @@ -164,8 +164,8 @@
164 164 return;
165 165 }
166 166 spin_unlock_irqrestore(shost->host_lock, flags);
167   - mutex_unlock(&shost->scan_mutex);
168 167 scsi_forget_host(shost);
  168 + mutex_unlock(&shost->scan_mutex);
169 169 scsi_proc_host_rm(shost);
170 170  
171 171 spin_lock_irqsave(shost->host_lock, flags);