diff options
author | Tejun Heo <tj@kernel.org> | 2010-11-01 06:39:19 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@redhat.com> | 2010-11-12 17:10:51 -0500 |
commit | 2a5f07b5ec098edc69e05fdd2f35d3fbb1235723 (patch) | |
tree | 28180df99e2b236018c29dd05480b13024159868 /drivers/ata/libata-scsi.c | |
parent | a0a6da1a735ba66c04019b39cca8f79008d6c434 (diff) |
libata: fix NULL sdev dereference race in atapi_qc_complete()
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>
Cc: stable@kernel.org
Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
Diffstat (limited to 'drivers/ata/libata-scsi.c')
-rw-r--r-- | drivers/ata/libata-scsi.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index d050e073e570..3f91c01c217f 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c | |||
@@ -2552,8 +2552,11 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc) | |||
2552 | * | 2552 | * |
2553 | * If door lock fails, always clear sdev->locked to | 2553 | * If door lock fails, always clear sdev->locked to |
2554 | * avoid this infinite loop. | 2554 | * avoid this infinite loop. |
2555 | * | ||
2556 | * This may happen before SCSI scan is complete. Make | ||
2557 | * sure qc->dev->sdev isn't NULL before dereferencing. | ||
2555 | */ | 2558 | */ |
2556 | if (qc->cdb[0] == ALLOW_MEDIUM_REMOVAL) | 2559 | if (qc->cdb[0] == ALLOW_MEDIUM_REMOVAL && qc->dev->sdev) |
2557 | qc->dev->sdev->locked = 0; | 2560 | qc->dev->sdev->locked = 0; |
2558 | 2561 | ||
2559 | qc->scsicmd->result = SAM_STAT_CHECK_CONDITION; | 2562 | qc->scsicmd->result = SAM_STAT_CHECK_CONDITION; |