lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230819083941.164365-1-wangzhu9@huawei.com>
Date:   Sat, 19 Aug 2023 08:39:41 +0000
From:   Zhu Wang <wangzhu9@...wei.com>
To:     <kartilak@...co.com>, <sebaddel@...co.com>, <jejb@...ux.ibm.com>,
        <martin.petersen@...cle.com>, <nmusini@...co.com>,
        <bvanassche@....org>, <dan.carpenter@...aro.org>,
        <linux-scsi@...r.kernel.org>, <linux-kernel@...r.kernel.org>
CC:     <wangzhu9@...wei.com>
Subject: [PATCH -next] scsi: snic: fix double free in snic_tgt_create()

The commit 41320b18a0e0 ("scsi: snic: Fix possible memory leak if
device_add() fails") fix the memory leak caused by dev_set_name() when
device_add() failed. While it did not consider that 'tgt' has already been
released when put_device(&tgt->dev) is called. We removed kfree(tgt) in
the error path to avoid double free 'tgt'. And we moved
put_device(&tgt->dev) after the removed kfree(tgt) to avoid UAF
(Use-After-Free).

Fixes: 41320b18a0e0 ("scsi: snic: Fix possible memory leak if device_add() fails")
Signed-off-by: Zhu Wang <wangzhu9@...wei.com>
---
 drivers/scsi/snic/snic_disc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/scsi/snic/snic_disc.c b/drivers/scsi/snic/snic_disc.c
index e429ad23c396..4db3ba62fcd3 100644
--- a/drivers/scsi/snic/snic_disc.c
+++ b/drivers/scsi/snic/snic_disc.c
@@ -303,12 +303,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;
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ