summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhu Wang <wangzhu9@huawei.com>2023-08-19 08:39:41 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-08-30 16:18:21 +0200
commitd3d57cdbfda44b503807451c4c1b59a5865547b3 (patch)
treecaf99a3d8b4b010e81139d3099f7c957b9421038
parentef56cc8889be5e0d2568f72dcf228f964f8104a7 (diff)
downloadlinux-stable-d3d57cdbfda44b503807451c4c1b59a5865547b3.tar.gz
linux-stable-d3d57cdbfda44b503807451c4c1b59a5865547b3.tar.bz2
linux-stable-d3d57cdbfda44b503807451c4c1b59a5865547b3.zip
scsi: snic: Fix double free in snic_tgt_create()
commit 1bd3a76880b2bce017987cf53780b372cf59528e upstream. Commit 41320b18a0e0 ("scsi: snic: Fix possible memory leak if device_add() fails") fixed the memory leak caused by dev_set_name() when device_add() failed. However, it did not consider that 'tgt' has already been released when put_device(&tgt->dev) is called. Remove kfree(tgt) in the error path to avoid double free of 'tgt' and move put_device(&tgt->dev) after the removed kfree(tgt) to avoid a use-after-free. Fixes: 41320b18a0e0 ("scsi: snic: Fix possible memory leak if device_add() fails") Signed-off-by: Zhu Wang <wangzhu9@huawei.com> Link: https://lore.kernel.org/r/20230819083941.164365-1-wangzhu9@huawei.com Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/scsi/snic/snic_disc.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/drivers/scsi/snic/snic_disc.c b/drivers/scsi/snic/snic_disc.c
index c445853c623e..e362453e8d26 100644
--- a/drivers/scsi/snic/snic_disc.c
+++ b/drivers/scsi/snic/snic_disc.c
@@ -317,12 +317,11 @@ snic_tgt_create(struct snic *snic, struct snic_tgt_id *tgtid)
"Snic Tgt: device_add, with err = %d\n",
ret);
- put_device(&tgt->dev);
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);
+ put_device(&tgt->dev);
tgt = NULL;
return tgt;