Skip to content

Commit 45e833f

Browse files
JustinStittmartinkpetersen
authored andcommitted
scsi: message: fusion: Replace deprecated strncpy() with strscpy()
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: KSPP#90 Cc: linux-hardening@vger.kernel.org Cc: Kees Cook <keescook@chromium.org> Signed-off-by: Justin Stitt <justinstitt@google.com> Link: https://lore.kernel.org/r/20231003-strncpy-drivers-message-fusion-mptsas-c-v2-1-5ce07e60bd21@google.com Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 4280a0a commit 45e833f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

drivers/message/fusion/mptsas.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,17 +2964,17 @@ mptsas_exp_repmanufacture_info(MPT_ADAPTER *ioc,
29642964
goto out_free;
29652965

29662966
manufacture_reply = data_out + sizeof(struct rep_manu_request);
2967-
strncpy(edev->vendor_id, manufacture_reply->vendor_id,
2968-
SAS_EXPANDER_VENDOR_ID_LEN);
2969-
strncpy(edev->product_id, manufacture_reply->product_id,
2970-
SAS_EXPANDER_PRODUCT_ID_LEN);
2971-
strncpy(edev->product_rev, manufacture_reply->product_rev,
2972-
SAS_EXPANDER_PRODUCT_REV_LEN);
2967+
strscpy(edev->vendor_id, manufacture_reply->vendor_id,
2968+
sizeof(edev->vendor_id));
2969+
strscpy(edev->product_id, manufacture_reply->product_id,
2970+
sizeof(edev->product_id));
2971+
strscpy(edev->product_rev, manufacture_reply->product_rev,
2972+
sizeof(edev->product_rev));
29732973
edev->level = manufacture_reply->sas_format;
29742974
if (manufacture_reply->sas_format) {
2975-
strncpy(edev->component_vendor_id,
2975+
strscpy(edev->component_vendor_id,
29762976
manufacture_reply->component_vendor_id,
2977-
SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN);
2977+
sizeof(edev->component_vendor_id));
29782978
tmp = (u8 *)&manufacture_reply->component_id;
29792979
edev->component_id = tmp[0] << 8 | tmp[1];
29802980
edev->component_revision_id =

0 commit comments

Comments
 (0)