Skip to content

Commit

Permalink
scsi: iscsi: Fix missing scsi_host_put() in error path
Browse files Browse the repository at this point in the history
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: ce51c81 ("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>
  • Loading branch information
Miaoqian Lin authored and Martin K. Petersen committed Apr 3, 2025
1 parent 20b97ac commit 72eea84
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/scsi/scsi_transport_iscsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 72eea84

Please sign in to comment.