Skip to content

Commit 5da5231

Browse files
gkennedy12Damien Le Moal
authored andcommitted
libata: if T_LENGTH is zero, dma direction should be DMA_NONE
Avoid data corruption by rejecting pass-through commands where T_LENGTH is zero (No data is transferred) and the dma direction is not DMA_NONE. Cc: <[email protected]> Reported-by: syzkaller<[email protected]> Signed-off-by: George Kennedy<[email protected]> Signed-off-by: Damien Le Moal <[email protected]>
1 parent 2585cf9 commit 5da5231

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

drivers/ata/libata-scsi.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,8 +2859,19 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc)
28592859
goto invalid_fld;
28602860
}
28612861

2862-
if (ata_is_ncq(tf->protocol) && (cdb[2 + cdb_offset] & 0x3) == 0)
2863-
tf->protocol = ATA_PROT_NCQ_NODATA;
2862+
if ((cdb[2 + cdb_offset] & 0x3) == 0) {
2863+
/*
2864+
* When T_LENGTH is zero (No data is transferred), dir should
2865+
* be DMA_NONE.
2866+
*/
2867+
if (scmd->sc_data_direction != DMA_NONE) {
2868+
fp = 2 + cdb_offset;
2869+
goto invalid_fld;
2870+
}
2871+
2872+
if (ata_is_ncq(tf->protocol))
2873+
tf->protocol = ATA_PROT_NCQ_NODATA;
2874+
}
28642875

28652876
/* enable LBA */
28662877
tf->flags |= ATA_TFLAG_LBA;

0 commit comments

Comments
 (0)