lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20101206133028.GB19448@joejin-pc.cn.oracle.com>
Date:	Mon, 6 Dec 2010 21:30:28 +0800
From:	Joe Jin <joe.jin@...cle.com>
To:	"James E.J. Bottomley" <James.Bottomley@...e.de>
Cc:	linux-scsi@...r.kernel.org, linux-kernel@...r.kernel.org,
	greg.marsden@...cle.com, guru.anbalagane@...cle.com,
	joe.jin@...cle.com
Subject: [PATCH 1/1] SCSI: fix scsi disk hotpulg/hotunplug race

Hi,

Trigger scsi scan when plug new disk, device also support disk
hotplug and auto scan disk, it may allocate scsi_target for same
target more then one by call scsi_alloc_target(),  this caused by
the race of __scsi_add_device() and scsi_scan_host_selected().

Cc: "James E.J. Bottomley" <James.Bottomley@...e.de>
Signed-off-by: Joe Jin <joe.jin@...cle.com>

---
 scsi_scan.c |    8 +++++---

diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 087821f..2429771 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1508,12 +1508,14 @@ struct scsi_device *__scsi_add_device(struct Scsi_Host *shost, uint channel,
 	if (strncmp(scsi_scan_type, "none", 4) == 0)
 		return ERR_PTR(-ENODEV);
 
+	mutex_lock(&shost->scan_mutex);
 	starget = scsi_alloc_target(parent, channel, id);
-	if (!starget)
+	if (!starget) {
+		mutex_unlock(&shost->scan_mutex);
 		return ERR_PTR(-ENOMEM);
+	}
 	scsi_autopm_get_target(starget);
 
-	mutex_lock(&shost->scan_mutex);
 	if (!shost->async_scan)
 		scsi_complete_async_scans();
 
@@ -1521,10 +1523,10 @@ struct scsi_device *__scsi_add_device(struct Scsi_Host *shost, uint channel,
 		scsi_probe_and_add_lun(starget, lun, NULL, &sdev, 1, hostdata);
 		scsi_autopm_put_host(shost);
 	}
-	mutex_unlock(&shost->scan_mutex);
 	scsi_autopm_put_target(starget);
 	scsi_target_reap(starget);
 	put_device(&starget->dev);
+	mutex_unlock(&shost->scan_mutex);
 
 	return sdev;
 }

-- 
Oracle <http://www.oracle.com>
Joe Jin | Team Leader, Software Development | +8610.8278.6295
ORACLE | Linux and Virtualization
Incubator Building 2-A ZPark | Beijing China, 100094


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ