android_kernel_xiaomi_sm8450/drivers/scsi/libsas
Duoming Zhou a9e5176ead scsi: libsas: Fix use-after-free bug in smp_execute_task_sg()
[ Upstream commit 46ba53c30666717cb06c2b3c5d896301cd00d0c0 ]

When executing SMP task failed, the smp_execute_task_sg() calls del_timer()
to delete "slow_task->timer". However, if the timer handler
sas_task_internal_timedout() is running, the del_timer() in
smp_execute_task_sg() will not stop it and a UAF will happen. The process
is shown below:

      (thread 1)               |        (thread 2)
smp_execute_task_sg()          | sas_task_internal_timedout()
 ...                           |
 del_timer()                   |
 ...                           |  ...
 sas_free_task(task)           |
  kfree(task->slow_task) //FREE|
                               |  task->slow_task->... //USE

Fix by calling del_timer_sync() in smp_execute_task_sg(), which makes sure
the timer handler have finished before the "task->slow_task" is
deallocated.

Link: https://lore.kernel.org/r/20220920144213.10536-1-duoming@zju.edu.cn
Fixes: 2908d778ab ("[SCSI] aic94xx: new driver")
Reviewed-by: Jason Yan <yanaijie@huawei.com>
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-10-26 13:25:37 +02:00
..
Kconfig ata: make SATA_PMP option selectable only if any SATA host driver is enabled 2020-03-26 10:28:17 -06:00
Makefile treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 167 2019-05-30 11:26:39 -07:00
sas_ata.c scsi: libsas: Fix sas_ata_qc_issue() handling of NCQ NON DATA commands 2022-04-08 14:39:52 +02:00
sas_discover.c SCSI misc on 20201013 2020-10-14 15:15:35 -07:00
sas_event.c scsi: libsas: Introduce a _gfp() variant of event notifiers 2021-03-25 09:04:11 +01:00
sas_expander.c scsi: libsas: Fix use-after-free bug in smp_execute_task_sg() 2022-10-26 13:25:37 +02:00
sas_host_smp.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 372 2019-06-05 17:37:10 +02:00
sas_init.c scsi: libsas: Introduce a _gfp() variant of event notifiers 2021-03-25 09:04:11 +01:00
sas_internal.h scsi: libsas: Introduce a _gfp() variant of event notifiers 2021-03-25 09:04:11 +01:00
sas_phy.c SCSI misc on 20190709 2019-07-11 15:14:01 -07:00
sas_port.c scsi: libsas: Use _safe() loop in sas_resume_port() 2021-06-03 09:00:50 +02:00
sas_scsi_host.c scsi: libsas: Add LUN number check in .slave_alloc callback 2021-07-25 14:36:16 +02:00
sas_task.c scsi: libsas: Tidy SAS address print format 2019-12-21 13:42:42 -05:00