public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: elx: libefc: potential use after free in efc_nport_vport_del()
@ 2024-08-15 11:29 Dan Carpenter
  2024-08-19  6:57 ` Daniel Wagner
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dan Carpenter @ 2024-08-15 11:29 UTC (permalink / raw)
  To: James Smart
  Cc: James Smart, Ram Vegesna, James E.J. Bottomley,
	Martin K. Petersen, Daniel Wagner, linux-scsi, target-devel,
	linux-kernel, kernel-janitors

The kref_put() function will call nport->release if the refcount drops
to zero.  The nport->release release function is _efc_nport_free() which
frees "nport".  But then we dereference "nport" on the next line which
is a use after free.  Re-order these lines to avoid the use after free.

Fixes: fcd427303eb9 ("scsi: elx: libefc: SLI and FC PORT state machine interfaces")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
From static analysis.  Untested.  But it seems low risk.
---
 drivers/scsi/elx/libefc/efc_nport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/elx/libefc/efc_nport.c b/drivers/scsi/elx/libefc/efc_nport.c
index 2e83a667901f..1a7437f4328e 100644
--- a/drivers/scsi/elx/libefc/efc_nport.c
+++ b/drivers/scsi/elx/libefc/efc_nport.c
@@ -705,9 +705,9 @@ efc_nport_vport_del(struct efc *efc, struct efc_domain *domain,
 	spin_lock_irqsave(&efc->lock, flags);
 	list_for_each_entry(nport, &domain->nport_list, list_entry) {
 		if (nport->wwpn == wwpn && nport->wwnn == wwnn) {
-			kref_put(&nport->ref, nport->release);
 			/* Shutdown this NPORT */
 			efc_sm_post_event(&nport->sm, EFC_EVT_SHUTDOWN, NULL);
+			kref_put(&nport->ref, nport->release);
 			break;
 		}
 	}
-- 
2.43.0


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

* Re: [PATCH] scsi: elx: libefc: potential use after free in efc_nport_vport_del()
  2024-08-15 11:29 [PATCH] scsi: elx: libefc: potential use after free in efc_nport_vport_del() Dan Carpenter
@ 2024-08-19  6:57 ` Daniel Wagner
  2024-08-23  1:08 ` Martin K. Petersen
  2024-08-29  2:50 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Wagner @ 2024-08-19  6:57 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: James Smart, James Smart, Ram Vegesna, James E.J. Bottomley,
	Martin K. Petersen, linux-scsi, target-devel, linux-kernel,
	kernel-janitors

On Thu, Aug 15, 2024 at 02:29:05PM GMT, Dan Carpenter wrote:
> The kref_put() function will call nport->release if the refcount drops
> to zero.  The nport->release release function is _efc_nport_free() which
> frees "nport".  But then we dereference "nport" on the next line which
> is a use after free.  Re-order these lines to avoid the use after free.
> 
> Fixes: fcd427303eb9 ("scsi: elx: libefc: SLI and FC PORT state machine interfaces")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> From static analysis.  Untested.  But it seems low risk.

Look reasonable.

Reviewed-by: Daniel Wagner <dwagner@suse.de>

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

* Re: [PATCH] scsi: elx: libefc: potential use after free in efc_nport_vport_del()
  2024-08-15 11:29 [PATCH] scsi: elx: libefc: potential use after free in efc_nport_vport_del() Dan Carpenter
  2024-08-19  6:57 ` Daniel Wagner
@ 2024-08-23  1:08 ` Martin K. Petersen
  2024-08-29  2:50 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2024-08-23  1:08 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: James Smart, James Smart, Ram Vegesna, James E.J. Bottomley,
	Martin K. Petersen, Daniel Wagner, linux-scsi, target-devel,
	linux-kernel, kernel-janitors


Dan,

> The kref_put() function will call nport->release if the refcount drops
> to zero. The nport->release release function is _efc_nport_free()
> which frees "nport". But then we dereference "nport" on the next line
> which is a use after free. Re-order these lines to avoid the use after
> free.

Applied to 6.12/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH] scsi: elx: libefc: potential use after free in efc_nport_vport_del()
  2024-08-15 11:29 [PATCH] scsi: elx: libefc: potential use after free in efc_nport_vport_del() Dan Carpenter
  2024-08-19  6:57 ` Daniel Wagner
  2024-08-23  1:08 ` Martin K. Petersen
@ 2024-08-29  2:50 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2024-08-29  2:50 UTC (permalink / raw)
  To: James Smart, Dan Carpenter
  Cc: Martin K . Petersen, James Smart, Ram Vegesna,
	James E.J. Bottomley, Daniel Wagner, linux-scsi, target-devel,
	linux-kernel, kernel-janitors

On Thu, 15 Aug 2024 14:29:05 +0300, Dan Carpenter wrote:

> The kref_put() function will call nport->release if the refcount drops
> to zero.  The nport->release release function is _efc_nport_free() which
> frees "nport".  But then we dereference "nport" on the next line which
> is a use after free.  Re-order these lines to avoid the use after free.
> 
> 

Applied to 6.12/scsi-queue, thanks!

[1/1] scsi: elx: libefc: potential use after free in efc_nport_vport_del()
      https://git.kernel.org/mkp/scsi/c/2e4b02fad094

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2024-08-29  2:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-15 11:29 [PATCH] scsi: elx: libefc: potential use after free in efc_nport_vport_del() Dan Carpenter
2024-08-19  6:57 ` Daniel Wagner
2024-08-23  1:08 ` Martin K. Petersen
2024-08-29  2:50 ` 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