Skip to content

Commit 97776ca

Browse files
davidarinzonkuba-moo
authored andcommitted
net: ena: Changes around strscpy calls
strscpy copies as much of the string as possible, meaning that the destination string will be truncated in case of no space. As this is a non-critical error in our case, adding a debug level print for indication. This patch also removes a -1 which was added to ensure enough space for NUL, but strscpy destination string is guaranteed to be NUL-terminted, therefore, the -1 is not needed. Signed-off-by: David Arinzon <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent b37b98a commit 97776ca

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

drivers/net/ethernet/amazon/ena/ena_ethtool.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,18 @@ static void ena_get_drvinfo(struct net_device *dev,
460460
struct ethtool_drvinfo *info)
461461
{
462462
struct ena_adapter *adapter = netdev_priv(dev);
463-
464-
strscpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
465-
strscpy(info->bus_info, pci_name(adapter->pdev),
466-
sizeof(info->bus_info));
463+
ssize_t ret = 0;
464+
465+
ret = strscpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
466+
if (ret < 0)
467+
netif_dbg(adapter, drv, dev,
468+
"module name will be truncated, status = %zd\n", ret);
469+
470+
ret = strscpy(info->bus_info, pci_name(adapter->pdev),
471+
sizeof(info->bus_info));
472+
if (ret < 0)
473+
netif_dbg(adapter, drv, dev,
474+
"bus info will be truncated, status = %zd\n", ret);
467475
}
468476

469477
static void ena_get_ringparam(struct net_device *netdev,

drivers/net/ethernet/amazon/ena/ena_netdev.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,6 +2703,7 @@ static void ena_config_host_info(struct ena_com_dev *ena_dev, struct pci_dev *pd
27032703
{
27042704
struct device *dev = &pdev->dev;
27052705
struct ena_admin_host_info *host_info;
2706+
ssize_t ret;
27062707
int rc;
27072708

27082709
/* Allocate only the host info */
@@ -2717,11 +2718,19 @@ static void ena_config_host_info(struct ena_com_dev *ena_dev, struct pci_dev *pd
27172718
host_info->bdf = pci_dev_id(pdev);
27182719
host_info->os_type = ENA_ADMIN_OS_LINUX;
27192720
host_info->kernel_ver = LINUX_VERSION_CODE;
2720-
strscpy(host_info->kernel_ver_str, utsname()->version,
2721-
sizeof(host_info->kernel_ver_str) - 1);
2721+
ret = strscpy(host_info->kernel_ver_str, utsname()->version,
2722+
sizeof(host_info->kernel_ver_str));
2723+
if (ret < 0)
2724+
dev_dbg(dev,
2725+
"kernel version string will be truncated, status = %zd\n", ret);
2726+
27222727
host_info->os_dist = 0;
2723-
strscpy(host_info->os_dist_str, utsname()->release,
2724-
sizeof(host_info->os_dist_str));
2728+
ret = strscpy(host_info->os_dist_str, utsname()->release,
2729+
sizeof(host_info->os_dist_str));
2730+
if (ret < 0)
2731+
dev_dbg(dev,
2732+
"OS distribution string will be truncated, status = %zd\n", ret);
2733+
27252734
host_info->driver_version =
27262735
(DRV_MODULE_GEN_MAJOR) |
27272736
(DRV_MODULE_GEN_MINOR << ENA_ADMIN_HOST_INFO_MINOR_SHIFT) |

0 commit comments

Comments
 (0)