Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: snic: Fix possible UAF in snic_tgt_create()

Smatch reports a warning as follows:

drivers/scsi/snic/snic_disc.c:307 snic_tgt_create() warn:
'&tgt->list' not removed from list

If device_add() fails in snic_tgt_create(), tgt will be freed, but
tgt->list will not be removed from snic->disc.tgt_list, then list traversal
may cause UAF.

Remove from snic->disc.tgt_list before free().

Fixes: c8806b6c9e82 ("snic: driver for Cisco SCSI HBA")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
Link: https://lore.kernel.org/r/20221117035100.2944812-1-cuigaosheng1@huawei.com
Acked-by: Narsimhulu Musini <nmusini@cisco.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Gaosheng Cui and committed by
Martin K. Petersen
e118df49 95da5e58

+3
+3
drivers/scsi/snic/snic_disc.c
··· 304 304 ret); 305 305 306 306 put_device(&snic->shost->shost_gendev); 307 + spin_lock_irqsave(snic->shost->host_lock, flags); 308 + list_del(&tgt->list); 309 + spin_unlock_irqrestore(snic->shost->host_lock, flags); 307 310 kfree(tgt); 308 311 tgt = NULL; 309 312