Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3066916imu; Mon, 19 Nov 2018 10:07:32 -0800 (PST) X-Google-Smtp-Source: AJdET5cfhKRyGUCpabiNDwllMEGUpMdypQC/8aqCYHmzV8/BY5g92QyBmGAHOWAd83P6iPzISnSH X-Received: by 2002:a62:7f94:: with SMTP id a142mr24129597pfd.96.1542650852768; Mon, 19 Nov 2018 10:07:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542650852; cv=none; d=google.com; s=arc-20160816; b=fjyAXtlCTtnvBNk6ncD6xghCu0yU84huE/GSjMTxoq7YgUBwhYwzr6FUosUNR0QnBl D0CDtHMXWurjU7z9cdnlBy78uID9iT+vtCqUh88TENnuxz+4IKvi9x+FjW39Ri1PpPcu sajNoT+5DVXgUnwfRilR/2IuLkVF79MwNYnoNFV1Tz09kftRpDMaPTHjYzu/CMWFMRbe PeB8RWy+oBSDIIB8fHh/KDw+Qdqv1NrJOKMeHFmYV5hNKq8uBSRx8K7ADraUdl2wmNDM Q3dxUPhjDu9yj1bBcR5XZ4k6ReZzgNHw2FcK4SCsoo1MMrKZbV1ENO7GuL4irmJkYtu3 Gz4A== 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=0LcjW5LZvixyNs7zeb9QELmCbJRHb2wMHHDHuirRYgM=; b=AiGp8lQ7a+crDsHBHJ4BEGFsW5L1jGG7c5VCC1TblvlDVlStau9rPthToA8vJrc/iw 71GNSUqYMmwfvwH6k9jLofuHxWSjfjYHxDdsgZF4/XoiixeutZcxW0o2FAxDDai+ltnj j2oFFH2TN/9SH0naDby9QE/m1rtEpXiJ8bBsN9bVTqNcpmMINt2YKVSO1jXbz6jzcqOB DVHpIbr76K+yraPgW4nyjWmTMa4phyXRqHgutV4CwK/DeKQbCIAM6oRZEI1LuZ6aUZQl BH+WjGXAczr0QZF1ZxtynoZdF4XiQjkU0TCbj+C5MOBDxvh4jK8pxETKZjneUVDhqXL7 PZOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KwjhgNKa; 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 b5si3681752ple.387.2018.11.19.10.07.18; Mon, 19 Nov 2018 10:07:32 -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=KwjhgNKa; 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 S1730851AbeKTC4s (ORCPT + 99 others); Mon, 19 Nov 2018 21:56:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:55120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730817AbeKTC4s (ORCPT ); Mon, 19 Nov 2018 21:56:48 -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 300A420831; Mon, 19 Nov 2018 16:32:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542645160; bh=L+3MMyd9MjHL7IkmilZQd4LaoLQ63dlf9tSIGQ2DRPw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KwjhgNKaxKpbbaN6tS6S+nJzcRlHGbDMucRUu4a5YOPAXhsK5KouqDvOl1Z1ywy+B fjwxISygBBapYLLnanALUrILboT+4mkpR1/QthXWk3n1dvOciLLkXC0HlhgWHHh+EY vhrr2mkU0HV/7FRnCDmFpccp/z43UMR+sGS+PzqA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Giridhar Malavali , "Ewan D. Milne" , Himanshu Madhani , "Martin K. Petersen" Subject: [PATCH 4.19 058/205] scsi: qla2xxx: Fix for double free of SRB structure Date: Mon, 19 Nov 2018 17:26:05 +0100 Message-Id: <20181119162627.463264521@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162616.586062722@linuxfoundation.org> References: <20181119162616.586062722@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Giridhar Malavali commit bcc71cc3cde1468958a3ea859276d8d1a1a68265 upstream. This patch fixes issue during switch command query where driver was freeing SRB resources multiple times Following stack trace will be seen [ 853.436234] BUG: unable to handle kernel NULL pointer dereference at 0000000000000001 [ 853.436348] IP: [] kmem_cache_alloc+0x74/0x1e0 [ 853.436476] PGD 0 [ 853.436601] Oops: 0000 [#1] SMP [ 853.454700] [] ? mod_timer+0x14a/0x220 [ 853.455543] [] mempool_alloc_slab+0x15/0x20 [ 853.456395] [] mempool_alloc+0x69/0x170 [ 853.457257] [] ? internal_add_timer+0x32/0x70 [ 853.458136] [] qla2xxx_queuecommand+0x29b/0x3f0 [qla2xxx] [ 853.459024] [] scsi_dispatch_cmd+0xaa/0x230 [ 853.459923] [] scsi_request_fn+0x4df/0x680 [ 853.460829] [] ? __switch_to+0xd7/0x510 [ 853.461747] [] __blk_run_queue+0x33/0x40 [ 853.462670] [] blk_delay_work+0x25/0x40 [ 853.463603] [] process_one_work+0x17a/0x440 [ 853.464546] [] worker_thread+0x126/0x3c0 [ 853.465501] [] ? manage_workers.isra.24+0x2a0/0x2a0 [ 853.466447] [] kthread+0xcf/0xe0 [ 853.467379] [] ? insert_kthread_work+0x40/0x40 [ 853.470172] Code: db e2 7e 49 8b 50 08 4d 8b 20 49 8b 40 10 4d 85 e4 0f 84 20 01 00 00 48 85 c0 0f 84 17 01 00 00 49 63 46 20 48 8d 4a 01 4d 8b 06 <49> 8b 1c 04 4c 89 e0 65 49 0f c7 08 0f 94 c0 84 c0 74 ba 49 63 [ 853.472072] RIP [] kmem_cache_alloc+0x74/0x1e0 [ 853.472971] RSP Fixes: 726b85487067 ("qla2xxx: Add framework for async fabric discovery") Cc: Signed-off-by: Giridhar Malavali Reviewed-by: Ewan D. Milne Signed-off-by: Himanshu Madhani Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/qla2xxx/qla_gs.c | 3 +++ drivers/scsi/qla2xxx/qla_init.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) --- a/drivers/scsi/qla2xxx/qla_gs.c +++ b/drivers/scsi/qla2xxx/qla_gs.c @@ -3261,6 +3261,9 @@ static void qla24xx_async_gpsc_sp_done(v "Async done-%s res %x, WWPN %8phC \n", sp->name, res, fcport->port_name); + if (res == QLA_FUNCTION_TIMEOUT) + return; + if (res == (DID_ERROR << 16)) { /* entry status error */ goto done; --- a/drivers/scsi/qla2xxx/qla_init.c +++ b/drivers/scsi/qla2xxx/qla_init.c @@ -52,12 +52,14 @@ qla2x00_sp_timeout(struct timer_list *t) struct srb_iocb *iocb; struct req_que *req; unsigned long flags; + struct qla_hw_data *ha = sp->vha->hw; - spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags); + WARN_ON(irqs_disabled()); + spin_lock_irqsave(&ha->hardware_lock, flags); req = sp->qpair->req; req->outstanding_cmds[sp->handle] = NULL; iocb = &sp->u.iocb_cmd; - spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags); + spin_unlock_irqrestore(&ha->hardware_lock, flags); iocb->timeout(sp); } @@ -972,6 +974,15 @@ void qla24xx_async_gpdb_sp_done(void *s, fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); + if (res == QLA_FUNCTION_TIMEOUT) + return; + + if (res == QLA_FUNCTION_TIMEOUT) { + dma_pool_free(sp->vha->hw->s_dma_pool, sp->u.iocb_cmd.u.mbx.in, + sp->u.iocb_cmd.u.mbx.in_dma); + return; + } + memset(&ea, 0, sizeof(ea)); ea.event = FCME_GPDB_DONE; ea.fcport = fcport;