Received: by 10.213.65.68 with SMTP id h4csp886416imn; Tue, 27 Mar 2018 10:35:30 -0700 (PDT) X-Google-Smtp-Source: AIpwx48FpvSh4T6aMb8pf7lVvlf0l8sT9vp8VZ5SWGqiwHxhOvLMIlCUFFyZpjMcN0aJlbCTI0O9 X-Received: by 2002:a17:902:7084:: with SMTP id z4-v6mr205161plk.395.1522172130265; Tue, 27 Mar 2018 10:35:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522172130; cv=none; d=google.com; s=arc-20160816; b=x+amKIy+gpUkfkfd9RpuNfxrG8qfEE+H6AmzntrK2yBfVc5sboaqm1+EeaFXS0SlXZ FeXUJgJU+O0yKbuaVNtuKVAqEtHZvKNHHmyECAfiBASplXpl9jSVZO88Ki6Ay6ZMN3nt Dx8XrICxLdzcBaqBi1fITb5EIQplRFgrILs4nADasXHDwhJqT3Zb8W0jYIejFnlnILWQ 6v0VFZdZkBOvsFkBgiOAscH4p2zxj+Ynys0yTMXNa3l8W23d6RSsM3pMnIaNhV7WGMKV CUzj+HtOqeBk/U7wMY80cdcZd1bspytT3O5hUF0cSm23T4V4iEfxXs7gjvZRn2qsOn1c VcFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ZrxYz/gUm33Gv7DZB7Jnw+cvqXPZGIDjK5tudDYeUnE=; b=nDORg90hCCXlzZ2zDO4Lx/CmwRUu4CC27Gs+PE+Z0Y+3hlqZCInu8CLVep2Q9ULyMW PO+gHkwnj3P+qMvwjDuzWihPAqr16yMC4bLcMswwqJnOKnIQpSDiNyw6VD1HT0CYIUN6 s7VkqQxB3KPhBq9jXUF+i+Cu2VSDOnhji3MRvcZEPag+zxP9nN4/YfkuJzwAYAC0aGWw nOX81C+stZBtB7I0MYUUtGzfKKI6YpFSDs+KjVRb/iO+ZQSLCRwNcQoo31b/U9LzrNdR aZml+T6uA4fK4vz7jsA4K+3BXd5YisHAk9JuP0TdZA9X50THCOa7pLVrZwmpUkmnIThi UXlg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q12-v6si1825387pll.419.2018.03.27.10.35.15; Tue, 27 Mar 2018 10:35:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754420AbeC0QfL (ORCPT + 99 others); Tue, 27 Mar 2018 12:35:11 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44706 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754344AbeC0QfJ (ORCPT ); Tue, 27 Mar 2018 12:35:09 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 86DC51226; Tue, 27 Mar 2018 16:35:08 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+2f69ca28df61bdfc77cd36af2e789850355a221e@syzkaller.appspotmail.com, Eric Biggers , Tejun Heo Subject: [PATCH 4.14 036/101] libata: dont try to pass through NCQ commands to non-NCQ devices Date: Tue, 27 Mar 2018 18:27:08 +0200 Message-Id: <20180327162752.221720085@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162749.993880276@linuxfoundation.org> References: <20180327162749.993880276@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers commit 2c1ec6fda2d07044cda922ee25337cf5d4b429b3 upstream. 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 #include 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)); } Fixes: ee7fb331c3ac ("libata: add support for NCQ commands for SG interface") Reported-by: syzbot+2f69ca28df61bdfc77cd36af2e789850355a221e@syzkaller.appspotmail.com Cc: # v4.4+ Signed-off-by: Eric Biggers Signed-off-by: Tejun Heo Signed-off-by: Greg Kroah-Hartman --- drivers/ata/libata-scsi.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -3315,6 +3315,12 @@ static unsigned int ata_scsi_pass_thru(s 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;