From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D4E6C4332F for ; Wed, 9 Feb 2022 18:40:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240169AbiBISke (ORCPT ); Wed, 9 Feb 2022 13:40:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240158AbiBISkY (ORCPT ); Wed, 9 Feb 2022 13:40:24 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A9D0C0401E0; Wed, 9 Feb 2022 10:39:39 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3ADC8B82378; Wed, 9 Feb 2022 18:39:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D853BC340E7; Wed, 9 Feb 2022 18:39:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644431976; bh=6gEPhc6j7K2vr4dJkRBn5zlS3bMBRpwTLNrRjht+vJY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OYzZmI/z54AKkJnj96kXn3Sh4nA2ZHNjwbKKmUFVtEo8cUg0Jp2zZ1sM4ukfBx2Eb CXkGJMwAKNmq4lllbmF9HcusXuSlXm5ARJVqP6wOKzOxbgPjlj31rZsVVx/muXT33B dVqaDiNoimvsY61DZ++SvW98SIjRxNnb1ziNXvE0227k++6H1x0i2iYHbdJQElJqYc 2cCrYZFoObORUBHalJMcU/pnDofzjec8YTW/Qu2mAPGX6lwgGfLrt40OiSYxP/nUv5 foPs60f2wg4ucwjbpEy2c0EZOU7s/dBgnydUP447YXppR1Pf72dTtQuZ2raVkBOM3h HYkNb5Nuf3s2g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: John Garry , Damien Le Moal , Jack Wang , "Martin K . Petersen" , Sasha Levin , jinpu.wang@cloud.ionos.com, jejb@linux.ibm.com, linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 24/36] scsi: pm8001: Fix use-after-free for aborted SSP/STP sas_task Date: Wed, 9 Feb 2022 13:37:47 -0500 Message-Id: <20220209183759.47134-24-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220209183759.47134-1-sashal@kernel.org> References: <20220209183759.47134-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: John Garry [ Upstream commit df7abcaa1246e2537ab4016077b5443bb3c09378 ] Currently a use-after-free may occur if a sas_task is aborted by the upper layer before we handle the I/O completion in mpi_ssp_completion() or mpi_sata_completion(). In this case, the following are the two steps in handling those I/O completions: - Call complete() to inform the upper layer handler of completion of the I/O. - Release driver resources associated with the sas_task in pm8001_ccb_task_free() call. When complete() is called, the upper layer may free the sas_task. As such, we should not touch the associated sas_task afterwards, but we do so in the pm8001_ccb_task_free() call. Fix by swapping the complete() and pm8001_ccb_task_free() calls ordering. Link: https://lore.kernel.org/r/1643289172-165636-4-git-send-email-john.garry@huawei.com Reviewed-by: Damien Le Moal Acked-by: Jack Wang Signed-off-by: John Garry Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/pm8001/pm80xx_hwi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/pm8001/pm80xx_hwi.c b/drivers/scsi/pm8001/pm80xx_hwi.c index 733781018c0ba..d430cd83e3981 100644 --- a/drivers/scsi/pm8001/pm80xx_hwi.c +++ b/drivers/scsi/pm8001/pm80xx_hwi.c @@ -2184,9 +2184,9 @@ mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) pm8001_dbg(pm8001_ha, FAIL, "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n", t, status, ts->resp, ts->stat); + pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); if (t->slow_task) complete(&t->slow_task->completion); - pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); } else { spin_unlock_irqrestore(&t->task_state_lock, flags); pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); @@ -2801,9 +2801,9 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, pm8001_dbg(pm8001_ha, FAIL, "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n", t, status, ts->resp, ts->stat); + pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); if (t->slow_task) complete(&t->slow_task->completion); - pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); } else { spin_unlock_irqrestore(&t->task_state_lock, flags); spin_unlock_irqrestore(&circularQ->oq_lock, -- 2.34.1