linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: snic: Fix possible UAF in snic_tgt_create
@ 2022-11-17  3:51 Gaosheng Cui
  2022-11-26  0:31 ` Martin K. Petersen
  2022-12-01  3:45 ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: Gaosheng Cui @ 2022-11-17  3:51 UTC (permalink / raw)
  To: kartilak, sebaddel, jejb, martin.petersen, hare, JBottomley,
	nmusini, cuigaosheng1
  Cc: linux-scsi

Smatch report 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.

Fix by removeing it from snic->disc.tgt_list before free().

Fixes: c8806b6c9e82 ("snic: driver for Cisco SCSI HBA")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
---
 drivers/scsi/snic/snic_disc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/scsi/snic/snic_disc.c b/drivers/scsi/snic/snic_disc.c
index 9b2b5f8c23b9..8fbf3c1b1311 100644
--- a/drivers/scsi/snic/snic_disc.c
+++ b/drivers/scsi/snic/snic_disc.c
@@ -304,6 +304,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;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: snic: Fix possible UAF in snic_tgt_create
  2022-11-17  3:51 [PATCH] scsi: snic: Fix possible UAF in snic_tgt_create Gaosheng Cui
@ 2022-11-26  0:31 ` Martin K. Petersen
  2022-12-01  3:45 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2022-11-26  0:31 UTC (permalink / raw)
  To: Gaosheng Cui
  Cc: kartilak, sebaddel, jejb, martin.petersen, hare, JBottomley,
	nmusini, linux-scsi


Gaosheng,

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

Applied to 6.2/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: snic: Fix possible UAF in snic_tgt_create
  2022-11-17  3:51 [PATCH] scsi: snic: Fix possible UAF in snic_tgt_create Gaosheng Cui
  2022-11-26  0:31 ` Martin K. Petersen
@ 2022-12-01  3:45 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2022-12-01  3:45 UTC (permalink / raw)
  To: jejb, nmusini, sebaddel, Gaosheng Cui, JBottomley, kartilak, hare
  Cc: Martin K . Petersen, linux-scsi

On Thu, 17 Nov 2022 11:51:00 +0800, Gaosheng Cui wrote:

> Smatch report 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.
> 
> [...]

Applied to 6.2/scsi-queue, thanks!

[1/1] scsi: snic: Fix possible UAF in snic_tgt_create
      https://git.kernel.org/mkp/scsi/c/e118df492320

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-01  3:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-17  3:51 [PATCH] scsi: snic: Fix possible UAF in snic_tgt_create Gaosheng Cui
2022-11-26  0:31 ` Martin K. Petersen
2022-12-01  3:45 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).