Skip to contentSkip to conversation

scsi: sg: Fix a use after free on error in sg_add_sfp()

PATCH New Dan Carpenter 1 participant 1 message Mar 12, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: sg: Fix a use after free on error in sg_add_sfp()

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

Fixes af1fc95db445 ("scsi: sg: Replace rq array with xarray")
---
 drivers/scsi/sg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/sg.c +1 -1
index 2d4bbc1a1727..79f05afa4407 100644
@@ -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) {
Signature · 1 line
2.30.1