FAILED: patch "[PATCH] libata: don't try to pass through NCQ commands to non-NCQ" failed to apply to 4.4-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 4.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
Quoted 1 line
From
2c1ec6fda2d07044cda922ee25337cf5d4b429b3Mon Sep 17 00:00:00 2001
From: Eric Biggers <[email protected]>
Date: Sat, 3 Feb 2018 20:33:51 -0800
Subject: [PATCH] libata: don't try to pass through NCQ commands to non-NCQ
devices
syzkaller hit a WARN() in ata_bmdma_qc_issue() when writing to /dev/sg0. This happened because it issued an ATA pass-through command (ATA_16) where the protocol field indicated that NCQ should be used -- but the device did not support NCQ.
We could just remove the WARN() from libata-sff.c, but the real problem seems to be that the SCSI -> ATA translation code passes through NCQ commands without verifying that the device actually supports NCQ.
Fix this by adding the appropriate check to ata_scsi_pass_thru().
Here's reproducer that works in QEMU when /dev/sg0 refers to a disk of the default type ("82371SB PIIX3 IDE"):
#include <fcntl.h>
#include <unistd.h>
int main()
{
char buf[53] = { 0 };
buf[36] = 0x85; /* ATA_16 */
buf[37] = (12 << 1); /* FPDMA */
buf[38] = 0x1; /* Has data */
buf[51] = 0xC8; /* ATA_CMD_READ */
write(open("/dev/sg0", O_RDWR), buf, sizeof(buf));
}drivers/ata/libata-scsi.c +6 -0
@@ -3316,6 +3316,12 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc) goto invalid_fld; } +/* We may not issue NCQ commands to devices not supporting NCQ */ +if (ata_is_ncq (tf->protocol) && !ata_ncq_enabled (dev)) { + fp =1 ; + goto invalid_fld; + } +/* sanity check for pio multi commands */ if ((cdb[1 ] &0xe0 ) && !is_multi_taskfile (tf)) { fp =1 ;