]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
scsi: snic: Fix possible UAF in snic_tgt_create()
authorGaosheng Cui <cuigaosheng1@huawei.com>
Thu, 17 Nov 2022 03:51:00 +0000 (11:51 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 7 Jan 2023 11:07:23 +0000 (12:07 +0100)
[ Upstream commit e118df492320176af94deec000ae034cc92be754 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/scsi/snic/snic_disc.c

index b106596cc0cf5b8e92c92c955f0db6517a30cb93..69c5e26a9d5b381a5f216c1bfbdbb55a8d30522c 100644 (file)
@@ -317,6 +317,9 @@ snic_tgt_create(struct snic *snic, struct snic_tgt_id *tgtid)
                              ret);
 
                put_device(&snic->shost->shost_gendev);
+               spin_lock_irqsave(snic->shost->host_lock, flags);
+               list_del(&tgt->list);
+               spin_unlock_irqrestore(snic->shost->host_lock, flags);
                kfree(tgt);
                tgt = NULL;