Commit 52cdbea1 authored by Justin Stitt's avatar Justin Stitt Committed by Jakub Kicinski

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: https://github.com/KSPP/linux/issues/90Signed-off-by: default avatarJustin Stitt <justinstitt@google.com>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20231005-strncpy-drivers-net-ethernet-cavium-liquidio-lio_ethtool-c-v1-1-ab565ab4d197@google.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 0aba5247
...@@ -442,10 +442,11 @@ lio_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo) ...@@ -442,10 +442,11 @@ lio_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
oct = lio->oct_dev; oct = lio->oct_dev;
memset(drvinfo, 0, sizeof(struct ethtool_drvinfo)); memset(drvinfo, 0, sizeof(struct ethtool_drvinfo));
strcpy(drvinfo->driver, "liquidio"); strscpy(drvinfo->driver, "liquidio", sizeof(drvinfo->driver));
strncpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version, strscpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version,
ETHTOOL_FWVERS_LEN); sizeof(drvinfo->fw_version));
strncpy(drvinfo->bus_info, pci_name(oct->pci_dev), 32); strscpy(drvinfo->bus_info, pci_name(oct->pci_dev),
sizeof(drvinfo->bus_info));
} }
static void static void
...@@ -458,10 +459,11 @@ lio_get_vf_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo) ...@@ -458,10 +459,11 @@ lio_get_vf_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
oct = lio->oct_dev; oct = lio->oct_dev;
memset(drvinfo, 0, sizeof(struct ethtool_drvinfo)); memset(drvinfo, 0, sizeof(struct ethtool_drvinfo));
strcpy(drvinfo->driver, "liquidio_vf"); strscpy(drvinfo->driver, "liquidio_vf", sizeof(drvinfo->driver));
strncpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version, strscpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version,
ETHTOOL_FWVERS_LEN); sizeof(drvinfo->fw_version));
strncpy(drvinfo->bus_info, pci_name(oct->pci_dev), 32); strscpy(drvinfo->bus_info, pci_name(oct->pci_dev),
sizeof(drvinfo->bus_info));
} }
static int static int
......
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