scsi: fix hot unplug vs async scan race
PATCH v2 1/1 scsi: fix hot unplug vs async scan race
The following crash results from cases where the end_device has been removed before scsi_sysfs_add_sdev has had a chance to run.
BUG: unable to handle kernel NULL pointer dereference at 0000000000000098 IP: [<ffffffff8115e100>] sysfs_create_dir+0x32/0xb6 ... Call Trace: [<ffffffff8125e4a8>] kobject_add_internal+0x120/0x1e3 [<ffffffff81075149>] ? trace_hardirqs_on+0xd/0xf [<ffffffff8125e641>] kobject_add_varg+0x41/0x50 [<ffffffff8125e70b>] kobject_add+0x64/0x66 [<ffffffff8131122b>] device_add+0x12d/0x63a [<ffffffff814b65ea>] ? _raw_spin_unlock_irqrestore+0x47/0x56 [<ffffffff8107de15>] ? module_refcount+0x89/0xa0 [<ffffffff8132f348>] scsi_sysfs_add_sdev+0x4e/0x28a [<ffffffff8132dcbb>] do_scan_async+0x9c/0x145
...teach scsi_sysfs_add_devices() to check for deleted devices() before trying to add them, and teach scsi_remove_target() how to remove targets that have not been added via device_add().
Cc Mike Christie <[email protected]>
Cc Robert Love <[email protected]>
Cc Nagalakshmi Nandigama <[email protected]>
Cc Kashyap Desai <[email protected]>
Cc Matthew Wilcox <[email protected]>
Reported-by Dariusz Majchrzak <[email protected]>
Signed-off-by Dan Williams <[email protected]>
---
Changes since v1: http://marc.info/?l=linux-scsi&m=133793175125892&w=2
Mike was right to point out that the initial version (having the transport remember the starget) was dangerous. So v2 takes the approach of looking up the starget via scsi structures and not the driver-core (device_for_each_child() is unreliable prior to device_add()).
drivers/scsi/scsi_scan.c | 3 +++ drivers/scsi/scsi_sysfs.c | 41 ++++++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 15 deletions(-)
drivers/scsi/scsi_scan.c +3 -0
@@ -1702,6 +1702,9 @@ static void scsi_sysfs_add_devices(struct Scsi_Host *shost) {struct scsi_device *sdev;shost_for_each_device (sdev, shost) { +/* target removed before the device could be added */ +if (sdev->sdev_state ==SDEV_DEL ) +continue ;if (!scsi_host_scan_allowed (shost) ||scsi_sysfs_add_sdev (sdev) !=0 )__scsi_remove_device (sdev);
drivers/scsi/scsi_sysfs.c +26 -15
61 lines not on this page · raw message