From: Damien Le Moal <damien.lemoal@opensource.wdc.com>
To: John Garry <john.garry@huawei.com>,
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
Subject: Re: [PATCH 3/3] scsi: pm8001: Fix use-after-free for aborted SSP/STP sas_task
Date: Fri, 28 Jan 2022 08:08:46 +0900 [thread overview]
Message-ID: <ab547eb4-d97d-45e0-207a-8b660c6e96bd@opensource.wdc.com> (raw)
In-Reply-To: <1643289172-165636-4-git-send-email-john.garry@huawei.com>
On 1/27/22 22:12, John Garry wrote:
> Currently a use-after-free may occur if a sas_task is aborted by the upper
> layer before we handle the IO completion in mpi_ssp_completion() or
> mpi_sata_completion().
>
> In this case, the following are the two steps in handling those IO
> completions:
> - call complete() to inform the upper layer handler of completion of
> the IO
> - 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.
>
> Signed-off-by: John Garry <john.garry@huawei.com>
> ---
> 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 ce38a2298e75..1134e86ac928 100644
> --- a/drivers/scsi/pm8001/pm80xx_hwi.c
> +++ b/drivers/scsi/pm8001/pm80xx_hwi.c
> @@ -2185,9 +2185,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);
> @@ -2794,9 +2794,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,
Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2022-01-27 23:09 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-27 13:12 [PATCH 0/3] scsi: pm8001: Documentation and use-after-free fixes John Garry
2022-01-27 13:12 ` [PATCH 1/3] scsi: pm8001: Fix warning for undescribed param in process_one_iomb() John Garry
2022-01-27 23:06 ` Damien Le Moal
2022-01-28 6:17 ` Jinpu Wang
2022-01-27 13:12 ` [PATCH 2/3] scsi: pm8001: Fix use-after-free for aborted TMF sas_task John Garry
2022-01-27 23:07 ` Damien Le Moal
2022-01-28 6:18 ` Jinpu Wang
2022-01-27 13:12 ` [PATCH 3/3] scsi: pm8001: Fix use-after-free for aborted SSP/STP sas_task John Garry
2022-01-27 23:08 ` Damien Le Moal [this message]
2022-01-28 6:18 ` Jinpu Wang
2022-01-31 21:40 ` [PATCH 0/3] scsi: pm8001: Documentation and use-after-free fixes Martin K. Petersen
2022-02-01 2:03 ` Martin K. Petersen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ab547eb4-d97d-45e0-207a-8b660c6e96bd@opensource.wdc.com \
--to=damien.lemoal@opensource.wdc.com \
--cc=Ajish.Koshy@microchip.com \
--cc=Viswas.G@microchip.com \
--cc=chenxiang66@hisilicon.com \
--cc=jejb@linux.ibm.com \
--cc=jinpu.wang@cloud.ionos.com \
--cc=john.garry@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®