On Sat, Feb 03, 2018 at 08:30:56PM -0800, Eric Biggers wrote: > From: Eric Biggers <ebigg...@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. -- tejun