Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp241871pxx; Wed, 28 Oct 2020 03:53:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1Mx8+11/LQzMGld3GKt7qbw59kmvU5vg00PT7fiM/Afwh3lGidogGNjSvPyLPznX0Ee9d X-Received: by 2002:a17:906:1cd6:: with SMTP id i22mr3917388ejh.16.1603882404250; Wed, 28 Oct 2020 03:53:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603882404; cv=none; d=google.com; s=arc-20160816; b=EUqGs5mgOwHWpdUcsbYDj4ThX352l7wz5OXtjB0oOG1Y7aHfeBsPYXOayEf0Enp9m+ 8KQt+5tIHjNFAHuwateozwBa6Zy+NgBDWoCG5pFyR3vv4ypGQjhbhyp1Ko1rleMmbdD0 qnDvCilCUexrP2K6Q+K3YjoiV2IQMkBBgWRUaA0dzwDHdysS522ULe1KhG8FmGyvU3AO iERkXqJShw4CRz5wpS2kL5mn5m+l3ZtZ1aA6QJQkx9y+0u2LijN+A+SXS7FY1Fki/siK qFcR1sY+nybSNQI8c8bp1K4ykUOXvUhlISERknBpm8HikGl9drsElEsWmNwMMrpO6K0e NYog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ji9uR4Wp+W0e3QsjuFe1HSzs0yOyVtJUy3WwtJs6kTQ=; b=jDAB44kTkpSV9vtDjW5V8m2cLUmz5EgTBMDv0ZW6/DRQ7jf/ItddI1Ca5k7lWWgPov O7pZnulqnvG9ndLCVFv2zDMObLdCx7Dg4OeRTGiMZQEScGbZNXA5+cyHC761cFLomkO9 yT0hx7kfHgOTnvAFqEupxDfi5wRGnHKBxAOJiuKqPNyHOyfqjnTMVVznS1/FHbQGH6Ha andlZqzLljOlkq6IG/7NWUQSZYA4zA7Eq8cRifKKQ0hZvFb3cs/ZlWWZDzMrBHDTNutW uAm8kDxWkYbqejgyL5halIrLclmXCLf6krr6jHbASgBe+qBYBrs1NKWkZELh+I2MoNwg sf3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xvEPKyhS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i19si2816688ejh.153.2020.10.28.03.53.02; Wed, 28 Oct 2020 03:53:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xvEPKyhS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1781300AbgJ0OzE (ORCPT + 99 others); Tue, 27 Oct 2020 10:55:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:47372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1764851AbgJ0Or3 (ORCPT ); Tue, 27 Oct 2020 10:47:29 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 81CDD21556; Tue, 27 Oct 2020 14:47:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810049; bh=XNBNPHCWavZrEu5SlajFZldWJA/rSGH/UWI9X1BQniU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xvEPKyhSPDVb9pw9TVI+lfOo8ok3X7e2gIck02ypGl8Wh2cO8xeJEU59Y+xajBxyK A4Bob5vsrEt+b2O45drdBbR4ctlbBYpdj9lZZgyVMxXggQnjMeF/+jb3uHYNlOXneV cHi0XeqIvE/amP9nA/Q7J9R1hR230DqFhZ8y3kDY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nilesh Javali , Manish Rangankar , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.4 384/408] scsi: qedi: Fix list_del corruption while removing active I/O Date: Tue, 27 Oct 2020 14:55:22 +0100 Message-Id: <20201027135512.808451797@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nilesh Javali [ Upstream commit 28b35d17f9f8573d4646dd8df08917a4076a6b63 ] While aborting the I/O, the firmware cleanup task timed out and driver deleted the I/O from active command list. Some time later the firmware sent the cleanup task response and driver again deleted the I/O from active command list causing firmware to send completion for non-existent I/O and list_del corruption of active command list. Add fix to check if I/O is present before deleting it from the active command list to ensure firmware sends valid I/O completion and protect against list_del corruption. Link: https://lore.kernel.org/r/20200908095657.26821-4-mrangankar@marvell.com Signed-off-by: Nilesh Javali Signed-off-by: Manish Rangankar Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/qedi/qedi_fw.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/qedi/qedi_fw.c b/drivers/scsi/qedi/qedi_fw.c index 32586800620bd..90aa64604ad78 100644 --- a/drivers/scsi/qedi/qedi_fw.c +++ b/drivers/scsi/qedi/qedi_fw.c @@ -825,8 +825,11 @@ static void qedi_process_cmd_cleanup_resp(struct qedi_ctx *qedi, qedi_clear_task_idx(qedi_conn->qedi, rtid); spin_lock(&qedi_conn->list_lock); - list_del_init(&dbg_cmd->io_cmd); - qedi_conn->active_cmd_count--; + if (likely(dbg_cmd->io_cmd_in_list)) { + dbg_cmd->io_cmd_in_list = false; + list_del_init(&dbg_cmd->io_cmd); + qedi_conn->active_cmd_count--; + } spin_unlock(&qedi_conn->list_lock); qedi_cmd->state = CLEANUP_RECV; wake_up_interruptible(&qedi_conn->wait_queue); @@ -1244,6 +1247,7 @@ int qedi_cleanup_all_io(struct qedi_ctx *qedi, struct qedi_conn *qedi_conn, qedi_conn->cmd_cleanup_req++; qedi_iscsi_cleanup_task(ctask, true); + cmd->io_cmd_in_list = false; list_del_init(&cmd->io_cmd); qedi_conn->active_cmd_count--; QEDI_WARN(&qedi->dbg_ctx, @@ -1455,8 +1459,11 @@ static void qedi_tmf_work(struct work_struct *work) spin_unlock_bh(&qedi_conn->tmf_work_lock); spin_lock(&qedi_conn->list_lock); - list_del_init(&cmd->io_cmd); - qedi_conn->active_cmd_count--; + if (likely(cmd->io_cmd_in_list)) { + cmd->io_cmd_in_list = false; + list_del_init(&cmd->io_cmd); + qedi_conn->active_cmd_count--; + } spin_unlock(&qedi_conn->list_lock); clear_bit(QEDI_CONN_FW_CLEANUP, &qedi_conn->flags); -- 2.25.1