public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 5/5] SCSI: fix target allocation outside of scan_mutex
@ 2010-02-12 17:14 Alan Stern
  2010-02-19 16:34 ` James Bottomley
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Stern @ 2010-02-12 17:14 UTC (permalink / raw)
  To: James Bottomley; +Cc: SCSI development list

This patch (as1337) fixes a bug in __scsi_add_device().  It calls
scsi_alloc_target() outside the protection of the host's scan_mutex,
meaning that it might find an incompletely-initialized target or it
might create a duplicate target.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>

---

Index: usb-2.6/drivers/scsi/scsi_scan.c
===================================================================
--- usb-2.6.orig/drivers/scsi/scsi_scan.c
+++ usb-2.6/drivers/scsi/scsi_scan.c
@@ -1506,25 +1506,29 @@ struct scsi_device *__scsi_add_device(st
 {
 	struct scsi_device *sdev = ERR_PTR(-ENODEV);
 	struct device *parent = &shost->shost_gendev;
-	struct scsi_target *starget;
+	struct scsi_target *starget = NULL;
 
 	if (strncmp(scsi_scan_type, "none", 4) == 0)
-		return ERR_PTR(-ENODEV);
-
-	starget = scsi_alloc_target(parent, channel, id);
-	if (!starget)
-		return ERR_PTR(-ENOMEM);
+		return sdev;
 
 	mutex_lock(&shost->scan_mutex);
 	if (!shost->async_scan)
 		scsi_complete_async_scans();
 
-	if (scsi_host_scan_allowed(shost))
-		scsi_probe_and_add_lun(starget, lun, NULL, &sdev, 1, hostdata);
+	if (scsi_host_scan_allowed(shost)) {
+		starget = scsi_alloc_target(parent, channel, id);
+		if (starget)
+			scsi_probe_and_add_lun(starget, lun, NULL, &sdev,
+					1, hostdata);
+		else
+			sdev = ERR_PTR(-ENOMEM);
+	}
 	mutex_unlock(&shost->scan_mutex);
-	scsi_target_reap(starget);
-	put_device(&starget->dev);
 
+	if (starget) {
+		scsi_target_reap(starget);
+		put_device(&starget->dev);
+	}
 	return sdev;
 }
 EXPORT_SYMBOL(__scsi_add_device);


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-03-13 15:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-12 17:14 [PATCH 5/5] SCSI: fix target allocation outside of scan_mutex Alan Stern
2010-02-19 16:34 ` James Bottomley
2010-02-19 20:21   ` Alan Stern
2010-03-12 21:45     ` James Bottomley
2010-03-13 15:51       ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox