Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3913244pxb; Mon, 21 Feb 2022 08:11:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4NFm7q3snaCE7lZ5TTbVxLJycCjed1Swl5uenX6qpx5IErMOHHO/Ai2+Pmzv0XUzIMIhX X-Received: by 2002:a17:90a:4a98:b0:1b9:459e:753a with SMTP id f24-20020a17090a4a9800b001b9459e753amr22272970pjh.232.1645459903219; Mon, 21 Feb 2022 08:11:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645459903; cv=none; d=google.com; s=arc-20160816; b=A/NfBHNjpAKLAk2tsIpDpW85MiUjmJjEvPC/jKDcS7g0aavtnNzmOFIm3PR5Ia7ET4 gXLFcmqvtfhaw9n9flv6iW8sb/NZ06NV0rjzyZZZrVX795lRUJzu+dcH2S54Fs2r4a/4 KYbHWLJXAnK98oHUPqcYfJNKySTVKF1j20SAPN0VHIEYJcfm+uDcoFZCQBAwgGAyq1KL jmDvaeAGnsUGanivMSZeTVZuqLOzjPNtEa/xycdyrU/0VtswTMy0CF14bJSJEs5bDU+G hRyjgoZRpqO7Tkof0Q1wJwcUTgFNaqdqi/qE/a9M10eaNIXQUvQs7O1qOtVETSiOUInU gnSA== 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=crAtvq+9q3L/1PerSEpMvLI/9HzhepaRgXGdpxfWCgc=; b=RTCpX5rUEbEzOC7cnFwIImrOgYQE7Obq8mEFBtTsM/i6ZyyfVuwoJYg4kK35R1vSl6 QMgOPDWFCYOVGhs8t4sZW0X7NYnw+58Qa/Rw3R4PFGcyS9e2Lds3CWYrHP3yonRJ3yAU HPIR+GDFnJqiRwLzNLWSycVxJ26VAgNpa+13ApZni4A+xXcoTTYj7ikVJpSSPqSs1Pb2 mr47u3q+YND8b6XcpAY2THYU/hpVT0Ce4KBlGO9yl6OLj78982d1sTIoYOrf3VuLWzne wpbSi+7umDf+b74WrZl11Xp8mKAQUT5eoM/cHuGjcOUMi9gXb5RX2M8i1n38kBWZlblY QvXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IUYqCKYm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p5si29438424pls.250.2022.02.21.08.11.26; Mon, 21 Feb 2022 08:11:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IUYqCKYm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354741AbiBUJ6s (ORCPT + 99 others); Mon, 21 Feb 2022 04:58:48 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:42352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352017AbiBUJq6 (ORCPT ); Mon, 21 Feb 2022 04:46:58 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FDE131207; Mon, 21 Feb 2022 01:18:56 -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 sin.source.kernel.org (Postfix) with ESMTPS id A801BCE0E90; Mon, 21 Feb 2022 09:18:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 871FCC340E9; Mon, 21 Feb 2022 09:18:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645435134; bh=cCeCFh09Il9xAvv0HNxIb0KqsWpXXevhDhL7xNZNzAY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IUYqCKYmnh+2BmfQG5UbAWPoiCBlvUJX810a+WcrZWlr72w2xnaMMRI3NidAAWdF2 WQHKhJIELgBlq0121iTHyMNtBHopRs7B96UNLWJOOXR+Z19CbbHXhKcZFEY0hT40lO WPSx1uq9Ac7IgOsge0tEWYac0ZKqqzVaU/zDCGp4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Damien Le Moal , Jack Wang , John Garry , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.16 057/227] scsi: pm8001: Fix use-after-free for aborted SSP/STP sas_task Date: Mon, 21 Feb 2022 09:47:56 +0100 Message-Id: <20220221084936.775956553@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084934.836145070@linuxfoundation.org> References: <20220221084934.836145070@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 885bc9e71ff64..ca4820d99dc70 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