Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4916052imc; Mon, 25 Feb 2019 13:33:47 -0800 (PST) X-Google-Smtp-Source: AHgI3IYi6KbZ1hcrM8DMEXbGfq9YG3bi09zLexvEG2JTm/oYktDa1cceCYPpIUsJqFpINvNfZ5Q/ X-Received: by 2002:a65:448b:: with SMTP id l11mr21026122pgq.450.1551130427490; Mon, 25 Feb 2019 13:33:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551130427; cv=none; d=google.com; s=arc-20160816; b=HZjSxxpVhGKIsriB1RrM6O40dLosS62iKgseRatIHk0/70wnbtSQBzfm+EEsHrzRqC ll29sCGKuNY59D8/xd8hEVBSNC2Vd9NT+tFgVffdY9vgVeobqKmQaqwSypxFChoxbvr1 b/N1+PvE26Zn/mrphLM9VhAAw2dM7dYT3uCTdF0ZOf66KgW00RvReBm/tb84WrISjEv8 UyMGucTj73608/tjxIgsfWo3PP/69m9ZqBQMpp8p95YiB9OguuXCiODdcmqann+9/7ex IcYjK+0xlAbxx8ADHVYVlmJANSYYsBEisDJNSNTfM6uxkrnm9kkoyuGEyVZNcuze1PwC 2Dwg== 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=zGUefPu8k8Nr3AFlkSD/6/LzXfqV9nvSh3oJ+38AE4w=; b=eMRJ/rz+hyELdbsrSufYnS+CxBb4fQQ3t2RrxxiDSnlubAg161l7jQMPDpoQFULQo/ yuhXo82tg6DRGNhKV20FTsBqgOqrJqaEWiaxFIYQNyzlx/0vIlpMX8lWXBFMkxHfoG/C j56o61cUT59uF9cd5+PiIfMVA9/HGDFY3qXO4T4j+BHr+A2THWViEuwQGTisuwvUsCR7 gB/udPTJXt3rbQMpL7XZz6k5LiYBzximDPeAytz2Mp6rjRQ27vyge+OiKBR3G23dHMLt A8l9ViDkH/I6MNjmIYCmOuvprmBZuwj8OQ81G7Cd6IANPILksVs0uScKPD2qsAKS3Y/n 2yyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KCEL6vjC; 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 h128si9971894pgc.397.2019.02.25.13.33.32; Mon, 25 Feb 2019 13:33:47 -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=KCEL6vjC; 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 S1732623AbfBYVdL (ORCPT + 99 others); Mon, 25 Feb 2019 16:33:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:39294 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732601AbfBYVdJ (ORCPT ); Mon, 25 Feb 2019 16:33:09 -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 8B3CD21852; Mon, 25 Feb 2019 21:33:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551130388; bh=milFHRWB9DVF009BcItAa38KjFotodjNbYuiQNgiR2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KCEL6vjCZh2iGz4nq/Bb/BvxtdoFYuR40nSM3ampABspKdGtdvazLh+gekMDqjieD G4NkjSJnw7KswM1AjsKUWJpVie7Ytw0snJoazbz5GPHnZM/L+w4QJtCohpscSqycNb D1O0Tt2C09biAiN0i6XA5Tov8K1Owqy1DYwYntbk= 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.20 058/183] scsi: isci: initialize shost fully before calling scsi_add_host() Date: Mon, 25 Feb 2019 22:10:31 +0100 Message-Id: <20190225195104.262440636@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190225195054.748060397@linuxfoundation.org> References: <20190225195054.748060397@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.20-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 08c7b1e25fe48..dde84f7443136 100644 --- a/drivers/scsi/isci/init.c +++ b/drivers/scsi/isci/init.c @@ -588,6 +588,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; @@ -675,13 +682,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