* [PATCH v2] scsi: message: fusion: replace deprecated strncpy with strscpy
@ 2023-10-03 22:15 Justin Stitt
2023-10-03 23:45 ` Kees Cook
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Justin Stitt @ 2023-10-03 22:15 UTC (permalink / raw)
To: Sathya Prakash, Sreekanth Reddy, Suganath Prabu Subramani
Cc: MPT-FusionLinux.pdl, linux-scsi, linux-kernel, linux-hardening,
Kees Cook, Justin Stitt
`strncpy` is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string
interfaces.
The only caller of mptsas_exp_repmanufacture_info() is
mptsas_probe_one_phy() which can allocate rphy in either
sas_end_device_alloc() or sas_expander_alloc(). Both of which
zero-allocate:
| rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
... this is supplied to mptsas_exp_repmanufacture_info() as edev meaning
that no future NUL-padding of edev members is needed.
Considering the above, a suitable replacement is `strscpy` [2] due to
the fact that it guarantees NUL-termination on the destination buffer
without unnecessarily NUL-padding.
Also use the more idiomatic strscpy pattern of (dest, src, sizeof(dest))
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2]
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
Changes in v2:
- use sizeof(dest) pattern (thanks Kees)
- rebase onto mainline cbf3a2cb156a2c91
- Link to v1: https://lore.kernel.org/r/20230927-strncpy-drivers-message-fusion-mptsas-c-v1-1-edac65cd7010@google.com
---
Note: build-tested only.
Note: similar to drivers/scsi/mpi3mr/mpi3mr_transport.c +212 which uses
strscpy
---
drivers/message/fusion/mptsas.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index 86f16f3ea478..300f8e955a53 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -2964,17 +2964,17 @@ mptsas_exp_repmanufacture_info(MPT_ADAPTER *ioc,
goto out_free;
manufacture_reply = data_out + sizeof(struct rep_manu_request);
- strncpy(edev->vendor_id, manufacture_reply->vendor_id,
- SAS_EXPANDER_VENDOR_ID_LEN);
- strncpy(edev->product_id, manufacture_reply->product_id,
- SAS_EXPANDER_PRODUCT_ID_LEN);
- strncpy(edev->product_rev, manufacture_reply->product_rev,
- SAS_EXPANDER_PRODUCT_REV_LEN);
+ strscpy(edev->vendor_id, manufacture_reply->vendor_id,
+ sizeof(edev->vendor_id));
+ strscpy(edev->product_id, manufacture_reply->product_id,
+ sizeof(edev->product_id));
+ strscpy(edev->product_rev, manufacture_reply->product_rev,
+ sizeof(edev->product_rev));
edev->level = manufacture_reply->sas_format;
if (manufacture_reply->sas_format) {
- strncpy(edev->component_vendor_id,
+ strscpy(edev->component_vendor_id,
manufacture_reply->component_vendor_id,
- SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN);
+ sizeof(edev->component_vendor_id));
tmp = (u8 *)&manufacture_reply->component_id;
edev->component_id = tmp[0] << 8 | tmp[1];
edev->component_revision_id =
---
base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2
change-id: 20230927-strncpy-drivers-message-fusion-mptsas-c-f22d5a4082e2
Best regards,
--
Justin Stitt <justinstitt@google.com>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] scsi: message: fusion: replace deprecated strncpy with strscpy
2023-10-03 22:15 [PATCH v2] scsi: message: fusion: replace deprecated strncpy with strscpy Justin Stitt
@ 2023-10-03 23:45 ` Kees Cook
2023-10-10 1:31 ` Martin K. Petersen
2023-10-13 21:03 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2023-10-03 23:45 UTC (permalink / raw)
To: Justin Stitt
Cc: Sathya Prakash, Sreekanth Reddy, Suganath Prabu Subramani,
MPT-FusionLinux.pdl, linux-scsi, linux-kernel, linux-hardening
On Tue, Oct 03, 2023 at 10:15:45PM +0000, Justin Stitt wrote:
> `strncpy` is deprecated for use on NUL-terminated destination strings
> [1] and as such we should prefer more robust and less ambiguous string
> interfaces.
>
> The only caller of mptsas_exp_repmanufacture_info() is
> mptsas_probe_one_phy() which can allocate rphy in either
> sas_end_device_alloc() or sas_expander_alloc(). Both of which
> zero-allocate:
> | rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
> ... this is supplied to mptsas_exp_repmanufacture_info() as edev meaning
> that no future NUL-padding of edev members is needed.
>
> Considering the above, a suitable replacement is `strscpy` [2] due to
> the fact that it guarantees NUL-termination on the destination buffer
> without unnecessarily NUL-padding.
>
> Also use the more idiomatic strscpy pattern of (dest, src, sizeof(dest))
>
> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
> Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2]
> Link: https://github.com/KSPP/linux/issues/90
> Cc: linux-hardening@vger.kernel.org
> Cc: Kees Cook <keescook@chromium.org>
> Signed-off-by: Justin Stitt <justinstitt@google.com>
Thanks for adjusting the sizes. Looks good!
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] scsi: message: fusion: replace deprecated strncpy with strscpy
2023-10-03 22:15 [PATCH v2] scsi: message: fusion: replace deprecated strncpy with strscpy Justin Stitt
2023-10-03 23:45 ` Kees Cook
@ 2023-10-10 1:31 ` Martin K. Petersen
2023-10-13 21:03 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2023-10-10 1:31 UTC (permalink / raw)
To: Justin Stitt
Cc: Sathya Prakash, Sreekanth Reddy, Suganath Prabu Subramani,
MPT-FusionLinux.pdl, linux-scsi, linux-kernel, linux-hardening,
Kees Cook
Justin,
> `strncpy` is deprecated for use on NUL-terminated destination strings
> [1] and as such we should prefer more robust and less ambiguous string
> interfaces.
Applied to 6.7/scsi-staging, thanks!
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] scsi: message: fusion: replace deprecated strncpy with strscpy
2023-10-03 22:15 [PATCH v2] scsi: message: fusion: replace deprecated strncpy with strscpy Justin Stitt
2023-10-03 23:45 ` Kees Cook
2023-10-10 1:31 ` Martin K. Petersen
@ 2023-10-13 21:03 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2023-10-13 21:03 UTC (permalink / raw)
To: Sathya Prakash, Sreekanth Reddy, Suganath Prabu Subramani,
Justin Stitt
Cc: Martin K . Petersen, MPT-FusionLinux.pdl, linux-scsi,
linux-kernel, linux-hardening, Kees Cook
On Tue, 03 Oct 2023 22:15:45 +0000, Justin Stitt wrote:
> `strncpy` is deprecated for use on NUL-terminated destination strings
> [1] and as such we should prefer more robust and less ambiguous string
> interfaces.
>
> The only caller of mptsas_exp_repmanufacture_info() is
> mptsas_probe_one_phy() which can allocate rphy in either
> sas_end_device_alloc() or sas_expander_alloc(). Both of which
> zero-allocate:
> | rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
> ... this is supplied to mptsas_exp_repmanufacture_info() as edev meaning
> that no future NUL-padding of edev members is needed.
>
> [...]
Applied to 6.7/scsi-queue, thanks!
[1/1] scsi: message: fusion: replace deprecated strncpy with strscpy
https://git.kernel.org/mkp/scsi/c/45e833f0e5bb
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-10-13 21:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-03 22:15 [PATCH v2] scsi: message: fusion: replace deprecated strncpy with strscpy Justin Stitt
2023-10-03 23:45 ` Kees Cook
2023-10-10 1:31 ` Martin K. Petersen
2023-10-13 21:03 ` 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