Skip to contentSkip to conversation

scsi: iscsi: Fix missing scsi_host_put in error path

PATCH Applied [email protected] 3 participants 3 messages Mar 18, 2025 – Apr 3, 2025

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

PATCH 1/1 scsi: iscsi: Fix missing scsi_host_put in error path

From: Miaoqian Lin <[email protected]>

Add goto to ensure scsi_host_put is called in all error paths of iscsi_set_host_param function. This fixes a potential memory leak when strlen check fails.

Fixes ce51c8170084 ("scsi: iscsi: Add strlen() check in iscsi_if_set{_host}_param()")
---
 drivers/scsi/scsi_transport_iscsi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/scsi/scsi_transport_iscsi.c +5 -2
index 9c347c64c315..0b8c91bf793f 100644
@@ -3182,11 +3182,14 @@ iscsi_set_host_param(struct iscsi_transport *transport,
 	}
 
 	/* see similar check in iscsi_if_set_param() */
-	if (strlen(data) > ev->u.set_host_param.len)
-		return -EINVAL;
+	if (strlen(data) > ev->u.set_host_param.len) {
+		err = -EINVAL;
+		goto out;
+	}
 
 	err = transport->set_host_param(shost, ev->u.set_host_param.param,
 					data, ev->u.set_host_param.len);
+out:
 	scsi_host_put(shost);
 	return err;
 }
Signature · 1 line
2.39.5 (Apple Git-154)
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · On 3/18/25 4:43 AM, [email protected] wrote:

From: Miaoqian Lin <[email protected]>

Add goto to ensure scsi_host_put is called in all error paths of iscsi_set_host_param function. This fixes a potential memory leak when strlen check fails.

Fixes ce51c8170084 ("scsi: iscsi: Add strlen() check in iscsi_if_set{_host}_param()")
---
 drivers/scsi/scsi_transport_iscsi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/scsi/scsi_transport_iscsi.c +1 -2
index 9c347c64c315..0b8c91bf793f 100644
@@ -3182,11 +3182,14 @@ iscsi_set_host_param(struct iscsi_transport *transport,
 	}
 
 	/* see similar check in iscsi_if_set_param() */
-	if (strlen(data) > ev->u.set_host_param.len)
-		return -EINVAL;
+	if (strlen(data) > ev->u.set_host_param.len) {

drivers/scsi/scsi_transport_iscsi.c iscsi_set_host_param(struct iscsi_transport *transport, · line 3195

Quoted 10 lines
drivers/scsi/scsi_transport_iscsi.c +4 -0
+		err = -EINVAL;
+		goto out;
+	}
 
 	err = transport->set_host_param(shost, ev->u.set_host_param.param,
 					data, ev->u.set_host_param.len);
+out:
 	scsi_host_put(shost);
 	return err;
 }
#2 lore raw
In reply to [email protected]
Quoted 4 lines

Add goto to ensure scsi_host_put is called in all error paths of iscsi_set_host_param function. This fixes a potential memory leak when strlen check fails.

Applied to 6.15/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen