Skip to content

Commit c1d5192

Browse files
gkennedy12gregkh
authored andcommitted
libata: if T_LENGTH is zero, dma direction should be DMA_NONE
commit 5da5231 upstream. 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: <stable@vger.kernel.org> Reported-by: syzkaller<syzkaller@googlegroups.com> Signed-off-by: George Kennedy<george.kennedy@oracle.com> Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a9f2c6a commit c1d5192

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
@@ -2870,8 +2870,19 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc)
28702870
goto invalid_fld;
28712871
}
28722872

2873-
if (ata_is_ncq(tf->protocol) && (cdb[2 + cdb_offset] & 0x3) == 0)
2874-
tf->protocol = ATA_PROT_NCQ_NODATA;
2873+
if ((cdb[2 + cdb_offset] & 0x3) == 0) {
2874+
/*
2875+
* When T_LENGTH is zero (No data is transferred), dir should
2876+
* be DMA_NONE.
2877+
*/
2878+
if (scmd->sc_data_direction != DMA_NONE) {
2879+
fp = 2 + cdb_offset;
2880+
goto invalid_fld;
2881+
}
2882+
2883+
if (ata_is_ncq(tf->protocol))
2884+
tf->protocol = ATA_PROT_NCQ_NODATA;
2885+
}
28752886

28762887
/* enable LBA */
28772888
tf->flags |= ATA_TFLAG_LBA;

0 commit comments

Comments
 (0)