Commit adb77bba authored by Kees Cook's avatar Kees Cook Committed by Kees Cook

scsi: mpt3sas: Avoid possible run-time warning with long manufacturer strings

The prior strscpy() replacement of strncpy() here expected the
manufacture_reply strings to be NUL-terminated, but it is possible
they are not, as the code pattern here shows, e.g., edev->vendor_id
being exactly 1 character larger than manufacture_reply->vendor_id,
and the replaced strncpy() was copying only up to the size of the
source character array. Replace this with memtostr(), which is the
unambiguous way to convert a maybe not-NUL-terminated character array
into a NUL-terminated string.

Fixes: b7e9712a ("scsi: mpt3sas: Replace deprecated strncpy() with strscpy()")
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Tested-by: default avatarMarco Patalano <mpatalan@redhat.com>
Reviewed-by: default avatarEwan D. Milne <emilne@redhat.com>
Reviewed-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Link: https://lore.kernel.org/r/20240410023155.2100422-3-keescook@chromium.orgSigned-off-by: default avatarKees Cook <kees@kernel.org>
parent 1613e604
...@@ -4774,7 +4774,7 @@ _base_display_ioc_capabilities(struct MPT3SAS_ADAPTER *ioc) ...@@ -4774,7 +4774,7 @@ _base_display_ioc_capabilities(struct MPT3SAS_ADAPTER *ioc)
char desc[17] = {0}; char desc[17] = {0};
u32 iounit_pg1_flags; u32 iounit_pg1_flags;
strscpy(desc, ioc->manu_pg0.ChipName, sizeof(desc)); memtostr(desc, ioc->manu_pg0.ChipName);
ioc_info(ioc, "%s: FWVersion(%02d.%02d.%02d.%02d), ChipRevision(0x%02x)\n", ioc_info(ioc, "%s: FWVersion(%02d.%02d.%02d.%02d), ChipRevision(0x%02x)\n",
desc, desc,
(ioc->facts.FWVersion.Word & 0xFF000000) >> 24, (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
......
...@@ -458,17 +458,13 @@ _transport_expander_report_manufacture(struct MPT3SAS_ADAPTER *ioc, ...@@ -458,17 +458,13 @@ _transport_expander_report_manufacture(struct MPT3SAS_ADAPTER *ioc,
goto out; goto out;
manufacture_reply = data_out + sizeof(struct rep_manu_request); manufacture_reply = data_out + sizeof(struct rep_manu_request);
strscpy(edev->vendor_id, manufacture_reply->vendor_id, memtostr(edev->vendor_id, manufacture_reply->vendor_id);
sizeof(edev->vendor_id)); memtostr(edev->product_id, manufacture_reply->product_id);
strscpy(edev->product_id, manufacture_reply->product_id, memtostr(edev->product_rev, manufacture_reply->product_rev);
sizeof(edev->product_id));
strscpy(edev->product_rev, manufacture_reply->product_rev,
sizeof(edev->product_rev));
edev->level = manufacture_reply->sas_format & 1; edev->level = manufacture_reply->sas_format & 1;
if (edev->level) { if (edev->level) {
strscpy(edev->component_vendor_id, memtostr(edev->component_vendor_id,
manufacture_reply->component_vendor_id, manufacture_reply->component_vendor_id);
sizeof(edev->component_vendor_id));
tmp = (u8 *)&manufacture_reply->component_id; tmp = (u8 *)&manufacture_reply->component_id;
edev->component_id = tmp[0] << 8 | tmp[1]; edev->component_id = tmp[0] << 8 | tmp[1];
edev->component_revision_id = edev->component_revision_id =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment