Skip to content

Commit 52cdbea

Browse files
JustinStittkuba-moo
authored andcommitted
liquidio: replace deprecated strncpy/strcpy 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. NUL-padding is not required as drvinfo is memset to 0: | memset(drvinfo, 0, sizeof(struct ethtool_drvinfo)); A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer without unnecessarily NUL-padding. 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/linux#90 Signed-off-by: Justin Stitt <justinstitt@google.com> Reviewed-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20231005-strncpy-drivers-net-ethernet-cavium-liquidio-lio_ethtool-c-v1-1-ab565ab4d197@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 0aba524 commit 52cdbea

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

drivers/net/ethernet/cavium/liquidio/lio_ethtool.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,11 @@ lio_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
442442
oct = lio->oct_dev;
443443

444444
memset(drvinfo, 0, sizeof(struct ethtool_drvinfo));
445-
strcpy(drvinfo->driver, "liquidio");
446-
strncpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version,
447-
ETHTOOL_FWVERS_LEN);
448-
strncpy(drvinfo->bus_info, pci_name(oct->pci_dev), 32);
445+
strscpy(drvinfo->driver, "liquidio", sizeof(drvinfo->driver));
446+
strscpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version,
447+
sizeof(drvinfo->fw_version));
448+
strscpy(drvinfo->bus_info, pci_name(oct->pci_dev),
449+
sizeof(drvinfo->bus_info));
449450
}
450451

451452
static void
@@ -458,10 +459,11 @@ lio_get_vf_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
458459
oct = lio->oct_dev;
459460

460461
memset(drvinfo, 0, sizeof(struct ethtool_drvinfo));
461-
strcpy(drvinfo->driver, "liquidio_vf");
462-
strncpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version,
463-
ETHTOOL_FWVERS_LEN);
464-
strncpy(drvinfo->bus_info, pci_name(oct->pci_dev), 32);
462+
strscpy(drvinfo->driver, "liquidio_vf", sizeof(drvinfo->driver));
463+
strscpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version,
464+
sizeof(drvinfo->fw_version));
465+
strscpy(drvinfo->bus_info, pci_name(oct->pci_dev),
466+
sizeof(drvinfo->bus_info));
465467
}
466468

467469
static int

0 commit comments

Comments
 (0)