Skip to content

Commit df7abca

Browse files
John Garrymartinkpetersen
authored andcommitted
scsi: pm8001: Fix use-after-free for aborted SSP/STP sas_task
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 <damien.lemoal@opensource.wdc.com> Acked-by: Jack Wang <jinpu.wang@ionos.com> Signed-off-by: John Garry <john.garry@huawei.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 61f162a commit df7abca

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/scsi/pm8001/pm80xx_hwi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,9 +2185,9 @@ mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
21852185
pm8001_dbg(pm8001_ha, FAIL,
21862186
"task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
21872187
t, status, ts->resp, ts->stat);
2188+
pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
21882189
if (t->slow_task)
21892190
complete(&t->slow_task->completion);
2190-
pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
21912191
} else {
21922192
spin_unlock_irqrestore(&t->task_state_lock, flags);
21932193
pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
@@ -2794,9 +2794,9 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha,
27942794
pm8001_dbg(pm8001_ha, FAIL,
27952795
"task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
27962796
t, status, ts->resp, ts->stat);
2797+
pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
27972798
if (t->slow_task)
27982799
complete(&t->slow_task->completion);
2799-
pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
28002800
} else {
28012801
spin_unlock_irqrestore(&t->task_state_lock, flags);
28022802
spin_unlock_irqrestore(&circularQ->oq_lock,

0 commit comments

Comments
 (0)