Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp902074pxb; Fri, 28 Jan 2022 12:44:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJy8JZsOfOPzRgdI6AviUcZGjVItv4qT1ZLW44z0EFQ7dWYAPuFp4D2E1ukp/xrlxVaJeV09 X-Received: by 2002:a17:907:8a24:: with SMTP id sc36mr8189498ejc.318.1643402644727; Fri, 28 Jan 2022 12:44:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643402644; cv=none; d=google.com; s=arc-20160816; b=QuzTqoRSPo0A7y8/bib3aykCzOKKznRrdE+uYbI/yWSmKA7wzKhEJHfuZ+nEvTY7ND KdZEyDsgYXIZN+VUDIBh5d55clum2LEBG21LwIJDQ/gVm8+QxmBp4oI4mBox+KDxql+0 z/XCyEon0/aeXuCdsEmwMZupropl/HIu81E/l+AZSxxn0fQlQ2F0+3k0AlokCV5jRgW5 jmj8g9+ucVTADq2eBm1hEX5zRWg399QP3MeZIRWyJDgOhGXGiLrEmjVGzbvWfQskvz1O lMCEO96ZU4xsULQBYNl0FtDdKpM6GkFJvROFGhvEO7xSegKepGKa1Hl5/zZJPN1Dz0t0 GsvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature :wdcironportexception:ironport-sdr:ironport-sdr:dkim-signature; bh=HRArn2/RV10O+U2bkwaQ0pnVoPd6unHwYIrbShH+Z8Y=; b=q5NusHZ0pp17T/zPZTSZWgpjE8Kupwn54NlsmxiGSNzIc+ng0upBv5vfLmHEFr13l1 x/CyHeq5ot6Eq51jrJwO0PGkZ6ruilluW/N8GxTf3/bjpjiqe24M4ly4NWQvtmTUCNO0 SPuQqRGTErzirHuxTdhRdu8WcUOGNTGwbLYDgoA3lSf9layyabI/cYFFhbT2kKT10HST B/ZUKZNgSP/2+BSlFesmt+6nCmjZyKSY3JMMuSeF6Xjsj5BUh3h1YOLcu2uQMJ5Jx336 A/p6ggQRbUXH+8QZr1jZe9x+J8B2XkCb3OND85mregepmrVZ/We3iRMytrgbI4ZMhlo9 F0ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=S0MGmVmz; dkim=pass header.i=@opensource.wdc.com header.s=dkim header.b=I+8FNWGW; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=opensource.wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f14si3968665edd.197.2022.01.28.12.43.40; Fri, 28 Jan 2022 12:44:04 -0800 (PST) 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=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=S0MGmVmz; dkim=pass header.i=@opensource.wdc.com header.s=dkim header.b=I+8FNWGW; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=opensource.wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244948AbiA0XID (ORCPT + 99 others); Thu, 27 Jan 2022 18:08:03 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:27044 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236513AbiA0XIC (ORCPT ); Thu, 27 Jan 2022 18:08:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1643324882; x=1674860882; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=RIc1G0jfMqESjsX/4a2c2KpqW6LjEkfd3i3QcfNLq/g=; b=S0MGmVmzzX1yz2cLFCmngi5Hio9Zv3cVJbyG2d3kVfjXn6p5MlkpDkYH vZntUb8BONWndJaSYN1ucgCLiWy3ebxBfeeMUDfiBDjxJG7W0R/wnywQJ 47l3f5i/3Lm/ILd0CjXssLUvDInc6hK+mZ6oBz0RZUib6bFN7kxI8wRHW poqPFmbNf8SNpbO4ixa8/8ox2bX56qw7LhbhXI0Jj/rWIHFLXKclQxgek M3GRdZj5oYfzphWHjKlifyK4lI5RndkWCHODiMQa65axVuGB6w9AMs1WK RDe7ziVKOkywwpB46JkeD/PkdluDi6Rk5gCJur6Dh00VGS56+wXdOoEDo A==; X-IronPort-AV: E=Sophos;i="5.88,321,1635177600"; d="scan'208";a="190525324" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Jan 2022 07:08:01 +0800 IronPort-SDR: +XBjZvEBIa1A9pV2GM/XwazOS4ZBCBfZzas4C3ey2+TTVupWit3JgfFX3Joo34J78gZXRCeBFs JelndTl8nuSOyNzhHaonqoePGBdJGF1qHKvGqPD7qv/FDmpf8xm3FnioQ/MuPTBwOLOtN+fZpH 3fv7pWlpkicJB3589fQMnxDBA5ppza03kr+ooGp1z4zt95NyaAsanZnTHhiRj3fuF8d9AUDzoL N+YzrnsTsEsfCVNdpHgnWnckwgptVUy2ZFgB5TMFcOefHQOA7hfEGUeZLLoHxE0G7aYn4wZJM7 EFnjhgeDtaLsZSfWIsVmcUXO Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2022 14:40:04 -0800 IronPort-SDR: rcGeXFVH4e8oCA4qfbZq3Nx1u2BXlGXVFFR7AMgt2TJYztVIYe+obyEhY1bnFnUIFIorKJbKgG 6XNl12e1q7F6sD+Mvs0S4+VFJRTUrqG965EZ/iSVGYrcoogZdgpT/nlRuC7mswcGxUAd+NmNGN y4z7Xi9gZFbx3pfmniv/3zn41fQ/84wfiMG5N//0b5x91lr/FSQDA0DoLY5ValASAMPEmlXL1s 6yvNJeybOXLBbC477gFgswYXTzdIbo0FYo93OertlvWVapMHXne//M+CwglXSZMa0+I/Qt3xDa Z8s= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2022 15:08:01 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4JlGTY0nQ9z1SVp4 for ; Thu, 27 Jan 2022 15:08:01 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:content-type :in-reply-to:organization:from:references:to:content-language :subject:user-agent:mime-version:date:message-id; s=dkim; t= 1643324880; x=1645916881; bh=RIc1G0jfMqESjsX/4a2c2KpqW6LjEkfd3i3 QcfNLq/g=; b=I+8FNWGWJ/4MlV/z/th2/1EineZqntzCdjD1+SdzBRZmleDIasU bDQHm2D3NYjKWvvl7CP3MGFkpk50BSKIdgdpnDDD2k5ag+1jVp/eA7j0i8a6w59z ooUI+8JdH3Df02k9FxqaRt/DZp4KFOrK03D0VTm+psD1UCCZ5jmlNDll9dKF6Bn+ rpVGWQ3hj3eHNz/juwNltJAuRiZFSHsXqL/lo/5+cVViCYFI6ttU2yc/TNrvF1He 0CaT/njGqMqyEl7WmRJXWbOact3UD1oxAc2gtOSca0ice30aYLMyt6ak+SAqWbd8 rbs6ZBWWS5OFBv5v6vtPbF2uLe8WfREwEuw== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id wW8hFouotPJ8 for ; Thu, 27 Jan 2022 15:08:00 -0800 (PST) Received: from [10.225.163.58] (unknown [10.225.163.58]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4JlGTW0WqXz1RvlN; Thu, 27 Jan 2022 15:07:58 -0800 (PST) Message-ID: <6e698ebf-e592-dd44-95a2-8d86416277f7@opensource.wdc.com> Date: Fri, 28 Jan 2022 08:07:57 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH 2/3] scsi: pm8001: Fix use-after-free for aborted TMF sas_task Content-Language: en-US To: John Garry , jinpu.wang@cloud.ionos.com, jejb@linux.ibm.com, martin.petersen@oracle.com, Ajish.Koshy@microchip.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Viswas.G@microchip.com, chenxiang66@hisilicon.com References: <1643289172-165636-1-git-send-email-john.garry@huawei.com> <1643289172-165636-3-git-send-email-john.garry@huawei.com> From: Damien Le Moal Organization: Western Digital Research In-Reply-To: <1643289172-165636-3-git-send-email-john.garry@huawei.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/27/22 22:12, John Garry wrote: > 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 IO completion occurs later, the IO completion still thinks > that the sas_task is available. Fix this by clearing the ccb->task if > the TMF times out - the IO completion handler does nothing if this pointer > is cleared. > > Signed-off-by: John Garry > --- > > Note: For hisi_sas driver we already do something similar. However there > we also flush the completion queue interrupt to ensure that there is no > race in clearing the task pointer. Please advise if/how something similar > can be done here. > > 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 160ee8b228c9..32edda3e55c6 100644 > --- a/drivers/scsi/pm8001/pm8001_sas.c > +++ b/drivers/scsi/pm8001/pm8001_sas.c > @@ -769,8 +769,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; > } > Reviewed-by: Damien Le Moal -- Damien Le Moal Western Digital Research