scsi: iscsi: Fix missing scsi_host_put() in error path
authorMiaoqian Lin <linmq006@gmail.com>
Tue, 18 Mar 2025 09:43:43 +0000 (17:43 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Apr 2025 08:45:38 +0000 (10:45 +0200)
[ Upstream commit 72eea84a1092b50a10eeecfeba4b28ac9f1312ab ]

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()")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Link: https://lore.kernel.org/r/20250318094344.91776-1-linmq006@gmail.com
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/scsi/scsi_transport_iscsi.c

index deeb657981a690f621841ebee22703dc93a68373..0c30fec555475bde5edc9e83eb7747c1049bb35d 100644 (file)
@@ -3208,11 +3208,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;
 }