]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
libata: fix NULL sdev dereference race in atapi_qc_complete()
authorTejun Heo <tj@kernel.org>
Mon, 1 Nov 2010 10:39:19 +0000 (11:39 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 21 Mar 2011 19:43:58 +0000 (12:43 -0700)
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>
drivers/ata/libata-scsi.c

index d096fbcbc771a61a0537e28842d04f1149dcc7a7..551662456c5983c26a3ad34a2b13da9b371062ab 100644 (file)
@@ -2547,8 +2547,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;