Message ID | 20180204043056.16466-1-ebiggers3@gmail.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
On Sat, Feb 03, 2018 at 08:30:56PM -0800, Eric Biggers wrote: > From: Eric Biggers <ebiggers@google.com> > > syzkaller reported a crash in ata_bmdma_fill_sg() when writing to > /dev/sg1. The immediate cause was that the ATA command's scatterlist > was not DMA-mapped, which causes 'pi - 1' to underflow, resulting in a > write to 'qc->ap->bmdma_prd[0xffffffff]'. > > Strangely though, the flag ATA_QCFLAG_DMAMAP was set in qc->flags. The > root cause is that when __ata_scsi_queuecmd() is preparing to relay a > SCSI command to an ATAPI device, it doesn't correctly validate the CDB > length before copying it into the 16-byte buffer 'cdb' in 'struct > ata_queued_cmd'. Namely, it validates the fixed CDB length expected > based on the SCSI opcode but not the actual CDB length, which can be > larger due to the use of the SG_NEXT_CMD_LEN ioctl. Since 'flags' is > the next member in ata_queued_cmd, a buffer overflow corrupts it. > > Fix it by requiring that the actual CDB length be <= 16 (ATAPI_CDB_LEN). Applied to libata/for-4.16-fixes. Thanks.
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 66be961c93a4e..47d421666451c 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -4309,7 +4309,9 @@ static inline int __ata_scsi_queuecmd(struct scsi_cmnd *scmd, if (likely((scsi_op != ATA_16) || !atapi_passthru16)) { /* relay SCSI command to ATAPI device */ int len = COMMAND_SIZE(scsi_op); - if (unlikely(len > scmd->cmd_len || len > dev->cdb_len)) + if (unlikely(len > scmd->cmd_len || + len > dev->cdb_len || + scmd->cmd_len > ATAPI_CDB_LEN)) goto bad_cdb_len; xlat_func = atapi_xlat;