Re: [PATCH] scsi: zfcp: Replace strlcpy() with strscpy()

From: Alexander Gordeev
Date: Fri Nov 17 2023 - 13:19:58 EST


On Thu, Nov 16, 2023 at 11:14:35AM -0800, Kees Cook wrote:

Hi Kees,

> diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
> index 4f0d0e55f0d4..1a29f10767fc 100644
> --- a/drivers/s390/scsi/zfcp_fc.c
> +++ b/drivers/s390/scsi/zfcp_fc.c
> @@ -900,8 +900,15 @@ static void zfcp_fc_rspn(struct zfcp_adapter *adapter,
> zfcp_fc_ct_ns_init(&rspn_req->ct_hdr, FC_NS_RSPN_ID,
> FC_SYMBOLIC_NAME_SIZE);
> hton24(rspn_req->rspn.fr_fid.fp_fid, fc_host_port_id(shost));
> - len = strlcpy(rspn_req->rspn.fr_name, fc_host_symbolic_name(shost),
> - FC_SYMBOLIC_NAME_SIZE);
> + len = strscpy(rspn_req->name, fc_host_symbolic_name(shost),
> + sizeof(rspn_req->name));

Could you please explain why do you copy to rspn_req->name instead
of rspn_req->rspn.fr_name?

> + /*
> + * It should be impossible for this to truncate, as
> + * sizeof(rspn_req->name) is equal to max size of
> + * fc_host_symbolic_name(shost), but check anyway.
> + */
> + if (len < 0)
> + len = sizeof(rspn_req->name) - 1;
> rspn_req->rspn.fr_name_len = len;
>
> sg_init_one(&fc_req->sg_req, rspn_req, sizeof(*rspn_req));

Thanks!