Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4899356imc; Mon, 25 Feb 2019 13:14:22 -0800 (PST) X-Google-Smtp-Source: AHgI3IaGQaYjyXqNFP6r4HfSO8Wn2J9d7HJ18l9H2Cviz+hVrtOtMmwGO4ZB5nxMnhVWD3o+8lfK X-Received: by 2002:a62:e704:: with SMTP id s4mr22160004pfh.94.1551129262929; Mon, 25 Feb 2019 13:14:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551129262; cv=none; d=google.com; s=arc-20160816; b=bWVJI68CgtOGPmrNBCqgpuJXlsp85sCz3aWLXM1BJ0PUo/0e68Fv0o4SiqOC/kfJE3 xRBXQg+HdK36J4ycjlfH7l79RC7kiPysqDQzZ3ZhPulEyeseKQ4wEZyOmowxC8pLPP9F ZgquTeoYvI4HI2/tJ/8rA9sYBnUNW5fthSHdjcsgwXrd2OQjYTfEs6eNfOHE7x5g0zto MBibLTTMs5VBmtygzWhrKVDE4ECTm8hck/ll3jrUOlbV5Yn8LUW8gy6zRvUQsUu37Rtr jyFHCkMfP2h2lapbGfbpCKbMqXnyQ7q8/QTAp6Her2f6jmujYfgtii96HKWDUIc3EFKI hA4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=29sNEFCsccLDZoj6ukoQC6uxc9t8fOjXQzvwNjoHEgE=; b=D27Gah1CVBWmg5iM29MOBSXGAIFwivMGizX2muv7ILeFqs634be+qlMhPHKkV/XDnR /OuXb93D9bLlmgpo2FT1Ye+vp3ukTllt22Nz5k77oJXOPJBEagGyBwbcC0852WcXslqJ IbAFmZRu7EJSIwP1T3cyiV4Aju2u3FrBAGetzDPCxY96jIDOSyVpxjKssBNsrEMo6pNO foGrCZHc5SVLir5ujpCkdPfgEJ4C8wcGcF6dNWA7BC66shTLUu2b1YlBJMBWtZ9LN3xz wT0Xda3HVBSK79wFVpVu86aRTarIQLut1JpXs9ORAIKS1yP6lxRJkmNyXcVbtZG7Zc2g UlOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LE9KInXu; 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 31si10658251plg.291.2019.02.25.13.14.07; Mon, 25 Feb 2019 13:14:22 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=LE9KInXu; 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 S1728921AbfBYVNY (ORCPT + 99 others); Mon, 25 Feb 2019 16:13:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:43842 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728911AbfBYVNT (ORCPT ); Mon, 25 Feb 2019 16:13:19 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 40DF12084D; Mon, 25 Feb 2019 21:13:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551129198; bh=Rc5/MBu9q2fJsRPCnc5afK3+3VsiqnmU4nHBm3KmU7U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LE9KInXuSBztt+zTzt9nkwDPMR4Dk7ulCWrWAdmqklg38POtB+uEavqVrka3mZOzz XWd3aoflEVSs1BNt2ESDs/5GL6vRrn2VFzN5ASyifweN+Ty973uU+XMquTxkSrzNMH EUgrYxTMPDJANDiMhjP/GETzyV5Rqzb61NU+HU+I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Logan Gunthorpe , Intel SCU Linux support , Artur Paszkiewicz , "James E.J. Bottomley" , "Martin K. Petersen" , Christoph Hellwig , Jens Axboe , Jeff Moyer , Sasha Levin Subject: [PATCH 4.9 19/63] scsi: isci: initialize shost fully before calling scsi_add_host() Date: Mon, 25 Feb 2019 22:11:19 +0100 Message-Id: <20190225195037.186041063@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190225195035.713274200@linuxfoundation.org> References: <20190225195035.713274200@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit cc29a1b0a3f2597ce887d339222fa85b9307706d ] scsi_mq_setup_tags(), which is called by scsi_add_host(), calculates the command size to allocate based on the prot_capabilities. In the isci driver, scsi_host_set_prot() is called after scsi_add_host() so the command size gets calculated to be smaller than it needs to be. Eventually, scsi_mq_init_request() locates the 'prot_sdb' after the command assuming it was sized correctly and a buffer overrun may occur. However, seeing blk_mq_alloc_rqs() rounds up to the nearest cache line size, the mistake can go unnoticed. The bug was noticed after the struct request size was reduced by commit 9d037ad707ed ("block: remove req->timeout_list") Which likely reduced the allocated space for the request by an entire cache line, enough that the overflow could be hit and it caused a panic, on boot, at: RIP: 0010:t10_pi_complete+0x77/0x1c0 Call Trace: sd_done+0xf5/0x340 scsi_finish_command+0xc3/0x120 blk_done_softirq+0x83/0xb0 __do_softirq+0xa1/0x2e6 irq_exit+0xbc/0xd0 call_function_single_interrupt+0xf/0x20 sd_done() would call scsi_prot_sg_count() which reads the number of entities in 'prot_sdb', but seeing 'prot_sdb' is located after the end of the allocated space it reads a garbage number and erroneously calls t10_pi_complete(). To prevent this, the calls to scsi_host_set_prot() are moved into isci_host_alloc() before the call to scsi_add_host(). Out of caution, also move the similar call to scsi_host_set_guard(). Fixes: 3d2d75254915 ("[SCSI] isci: T10 DIF support") Link: http://lkml.kernel.org/r/da851333-eadd-163a-8c78-e1f4ec5ec857@deltatee.com Signed-off-by: Logan Gunthorpe Cc: Intel SCU Linux support Cc: Artur Paszkiewicz Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: Christoph Hellwig Cc: Jens Axboe Cc: Jeff Moyer Reviewed-by: Jeff Moyer Reviewed-by: Jens Axboe Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/isci/init.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/isci/init.c b/drivers/scsi/isci/init.c index 77128d680e3bc..6f38fa1f468a7 100644 --- a/drivers/scsi/isci/init.c +++ b/drivers/scsi/isci/init.c @@ -595,6 +595,13 @@ static struct isci_host *isci_host_alloc(struct pci_dev *pdev, int id) shost->max_lun = ~0; shost->max_cmd_len = MAX_COMMAND_SIZE; + /* turn on DIF support */ + scsi_host_set_prot(shost, + SHOST_DIF_TYPE1_PROTECTION | + SHOST_DIF_TYPE2_PROTECTION | + SHOST_DIF_TYPE3_PROTECTION); + scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); + err = scsi_add_host(shost, &pdev->dev); if (err) goto err_shost; @@ -682,13 +689,6 @@ static int isci_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto err_host_alloc; } pci_info->hosts[i] = h; - - /* turn on DIF support */ - scsi_host_set_prot(to_shost(h), - SHOST_DIF_TYPE1_PROTECTION | - SHOST_DIF_TYPE2_PROTECTION | - SHOST_DIF_TYPE3_PROTECTION); - scsi_host_set_guard(to_shost(h), SHOST_DIX_GUARD_CRC); } err = isci_setup_interrupts(pdev); -- 2.19.1