* [PATCH] scsi: qla2xxx: Replace all non-returning strlcpy with strscpy
@ 2023-05-16 2:54 Azeem Shaikh
2023-05-16 18:17 ` Kees Cook
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Azeem Shaikh @ 2023-05-16 2:54 UTC (permalink / raw)
To: Nilesh Javali, GR-QLogic-Storage-Upstream
Cc: linux-hardening, Azeem Shaikh, linux-scsi, linux-kernel,
James E.J. Bottomley, Martin K. Petersen
strlcpy() reads the entire source buffer first.
This read may exceed the destination size limit.
This is both inefficient and can lead to linear read
overflows if a source string is not NUL-terminated [1].
In an effort to remove strlcpy() completely [2], replace
strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.
[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89
Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>
---
drivers/scsi/qla2xxx/qla_init.c | 8 ++++----
drivers/scsi/qla2xxx/qla_mr.c | 20 ++++++++++----------
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index ec0423ec6681..e831d14a4044 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -4861,7 +4861,7 @@ qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
if (use_tbl &&
ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
index < QLA_MODEL_NAMES)
- strlcpy(ha->model_desc,
+ strscpy(ha->model_desc,
qla2x00_model_name[index * 2 + 1],
sizeof(ha->model_desc));
} else {
@@ -4869,14 +4869,14 @@ qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
if (use_tbl &&
ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
index < QLA_MODEL_NAMES) {
- strlcpy(ha->model_number,
+ strscpy(ha->model_number,
qla2x00_model_name[index * 2],
sizeof(ha->model_number));
- strlcpy(ha->model_desc,
+ strscpy(ha->model_desc,
qla2x00_model_name[index * 2 + 1],
sizeof(ha->model_desc));
} else {
- strlcpy(ha->model_number, def,
+ strscpy(ha->model_number, def,
sizeof(ha->model_number));
}
}
diff --git a/drivers/scsi/qla2xxx/qla_mr.c b/drivers/scsi/qla2xxx/qla_mr.c
index f726eb8449c5..083f94e43fba 100644
--- a/drivers/scsi/qla2xxx/qla_mr.c
+++ b/drivers/scsi/qla2xxx/qla_mr.c
@@ -691,7 +691,7 @@ qlafx00_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
struct qla_hw_data *ha = vha->hw;
if (pci_is_pcie(ha->pdev))
- strlcpy(str, "PCIe iSA", str_len);
+ strscpy(str, "PCIe iSA", str_len);
return str;
}
@@ -1850,21 +1850,21 @@ qlafx00_fx_disc(scsi_qla_host_t *vha, fc_port_t *fcport, uint16_t fx_type)
phost_info = &preg_hsi->hsi;
memset(preg_hsi, 0, sizeof(struct register_host_info));
phost_info->os_type = OS_TYPE_LINUX;
- strlcpy(phost_info->sysname, p_sysid->sysname,
+ strscpy(phost_info->sysname, p_sysid->sysname,
sizeof(phost_info->sysname));
- strlcpy(phost_info->nodename, p_sysid->nodename,
+ strscpy(phost_info->nodename, p_sysid->nodename,
sizeof(phost_info->nodename));
if (!strcmp(phost_info->nodename, "(none)"))
ha->mr.host_info_resend = true;
- strlcpy(phost_info->release, p_sysid->release,
+ strscpy(phost_info->release, p_sysid->release,
sizeof(phost_info->release));
- strlcpy(phost_info->version, p_sysid->version,
+ strscpy(phost_info->version, p_sysid->version,
sizeof(phost_info->version));
- strlcpy(phost_info->machine, p_sysid->machine,
+ strscpy(phost_info->machine, p_sysid->machine,
sizeof(phost_info->machine));
- strlcpy(phost_info->domainname, p_sysid->domainname,
+ strscpy(phost_info->domainname, p_sysid->domainname,
sizeof(phost_info->domainname));
- strlcpy(phost_info->hostdriver, QLA2XXX_VERSION,
+ strscpy(phost_info->hostdriver, QLA2XXX_VERSION,
sizeof(phost_info->hostdriver));
preg_hsi->utc = (uint64_t)ktime_get_real_seconds();
ql_dbg(ql_dbg_init, vha, 0x0149,
@@ -1909,9 +1909,9 @@ qlafx00_fx_disc(scsi_qla_host_t *vha, fc_port_t *fcport, uint16_t fx_type)
if (fx_type == FXDISC_GET_CONFIG_INFO) {
struct config_info_data *pinfo =
(struct config_info_data *) fdisc->u.fxiocb.rsp_addr;
- strlcpy(vha->hw->model_number, pinfo->model_num,
+ strscpy(vha->hw->model_number, pinfo->model_num,
ARRAY_SIZE(vha->hw->model_number));
- strlcpy(vha->hw->model_desc, pinfo->model_description,
+ strscpy(vha->hw->model_desc, pinfo->model_description,
ARRAY_SIZE(vha->hw->model_desc));
memcpy(&vha->hw->mr.symbolic_name, pinfo->symbolic_name,
sizeof(vha->hw->mr.symbolic_name));
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] scsi: qla2xxx: Replace all non-returning strlcpy with strscpy
2023-05-16 2:54 [PATCH] scsi: qla2xxx: Replace all non-returning strlcpy with strscpy Azeem Shaikh
@ 2023-05-16 18:17 ` Kees Cook
2023-05-17 1:41 ` Martin K. Petersen
2023-05-22 22:46 ` Martin K. Petersen
2 siblings, 0 replies; 6+ messages in thread
From: Kees Cook @ 2023-05-16 18:17 UTC (permalink / raw)
To: Azeem Shaikh
Cc: Nilesh Javali, GR-QLogic-Storage-Upstream, linux-hardening,
linux-scsi, linux-kernel, James E.J. Bottomley,
Martin K. Petersen
On Tue, May 16, 2023 at 02:54:04AM +0000, Azeem Shaikh wrote:
> strlcpy() reads the entire source buffer first.
> This read may exceed the destination size limit.
> This is both inefficient and can lead to linear read
> overflows if a source string is not NUL-terminated [1].
> In an effort to remove strlcpy() completely [2], replace
> strlcpy() here with strscpy().
> No return values were used, so direct replacement is safe.
>
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
> [2] https://github.com/KSPP/linux/issues/89
>
> Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] scsi: qla2xxx: Replace all non-returning strlcpy with strscpy
2023-05-16 2:54 [PATCH] scsi: qla2xxx: Replace all non-returning strlcpy with strscpy Azeem Shaikh
2023-05-16 18:17 ` Kees Cook
@ 2023-05-17 1:41 ` Martin K. Petersen
2023-05-17 14:11 ` Azeem Shaikh
2023-05-22 22:46 ` Martin K. Petersen
2 siblings, 1 reply; 6+ messages in thread
From: Martin K. Petersen @ 2023-05-17 1:41 UTC (permalink / raw)
To: Azeem Shaikh
Cc: Nilesh Javali, GR-QLogic-Storage-Upstream, linux-hardening,
linux-scsi, linux-kernel, James E.J. Bottomley,
Martin K. Petersen
Azeem,
> strlcpy() reads the entire source buffer first. This read may exceed
> the destination size limit. This is both inefficient and can lead to
> linear read overflows if a source string is not NUL-terminated [1]. In
> an effort to remove strlcpy() completely [2], replace strlcpy() here
> with strscpy(). No return values were used, so direct replacement is
> safe.
Applied to 6.5/scsi-staging, thanks!
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] scsi: qla2xxx: Replace all non-returning strlcpy with strscpy
2023-05-17 1:41 ` Martin K. Petersen
@ 2023-05-17 14:11 ` Azeem Shaikh
2023-05-18 4:48 ` Azeem Shaikh
0 siblings, 1 reply; 6+ messages in thread
From: Azeem Shaikh @ 2023-05-17 14:11 UTC (permalink / raw)
To: Martin K. Petersen
Cc: Nilesh Javali, GR-QLogic-Storage-Upstream, linux-hardening,
linux-scsi, linux-kernel, James E.J. Bottomley
On Tue, May 16, 2023 at 9:42 PM Martin K. Petersen
<martin.petersen@oracle.com> wrote:
>
>
> Azeem,
>
> > strlcpy() reads the entire source buffer first. This read may exceed
> > the destination size limit. This is both inefficient and can lead to
> > linear read overflows if a source string is not NUL-terminated [1]. In
> > an effort to remove strlcpy() completely [2], replace strlcpy() here
> > with strscpy(). No return values were used, so direct replacement is
> > safe.
>
> Applied to 6.5/scsi-staging, thanks!
>
Thanks a lot for the quick response Martin (on this and other patches
too). Just for my understanding, do you mind pointing me to the
6.5/scsi-staging tree?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] scsi: qla2xxx: Replace all non-returning strlcpy with strscpy
2023-05-17 14:11 ` Azeem Shaikh
@ 2023-05-18 4:48 ` Azeem Shaikh
0 siblings, 0 replies; 6+ messages in thread
From: Azeem Shaikh @ 2023-05-18 4:48 UTC (permalink / raw)
To: Martin K. Petersen
Cc: Nilesh Javali, GR-QLogic-Storage-Upstream, linux-hardening,
linux-scsi, linux-kernel, James E.J. Bottomley
On Wed, May 17, 2023 at 10:11 AM Azeem Shaikh <azeemshaikh38@gmail.com> wrote:
>
> On Tue, May 16, 2023 at 9:42 PM Martin K. Petersen
> <martin.petersen@oracle.com> wrote:
> >
> >
> > Azeem,
> >
> > > strlcpy() reads the entire source buffer first. This read may exceed
> > > the destination size limit. This is both inefficient and can lead to
> > > linear read overflows if a source string is not NUL-terminated [1]. In
> > > an effort to remove strlcpy() completely [2], replace strlcpy() here
> > > with strscpy(). No return values were used, so direct replacement is
> > > safe.
> >
> > Applied to 6.5/scsi-staging, thanks!
> >
>
> Thanks a lot for the quick response Martin (on this and other patches
> too). Just for my understanding, do you mind pointing me to the
> 6.5/scsi-staging tree?
Found it: https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git/log/?h=6.5/scsi-staging
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] scsi: qla2xxx: Replace all non-returning strlcpy with strscpy
2023-05-16 2:54 [PATCH] scsi: qla2xxx: Replace all non-returning strlcpy with strscpy Azeem Shaikh
2023-05-16 18:17 ` Kees Cook
2023-05-17 1:41 ` Martin K. Petersen
@ 2023-05-22 22:46 ` Martin K. Petersen
2 siblings, 0 replies; 6+ messages in thread
From: Martin K. Petersen @ 2023-05-22 22:46 UTC (permalink / raw)
To: Nilesh Javali, GR-QLogic-Storage-Upstream, Azeem Shaikh
Cc: Martin K . Petersen, linux-hardening, linux-scsi, linux-kernel,
James E.J. Bottomley
On Tue, 16 May 2023 02:54:04 +0000, Azeem Shaikh wrote:
> strlcpy() reads the entire source buffer first.
> This read may exceed the destination size limit.
> This is both inefficient and can lead to linear read
> overflows if a source string is not NUL-terminated [1].
> In an effort to remove strlcpy() completely [2], replace
> strlcpy() here with strscpy().
> No return values were used, so direct replacement is safe.
>
> [...]
Applied to 6.5/scsi-queue, thanks!
[1/1] scsi: qla2xxx: Replace all non-returning strlcpy with strscpy
https://git.kernel.org/mkp/scsi/c/37f1663c9193
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-05-22 22:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-16 2:54 [PATCH] scsi: qla2xxx: Replace all non-returning strlcpy with strscpy Azeem Shaikh
2023-05-16 18:17 ` Kees Cook
2023-05-17 1:41 ` Martin K. Petersen
2023-05-17 14:11 ` Azeem Shaikh
2023-05-18 4:48 ` Azeem Shaikh
2023-05-22 22:46 ` Martin K. Petersen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox