Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: sg: Fix a use after free on error in sg_add_sfp()
@ 2021-03-12  7:43 Dan Carpenter
  0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2021-03-12  7:43 UTC (permalink / raw)
  To: Doug Gilbert
  Cc: James E.J. Bottomley, Martin K. Petersen, Hannes Reinecke,
	linux-scsi, kernel-janitors

The SG_LOG() error message dereferences "sfp" so move the kfree down a
couple lines.

Fixes: af1fc95db445 ("scsi: sg: Replace rq array with xarray")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/scsi/sg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 2d4bbc1a1727..79f05afa4407 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -3799,10 +3799,10 @@ sg_add_sfp(struct sg_device *sdp)
 	if (rbuf_len > 0) {
 		srp = sg_build_reserve(sfp, rbuf_len);
 		if (IS_ERR(srp)) {
-			kfree(sfp);
 			err = PTR_ERR(srp);
 			SG_LOG(1, sfp, "%s: build reserve err=%ld\n", __func__,
 			       -err);
+			kfree(sfp);
 			return ERR_PTR(err);
 		}
 		if (srp->sgat_h.buflen < rbuf_len) {
-- 
2.30.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-12  7:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-12  7:43 [PATCH] scsi: sg: Fix a use after free on error in sg_add_sfp() Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox