Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp71910imu; Tue, 8 Jan 2019 14:55:45 -0800 (PST) X-Google-Smtp-Source: ALg8bN5y0TkFbpfd2avegi28my3ZQ+UTTPumHjVS26+tnGnytT3a5EpyAiElkf7I7ugy/z2m467l X-Received: by 2002:a17:902:24a2:: with SMTP id w31mr3598181pla.216.1546988145846; Tue, 08 Jan 2019 14:55:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546988145; cv=none; d=google.com; s=arc-20160816; b=III6RVkpMkqf7K2YtfZDvdNkXXHXfF9UMLpB8CQeG2YeQRIp/JJS+nQguCv6VjfVhI PKE3gU39/pXZ1qKk8jl6kCiWGAw0eIfpJkdJ6OYmVBj6Ct7ngzcfi04drPsNtZwl0Q+t IXh+EBj4KRAqTWN2XMI5ya1MsgBgm/lrP3zQyNQZ67mfXH4o+zLHA/eROy36xlgjgyPt r8GcL1FleKFlL5wdu/ayPaAk1fggL8bSq1aGC90Pfhshkh71/H7vAqOiIpLvDRDuI1b1 m1Uu234SfMAq2iFklJgIwXHMo5ojx8vd7QgycEPS4eP9TkAORs6sZt8F+7F96wddVj9w OCQA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=GTPRWlanFQfEpyiJDqi1SxvDYh4Pf0VcEum9gF01aaE=; b=u9pVZRnyx77ivWTgBw0jb8M3WwTIkegXkRwluknmE89BDufr8Jhvzj2MprEo0G4Kv6 bEDyJ1GbiGnWnOvd7LONXsxX3syIU4UWVUeeCFEc9x5nkeYN1srBlM4cipD9I9O8aKca PAE4T+2wcgN/lnu1Vxge6cYgun0yxU1R90nIryGh5/UWMc+IcelqrP9xyGIUQ5aCkF2R 1roqKq0TvPDR9Y61OYg3t+NBsVnS+us2UpfzNfDboKCqDPwAvDFvz+Exmm0SP+uMYLbT AWh/J3BkyaJOX+1lPnpgVkrVOY5bnRb/zPw1H06KYVfqxsNKVFmCm7LmUAaC6Mlb4sGo gGlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=bind6z0U; 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 l14si8529146pgi.147.2019.01.08.14.55.30; Tue, 08 Jan 2019 14:55:45 -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-dk.20150623.gappssmtp.com header.s=20150623 header.b=bind6z0U; 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 S1729415AbfAHVan (ORCPT + 99 others); Tue, 8 Jan 2019 16:30:43 -0500 Received: from mail-io1-f67.google.com ([209.85.166.67]:43700 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728913AbfAHVan (ORCPT ); Tue, 8 Jan 2019 16:30:43 -0500 Received: by mail-io1-f67.google.com with SMTP id b23so4337108ios.10 for ; Tue, 08 Jan 2019 13:30:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=GTPRWlanFQfEpyiJDqi1SxvDYh4Pf0VcEum9gF01aaE=; b=bind6z0U3eNgDyDvJGBeGb9gkfHDVJBScwaPME18fn7Z9zmQ2rdIG5ue+V2PLBKbKi RSFYKnTy0rkCi37HUmihGE3/QUwhJ5tGTesphZxS4FoYcAp0knhXxZ+DOir0M1j0sQHo zXcB6ZYSGO4M6+xyhl3oCjdNrLPdvJLIE2htNIW4lXmEYP02po2HEjZwGjjXfDmN/kx2 +mXL9NsITvFUf2B7TnnRspFO8wE4hjlXgG1XolQ8iJ9CUIIa298PytBAISuDjgpXh5yp ri65MNJV7whUzmEqy0HQNnfcRkFW2sr5lou+yoPM14bdTPon7kape1rb5eJiemkzuJHM jTDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=GTPRWlanFQfEpyiJDqi1SxvDYh4Pf0VcEum9gF01aaE=; b=Qv4p2qYcTmBrfjnXLHEjT3Sluuq74VZIUKSHhO+WbwOnDg2uzwW7PfSvLD+3xbQSAV ywAY0IG+JoaxmEbzb2n2HwV4AL8NWYpOKOi2IuNp6jZDG7rkGHd7XymuTMwNSiSDlcZy N97RFW5S5dLJNycZ0E0ngmiiViV6NDLOEEBb9BGGsZwhoIHGmxu2aMHfe4FeESQ0pedL JpOiYqjweegDLtcjpCsh/PFw/sGQsZ4jwrcP98E663BboWVe4FjEGmuzB7o3UJ/ga1sL I1CLvuPX9sUT8t+ppwpRRFbWgt4auTMplJnh8IRHHqIzDloyLCpdnkhwQ7keGkn71etU lrUg== X-Gm-Message-State: AJcUukcT4MoFCYPN02hC0Zfxx6CNdIaPlVKHRY6uDVjwiCdKStsQ0Wri pJdiFDAM1PHGCEE2rcLtWBhBjg== X-Received: by 2002:a6b:5b12:: with SMTP id v18mr2282292ioh.157.1546983042201; Tue, 08 Jan 2019 13:30:42 -0800 (PST) Received: from [192.168.1.56] ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id m7sm5133381itk.38.2019.01.08.13.30.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Jan 2019 13:30:41 -0800 (PST) Subject: Re: [PATCH] scsi: isci: initialize shost fully before calling scsi_add_host() To: Logan Gunthorpe , linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Intel SCU Linux support , Artur Paszkiewicz , "James E.J. Bottomley" , "Martin K. Petersen" , Christoph Hellwig , Jeff Moyer References: <20190108205043.3122-1-logang@deltatee.com> From: Jens Axboe Message-ID: <0d986fa7-b510-07d0-02bd-cf4da11fd84e@kernel.dk> Date: Tue, 8 Jan 2019 14:30:36 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20190108205043.3122-1-logang@deltatee.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/8/19 1:50 PM, Logan Gunthorpe wrote: > 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(). Nice work! Reviewed-by: Jens Axboe -- Jens Axboe