android_kernel_xiaomi_sm8350/drivers/scsi/libsas
Duoming Zhou 117331a2a5 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:22:41 +02:00
..
Kconfig
Makefile
sas_ata.c scsi: libsas: Fix sas_ata_qc_issue() handling of NCQ NON DATA commands 2022-04-15 14:18:00 +02:00
sas_discover.c
sas_event.c
sas_expander.c scsi: libsas: Fix use-after-free bug in smp_execute_task_sg() 2022-10-26 13:22:41 +02:00
sas_host_smp.c
sas_init.c
sas_internal.h
sas_phy.c
sas_port.c
sas_scsi_host.c scsi: libsas: Add LUN number check in .slave_alloc callback 2021-07-25 14:35:13 +02:00
sas_task.c