From patchwork Tue Mar 20 08:42:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10296669 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1DAE3602B3 for ; Tue, 20 Mar 2018 08:42:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D91D29545 for ; Tue, 20 Mar 2018 08:42:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0250A2956D; Tue, 20 Mar 2018 08:42:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7ECC029545 for ; Tue, 20 Mar 2018 08:42:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752019AbeCTImL (ORCPT ); Tue, 20 Mar 2018 04:42:11 -0400 Received: from verein.lst.de ([213.95.11.211]:36041 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751408AbeCTImK (ORCPT ); Tue, 20 Mar 2018 04:42:10 -0400 Received: by newverein.lst.de (Postfix, from userid 2407) id C1A93DE401; Tue, 20 Mar 2018 09:42:08 +0100 (CET) Date: Tue, 20 Mar 2018 09:42:08 +0100 From: Christoph Hellwig To: "Martin K. Petersen" Cc: Dan Carpenter , Adaptec OEM Raid Solutions , Christoph Hellwig , "James E.J. Bottomley" , linux-scsi@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH 1/2] scsi: dpt_i2o: use after free in adpt_release() Message-ID: <20180320084208.GA16215@lst.de> References: <20180319103303.GA8543@mwanda> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Mar 19, 2018 at 11:08:37PM -0400, Martin K. Petersen wrote: > > Dan, > > > The scsi_host_put() function frees "pHba" and then we dereference it on > > the next line when we do "scsi_host_put(pHba->host);". > > Applied to 4.17/scsi-queue, thank you. This fix is broken! adpt_i2o_delete_hba references pHba->host as well. Instead we need a local variable for the host. Fix below: --- From 701440055539c0f72a3179d85a44bd59d45a7d4b Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Tue, 20 Mar 2018 09:40:44 +0100 Subject: dpt_i2o: fix use after free in adpt_release for real Fixes: 7bec5bed ("scsi: dpt_i2o: use after free in adpt_release()") adpt_i2o_delete_hba still references the host. Signed-off-by: Christoph Hellwig --- drivers/scsi/dpt_i2o.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c index 0f30792d74c4..35d45903ed2e 100644 --- a/drivers/scsi/dpt_i2o.c +++ b/drivers/scsi/dpt_i2o.c @@ -304,10 +304,12 @@ static int adpt_detect(struct scsi_host_template* sht) static void adpt_release(adpt_hba *pHba) { - scsi_remove_host(pHba->host); + struct Scsi_Host *shost = pHba->host; + + scsi_remove_host(shost); // adpt_i2o_quiesce_hba(pHba); - scsi_host_put(pHba->host); adpt_i2o_delete_hba(pHba); + scsi_host_put(shost); }