summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2010-11-01 11:39:19 +0100
committerGreg Kroah-Hartman <gregkh@suse.de>2010-12-09 13:24:17 -0800
commit330b3db2ccf393581e2c06d2cb36e0689dd585e3 (patch)
tree7dcbb5a4df689809dfd1e60181b9781ccaeedc2b
parent99b6f6c69d47e4e61856884e96020bb4a57d6158 (diff)
downloadlwn-330b3db2ccf393581e2c06d2cb36e0689dd585e3.tar.gz
lwn-330b3db2ccf393581e2c06d2cb36e0689dd585e3.zip
libata: fix NULL sdev dereference race in atapi_qc_complete()
commit 2a5f07b5ec098edc69e05fdd2f35d3fbb1235723 upstream. SCSI commands may be issued between __scsi_add_device() and dev->sdev assignment, so it's unsafe for ata_qc_complete() to dereference dev->sdev->locked without checking whether it's NULL or not. Fix it. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jeff Garzik <jgarzik@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/ata/libata-scsi.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index b9d3ba423cb2..feba4256aa59 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -2371,8 +2371,11 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc)
*
* If door lock fails, always clear sdev->locked to
* avoid this infinite loop.
+ *
+ * This may happen before SCSI scan is complete. Make
+ * sure qc->dev->sdev isn't NULL before dereferencing.
*/
- if (qc->cdb[0] == ALLOW_MEDIUM_REMOVAL)
+ if (qc->cdb[0] == ALLOW_MEDIUM_REMOVAL && qc->dev->sdev)
qc->dev->sdev->locked = 0;
qc->scsicmd->result = SAM_STAT_CHECK_CONDITION;