Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4423237pxb; Mon, 21 Feb 2022 21:08:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJwFPns6+P3thaUnkty6hgN63xLwCY1gO8+YnatKFXkzltRgZnOSB1ztT33ghGKYOLhD30dt X-Received: by 2002:a17:902:d2ca:b0:14f:cf98:54f6 with SMTP id n10-20020a170902d2ca00b0014fcf9854f6mr4213493plc.34.1645506523636; Mon, 21 Feb 2022 21:08:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645506523; cv=none; d=google.com; s=arc-20160816; b=fFC/OFSqatWAaQSoGGg93dc5fGNJxQQI9WEiZFCR0IA6bP0cg0byqJe1hfO625jkoR KTy9ZTMJCpRoV38MvmTcrO4cUBnraIZvdUlUdmKGPtXQi8afJ5QqjpVnss7MXE4kq6CM u0zVoOnaCG6n9mlAOLnP6Enh+qUC8KdSwm4QqZXvwqLomsZhkYbT35Slc8DeAeNdr4Vr o85JrSDURv2v19dGHMKZ4DOzQ5r6nssUjkgzDg1VhNdjWNKMlLMRzPFeDnBTCkBX9LXI HXG6uUeDFdCNMkNdlhMb3JJLE/yg/NYdvm2iQZDWQACLYfY+Bmggu4PVKE1MeTCtlhyE 9uNg== 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=qq5jT/f7kP69KnPwk2qShdwgmv28M89Mfh3uRit2MDY=; b=XWydxUyrP9dloNSYHbLxvxuOg05oNYtDI9gpZVyoRm1ZhvEPYl8vmlWwNUA3Vv0PQH 8cGHJ1vypA5cPpptazkdAnZalj+LF8Q2LEdpQtBv4f3R8pnszoAW42Y05NGmAAaV1ef5 /dGq8/njnBFu1bU4WZXvcgIGhq+nw0iwRiFH5yom8XHEvNWUro0nCuJfX2h14QNJploc JreA6Qfepk38wAuklb1TMj7q4iQWA3QS5DmcltqbiU6x10/CtI0MxM40GStBQihYsotT ojfFPNjMQKiBjfF3WF1fwEFOmkXRsMfH5Uc94F/MDcUzlIumAUFDQhENCYtLxIM7ktb8 3Biw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SlQcX0KJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s7si29756299plq.462.2022.02.21.21.08.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 21:08:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SlQcX0KJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E0A6E652D2; Mon, 21 Feb 2022 20:41:48 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349790AbiBUJ3P (ORCPT + 99 others); Mon, 21 Feb 2022 04:29:15 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:35818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349774AbiBUJVp (ORCPT ); Mon, 21 Feb 2022 04:21:45 -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 480DA32060; Mon, 21 Feb 2022 01:09:01 -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 836E0CE0E95; Mon, 21 Feb 2022 09:08:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D419C340EB; Mon, 21 Feb 2022 09:08:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645434538; bh=a5z1qJjCuNm4itE6vzeRJiyvc82uzHYi8mzCBjw+F64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SlQcX0KJ1jK8Z/1pILe3nIJAufO3aVWXVKpeTPhHs84zC6HegJPzQtUS5zuFur0sW 4rnVpkmDvN57WI3wX4TzpmIsoU+k6MqoYI7NqQIXenoNBHQ5ZboNZQ0ELqhCxshQRb smxsbk9R6tfMls0XkhbNYSIzKQMoxFQaT1N0Zrbw= 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.15 041/196] scsi: pm8001: Fix use-after-free for aborted TMF sas_task Date: Mon, 21 Feb 2022 09:47:53 +0100 Message-Id: <20220221084932.310458255@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084930.872957717@linuxfoundation.org> References: <20220221084930.872957717@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 61f162aa4381845acbdc7f2be4dfb694d027c018 ] Currently a use-after-free may occur if a TMF sas_task is aborted before we handle the IO completion in mpi_ssp_completion(). The abort occurs due to timeout. When the timeout occurs, the SAS_TASK_STATE_ABORTED flag is set and the sas_task is freed in pm8001_exec_internal_tmf_task(). However, if the I/O completion occurs later, the I/O completion still thinks that the sas_task is available. Fix this by clearing the ccb->task if the TMF times out - the I/O completion handler does nothing if this pointer is cleared. Link: https://lore.kernel.org/r/1643289172-165636-3-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/pm8001_sas.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/scsi/pm8001/pm8001_sas.c b/drivers/scsi/pm8001/pm8001_sas.c index 32e60f0c3b148..491cecbbe1aa7 100644 --- a/drivers/scsi/pm8001/pm8001_sas.c +++ b/drivers/scsi/pm8001/pm8001_sas.c @@ -753,8 +753,13 @@ static int pm8001_exec_internal_tmf_task(struct domain_device *dev, res = -TMF_RESP_FUNC_FAILED; /* Even TMF timed out, return direct. */ if (task->task_state_flags & SAS_TASK_STATE_ABORTED) { + struct pm8001_ccb_info *ccb = task->lldd_task; + pm8001_dbg(pm8001_ha, FAIL, "TMF task[%x]timeout.\n", tmf->tmf); + + if (ccb) + ccb->task = NULL; goto ex_err; } -- 2.34.1