Intel Wired LAN Driver Updates 2023-10-17
Subsystems (3)
cover Intel Wired LAN Driver Updates 2023-10-17
This series contains cleanups for all the Intel drivers relating to their use of format specifiers and the use of strncpy.
Jesse fixes various -Wformat warnings across all the Intel networking, including various cases where a "%s" string format specifier is preferred, and using kasprintf instead of snprintf.
Justin replaces all of the uses of the now deprecated strncpy with a more modern string function, primarily strscpy.
Jesse Brandeburg (2):
intel: fix string truncation warnings
intel: fix format warnings
Justin Stitt (7):
e100: replace deprecated strncpy with strscpy
e1000: replace deprecated strncpy with strscpy
fm10k: replace deprecated strncpy with strscpy
i40e: use scnprintf over strncpy+strncat
igb: replace deprecated strncpy with strscpy
igbvf: replace deprecated strncpy with strscpy
igc: replace deprecated strncpy with strscpy
drivers/net/ethernet/intel/e100.c | 2 +- drivers/net/ethernet/intel/e1000/e1000_main.c | 2 +- .../net/ethernet/intel/fm10k/fm10k_ethtool.c | 8 ++-- drivers/net/ethernet/intel/i40e/i40e_ddp.c | 7 ++-- .../net/ethernet/intel/i40e/i40e_ethtool.c | 6 ++- .../net/ethernet/intel/iavf/iavf_ethtool.c | 8 ++-- .../net/ethernet/intel/iavf/iavf_virtchnl.c | 22 ++++------- drivers/net/ethernet/intel/ice/ice_ethtool.c | 7 ++-- drivers/net/ethernet/intel/ice/ice_ptp.c | 4 +- drivers/net/ethernet/intel/igb/igb_ethtool.c | 4 +- drivers/net/ethernet/intel/igb/igb_main.c | 39 +++++++++---------- drivers/net/ethernet/intel/igbvf/netdev.c | 2 +- drivers/net/ethernet/intel/igc/igc_ethtool.c | 5 ++- drivers/net/ethernet/intel/igc/igc_main.c | 2 +- .../net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 4 +- 15 files changed, 58 insertions(+), 64 deletions(-)
Signature · 1 line
2.41.0
PATCH 1/9 intel: fix string truncation warnings
From: Jesse Brandeburg <[email protected]>
Fix -Wformat-truncated warnings to complete the intel directories' W=1 clean efforts. The W=1 recently got enhanced with a few new flags and this brought up some new warnings.
Switch to using kasprintf() when possible so we always allocate the right length strings.
summary of warnings:drivers/net/ethernet/intel/iavf/iavf_virtchnl.c:1425:60: warning: ‘%s’ directive output may be truncated writing 4 bytes into a region of size between 1 and 11 [-Wformat-truncation=] drivers/net/ethernet/intel/iavf/iavf_virtchnl.c:1425:17: note: ‘snprintf’ output between 7 and 17 bytes into a destination of size 13 drivers/net/ethernet/intel/ice/ice_ptp.c:43:27: warning: ‘%s’ directive output may be truncated writing up to 479 bytes into a region of size 64 [-Wformat-truncation=] drivers/net/ethernet/intel/ice/ice_ptp.c:42:17: note: ‘snprintf’ output between 1 and 480 bytes into a destination of size 64 drivers/net/ethernet/intel/igb/igb_main.c:3092:53: warning: ‘%d’ directive output may be truncated writing between 1 and 5 bytes into a region of size between 1 and 13 [-Wformat-truncation=] drivers/net/ethernet/intel/igb/igb_main.c:3092:34: note: directive argument in the range [0, 65535]drivers/net/ethernet/intel/igb/igb_main.c:3092:34: note: directive argument in the range [0, 65535]drivers/net/ethernet/intel/igb/igb_main.c:3090:25: note: ‘snprintf’ output between 23 and 43 bytes into a destination of size 32
--- .../net/ethernet/intel/iavf/iavf_ethtool.c | 4 +- .../net/ethernet/intel/iavf/iavf_virtchnl.c | 22 ++++------- drivers/net/ethernet/intel/ice/ice_ptp.c | 4 +- drivers/net/ethernet/intel/igb/igb_main.c | 37 +++++++++---------- 4 files changed, 30 insertions(+), 37 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_ethtool.c +2 -2
@@ -396,8 +396,8 @@ static void iavf_get_priv_flag_strings(struct net_device *netdev, u8 *data)unsigned int i;for (i =0 ; i <IAVF_PRIV_FLAGS_STR_LEN ; i++) { -snprintf (data,ETH_GSTRING_LEN ,"%s" , - iavf_gstrings_priv_flags[i].flag_string); +strscpy (data, iavf_gstrings_priv_flags[i].flag_string, +ETH_GSTRING_LEN ); data +=ETH_GSTRING_LEN ; } }
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +8 -14
@@ -1378,8 +1378,6 @@ void iavf_disable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid) VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2); } -#define IAVF_MAX_SPEED_STRLEN 13 -/** * iavf_print_link_message - print link up or down * @adapter: adapter structure
@@ -1397,10 +1395,6 @@ static void iavf_print_link_message(struct iavf_adapter *adapter)return ; } - speed =kzalloc (IAVF_MAX_SPEED_STRLEN ,GFP_KERNEL ); -if (!speed) -return ; -if (ADV_LINK_SUPPORT (adapter)) { link_speed_mbps = adapter->link_speed_mbps; goto print_link_msg;
@@ -1438,17 +1432,17 @@ static void iavf_print_link_message(struct iavf_adapter *adapter) print_link_msg:if (link_speed_mbps >SPEED_1000 ) { -if (link_speed_mbps ==SPEED_2500 ) -snprintf (speed,IAVF_MAX_SPEED_STRLEN ,"2.5 Gbps" ); -else +if (link_speed_mbps ==SPEED_2500 ) { + speed =kasprintf (GFP_KERNEL ,"%s" ,"2.5 Gbps" ); + }else {/* convert to Gbps inline */ -snprintf (speed,IAVF_MAX_SPEED_STRLEN ,"%d %s" , - link_speed_mbps /1000 ,"Gbps" ); + speed =kasprintf (GFP_KERNEL ,"%d Gbps" , + link_speed_mbps /1000 ); + } }else if (link_speed_mbps ==SPEED_UNKNOWN ) { -snprintf (speed,IAVF_MAX_SPEED_STRLEN ,"%s" ,"Unknown Mbps" ); + speed =kasprintf (GFP_KERNEL ,"%s" ,"Unknown Mbps" ); }else { -snprintf (speed,IAVF_MAX_SPEED_STRLEN ,"%d %s" , - link_speed_mbps,"Mbps" ); + speed =kasprintf (GFP_KERNEL ,"%d Mbps" , link_speed_mbps); }netdev_info (netdev,"NIC Link is Up Speed is %s Full Duplex\n" , speed);
drivers/net/ethernet/intel/ice/ice_ptp.c +2 -2
@@ -39,8 +39,8 @@ ice_get_sma_config_e810t(struct ice_hw *hw, struct ptp_pin_desc *ptp_pins)/* initialize with defaults */ for (i =0 ; i <NUM_PTP_PINS_E810T ; i++) { -snprintf (ptp_pins[i].name,sizeof (ptp_pins[i].name), -"%s" , ice_pin_desc_e810t[i].name); +strscpy (ptp_pins[i].name, ice_pin_desc_e810t[i].name, +sizeof (ptp_pins[i].name)); ptp_pins[i].index = ice_pin_desc_e810t[i].index; ptp_pins[i].func = ice_pin_desc_e810t[i].func; ptp_pins[i].chan = ice_pin_desc_e810t[i].chan;
drivers/net/ethernet/intel/igb/igb_main.c +18 -19
@@ -3069,6 +3069,7 @@ void igb_set_fw_version(struct igb_adapter *adapter) {struct e1000_hw *hw = &adapter->hw;struct e1000_fw_version fw; +char *lbuf;igb_get_fw_version (hw, &fw);
@@ -3076,36 +3077,34 @@ void igb_set_fw_version(struct igb_adapter *adapter)case e1000_i210:case e1000_i211:if (!(igb_get_flash_presence_i210 (hw))) { -snprintf (adapter->fw_version, -sizeof (adapter->fw_version), -"%2d.%2d-%d" , - fw.invm_major, fw.invm_minor, - fw.invm_img_type); + lbuf =kasprintf (GFP_KERNEL ,"%2d.%2d-%d" , + fw.invm_major, fw.invm_minor, + fw.invm_img_type);break ; } fallthrough;default : -/* if option is rom valid, display its version too */ +/* if option rom is valid, display its version too */ if (fw.or_valid) { -snprintf (adapter->fw_version, -sizeof (adapter->fw_version), -"%d.%d, 0x%08x, %d.%d.%d" , - fw.eep_major, fw.eep_minor, fw.etrack_id, - fw.or_major, fw.or_build, fw.or_patch); + lbuf =kasprintf (GFP_KERNEL ,"%d.%d, 0x%08x, %d.%d.%d" , + fw.eep_major, fw.eep_minor, + fw.etrack_id, fw.or_major, fw.or_build, + fw.or_patch);/* no option rom */ }else if (fw.etrack_id !=0X0000 ) { -snprintf (adapter->fw_version, -sizeof (adapter->fw_version), -"%d.%d, 0x%08x" , - fw.eep_major, fw.eep_minor, fw.etrack_id); + lbuf =kasprintf (GFP_KERNEL ,"%d.%d, 0x%08x" , + fw.eep_major, fw.eep_minor, + fw.etrack_id); }else { -snprintf (adapter->fw_version, -sizeof (adapter->fw_version), -"%d.%d.%d" , - fw.eep_major, fw.eep_minor, fw.eep_build); + lbuf =kasprintf (GFP_KERNEL ,"%d.%d.%d" , fw.eep_major, + fw.eep_minor, fw.eep_build); }break ; } + +/* the truncate happens here if it doesn't fit */ +strscpy (adapter->fw_version, lbuf,sizeof (adapter->fw_version)); +kfree (lbuf); }/**
Signature · 1 line
2.41.0
PATCH 2/9 intel: fix format warnings
In reply to Jacob KellerFrom: Jesse Brandeburg <[email protected]>
Get ahead of the game and fix all the -Wformat=2 noted warnings in the intel drivers directory.
There are one set of i40e and iavf warnings I couldn't figure out how to fix because the driver is already using vsnprintf without an explicit "const char *" format string.
Tested with both gcc-12 and clang-15. I found gcc-12 runs clean after this series but clang-15 is a little worried about the vsnprintf lines.
summary of warnings:
drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c:148:34: warning: format string is not a string literal [-Wformat-nonliteral] drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c:1416:24: warning: format string is not a string literal (potentially insecure) [-Wformat-security] drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c:1416:24: note: treat the string as an argument to avoid this drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c:1421:6: warning: format string is not a string literal (potentially insecure) [-Wformat-security] drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c:1421:6: note: treat the string as an argument to avoid this drivers/net/ethernet/intel/igc/igc_ethtool.c:776:24: warning: format string is not a string literal (potentially insecure) [-Wformat-security] drivers/net/ethernet/intel/igc/igc_ethtool.c:776:24: note: treat the string as an argument to avoid this drivers/net/ethernet/intel/igc/igc_ethtool.c:779:6: warning: format string is not a string literal (potentially insecure) [-Wformat-security] drivers/net/ethernet/intel/igc/igc_ethtool.c:779:6: note: treat the string as an argument to avoid this drivers/net/ethernet/intel/iavf/iavf_ethtool.c:199:34: warning: format string is not a string literal [-Wformat-nonliteral] drivers/net/ethernet/intel/igb/igb_ethtool.c:2360:6: warning: format string is not a string literal (potentially insecure) [-Wformat-security] drivers/net/ethernet/intel/igb/igb_ethtool.c:2360:6: note: treat the string as an argument to avoid this drivers/net/ethernet/intel/igb/igb_ethtool.c:2363:6: warning: format string is not a string literal (potentially insecure) [-Wformat-security] drivers/net/ethernet/intel/igb/igb_ethtool.c:2363:6: note: treat the string as an argument to avoid this drivers/net/ethernet/intel/i40e/i40e_ethtool.c:208:34: warning: format string is not a string literal [-Wformat-nonliteral] drivers/net/ethernet/intel/i40e/i40e_ethtool.c:2515:23: warning: format string is not a string literal (potentially insecure) [-Wformat-security] drivers/net/ethernet/intel/i40e/i40e_ethtool.c:2515:23: note: treat the string as an argument to avoid this drivers/net/ethernet/intel/i40e/i40e_ethtool.c:2519:23: warning: format string is not a string literal (potentially insecure) [-Wformat-security] drivers/net/ethernet/intel/i40e/i40e_ethtool.c:2519:23: note: treat the string as an argument to avoid this drivers/net/ethernet/intel/ice/ice_ethtool.c:1064:6: warning: format string is not a string literal (potentially insecure) [-Wformat-security] drivers/net/ethernet/intel/ice/ice_ethtool.c:1064:6: note: treat the string as an argument to avoid this drivers/net/ethernet/intel/ice/ice_ethtool.c:1084:6: warning: format string is not a string literal (potentially insecure) [-Wformat-security] drivers/net/ethernet/intel/ice/ice_ethtool.c:1084:6: note: treat the string as an argument to avoid this drivers/net/ethernet/intel/ice/ice_ethtool.c:1100:24: warning: format string is not a string literal (potentially insecure) [-Wformat-security] drivers/net/ethernet/intel/ice/ice_ethtool.c:1100:24: note: treat the string as an argument to avoid this
--- drivers/net/ethernet/intel/i40e/i40e_ethtool.c | 6 ++++-- drivers/net/ethernet/intel/iavf/iavf_ethtool.c | 8 +++----- drivers/net/ethernet/intel/ice/ice_ethtool.c | 7 ++++--- drivers/net/ethernet/intel/igb/igb_ethtool.c | 4 ++-- drivers/net/ethernet/intel/igc/igc_ethtool.c | 5 +++-- drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 4 ++-- 6 files changed, 18 insertions(+), 16 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_ethtool.c +4 -2
@@ -2514,11 +2514,13 @@ static void i40e_get_priv_flag_strings(struct net_device *netdev, u8 *data)u8 *p = data;for (i =0 ; i <I40E_PRIV_FLAGS_STR_LEN ; i++) -ethtool_sprintf (&p, i40e_gstrings_priv_flags[i].flag_string); +ethtool_sprintf (&p,"%s" , + i40e_gstrings_priv_flags[i].flag_string);if (pf->hw.pf_id !=0 )return ;for (i =0 ; i <I40E_GL_PRIV_FLAGS_STR_LEN ; i++) -ethtool_sprintf (&p, i40e_gl_gstrings_priv_flags[i].flag_string); +ethtool_sprintf (&p,"%s" , + i40e_gl_gstrings_priv_flags[i].flag_string); } static void i40e_get_strings(struct net_device *netdev, u32 stringset,
drivers/net/ethernet/intel/iavf/iavf_ethtool.c +3 -5
@@ -395,11 +395,9 @@ static void iavf_get_priv_flag_strings(struct net_device *netdev, u8 *data) {unsigned int i; -for (i =0 ; i <IAVF_PRIV_FLAGS_STR_LEN ; i++) { -strscpy (data, iavf_gstrings_priv_flags[i].flag_string, -ETH_GSTRING_LEN ); - data +=ETH_GSTRING_LEN ; - } +for (i =0 ; i <IAVF_PRIV_FLAGS_STR_LEN ; i++) +ethtool_sprintf (&data,"%s" , + iavf_gstrings_priv_flags[i].flag_string); }/**
drivers/net/ethernet/intel/ice/ice_ethtool.c +4 -3
@@ -1060,7 +1060,7 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,switch (stringset) {case ETH_SS_STATS :for (i =0 ; i <ICE_VSI_STATS_LEN ; i++) -ethtool_sprintf (&p, +ethtool_sprintf (&p,"%s" , ice_gstrings_vsi_stats[i].stat_string);if (ice_is_port_repr_netdev (netdev))
@@ -1080,7 +1080,7 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,return ;for (i =0 ; i <ICE_PF_STATS_LEN ; i++) -ethtool_sprintf (&p, +ethtool_sprintf (&p,"%s" , ice_gstrings_pf_stats[i].stat_string);for (i =0 ; i <ICE_MAX_USER_PRIORITY ; i++) {
@@ -1097,7 +1097,8 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,break ;case ETH_SS_PRIV_FLAGS :for (i =0 ; i <ICE_PRIV_FLAG_ARRAY_SIZE ; i++) -ethtool_sprintf (&p, ice_gstrings_priv_flags[i].name); +ethtool_sprintf (&p,"%s" , + ice_gstrings_priv_flags[i].name);break ;default :break ;
drivers/net/ethernet/intel/igb/igb_ethtool.c +2 -2
@@ -2356,10 +2356,10 @@ static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)break ;case ETH_SS_STATS :for (i =0 ; i <IGB_GLOBAL_STATS_LEN ; i++) -ethtool_sprintf (&p, +ethtool_sprintf (&p,"%s" , igb_gstrings_stats[i].stat_string);for (i =0 ; i <IGB_NETDEV_STATS_LEN ; i++) -ethtool_sprintf (&p, +ethtool_sprintf (&p,"%s" , igb_gstrings_net_stats[i].stat_string);for (i =0 ; i < adapter->num_tx_queues; i++) {ethtool_sprintf (&p,"tx_queue_%u_packets" , i);
drivers/net/ethernet/intel/igc/igc_ethtool.c +3 -2
@@ -773,9 +773,10 @@ static void igc_ethtool_get_strings(struct net_device *netdev, u32 stringset,break ;case ETH_SS_STATS :for (i =0 ; i <IGC_GLOBAL_STATS_LEN ; i++) -ethtool_sprintf (&p, igc_gstrings_stats[i].stat_string); +ethtool_sprintf (&p,"%s" , + igc_gstrings_stats[i].stat_string);for (i =0 ; i <IGC_NETDEV_STATS_LEN ; i++) -ethtool_sprintf (&p, +ethtool_sprintf (&p,"%s" , igc_gstrings_net_stats[i].stat_string);for (i =0 ; i < adapter->num_tx_queues; i++) {ethtool_sprintf (&p,"tx_queue_%u_packets" , i);
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c +2 -2
@@ -1413,11 +1413,11 @@ static void ixgbe_get_strings(struct net_device *netdev, u32 stringset,switch (stringset) {case ETH_SS_TEST :for (i =0 ; i <IXGBE_TEST_LEN ; i++) -ethtool_sprintf (&p, ixgbe_gstrings_test[i]); +ethtool_sprintf (&p,"%s" , ixgbe_gstrings_test[i]);break ;case ETH_SS_STATS :for (i =0 ; i <IXGBE_GLOBAL_STATS_LEN ; i++) -ethtool_sprintf (&p, +ethtool_sprintf (&p,"%s" , ixgbe_gstrings_stats[i].stat_string);for (i =0 ; i < netdev->num_tx_queues; i++) {ethtool_sprintf (&p,"tx_queue_%u_packets" , i);
Signature · 1 line
2.41.0
PATCH 3/9 e100: replace deprecated strncpy with strscpy
In reply to Jacob KellerFrom: Justin Stitt <[email protected]>
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 "...-1" pattern makes it evident that netdev->name is expected to be NUL-terminated.
Meanwhile, it seems NUL-padding is not required due to alloc_etherdev zero-allocating the buffer.
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.
This is in line with other uses of strscpy on netdev->name:
$ rg "strscpy\(netdev\->name.*pci.*"
drivers/net/ethernet/intel/e1000e/netdev.c
7455: strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
10839: strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
--- drivers/net/ethernet/intel/e100.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/e100.c +1 -1
@@ -2841,7 +2841,7 @@ static int e100_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netdev->netdev_ops = &e100_netdev_ops; netdev->ethtool_ops = &e100_ethtool_ops; netdev->watchdog_timeo =E100_WATCHDOG_PERIOD ; -strncpy (netdev->name,pci_name (pdev),sizeof (netdev->name) -1 ); +strscpy (netdev->name,pci_name (pdev),sizeof (netdev->name)); nic =netdev_priv (netdev);netif_napi_add_weight (netdev, &nic->napi, e100_poll,E100_NAPI_WEIGHT );
Signature · 1 line
2.41.0
PATCH 4/9 e1000: replace deprecated strncpy with strscpy
In reply to Jacob KellerFrom: Justin Stitt <[email protected]>
strncpy is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string interfaces.
We can see that netdev->name is expected to be NUL-terminated based on it's usage with format strings:
| pr_info("%s NIC Link is Down\n",
| netdev->name);
A suitable replacement is strscpy [2] due to the fact that it guarantees NUL-termination on the destination buffer without unnecessarily NUL-padding.
This is in line with other uses of strscpy on netdev->name:
$ rg "strscpy\(netdev\->name.*pci.*"
drivers/net/ethernet/intel/e1000e/netdev.c
7455: strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
10839: strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
--- drivers/net/ethernet/intel/e1000/e1000_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/e1000/e1000_main.c +1 -1
@@ -1014,7 +1014,7 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netdev->watchdog_timeo =5 *HZ ;netif_napi_add (netdev, &adapter->napi, e1000_clean); -strncpy (netdev->name,pci_name (pdev),sizeof (netdev->name) -1 ); +strscpy (netdev->name,pci_name (pdev),sizeof (netdev->name)); adapter->bd_number = cards_found;
Signature · 1 line
2.41.0
PATCH 5/9 fm10k: replace deprecated strncpy with strscpy
In reply to Jacob KellerFrom: Justin Stitt <[email protected]>
strncpy is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string interfaces.
A suitable replacement is strscpy [2] due to the fact that it guarantees NUL-termination on the destination buffer without unnecessarily NUL-padding.
Other implementations of .*get_drvinfo also use strscpy so this patch brings fm10k_get_drvinfo in line as well:
igb/igb_ethtool.c +851
static void igb_get_drvinfo(struct net_device *netdev,
igbvf/ethtool.c
167:static void igbvf_get_drvinfo(struct net_device *netdev,
i40e/i40e_ethtool.c
1999:static void i40e_get_drvinfo(struct net_device *netdev,
e1000/e1000_ethtool.c
529:static void e1000_get_drvinfo(struct net_device *netdev,
ixgbevf/ethtool.c
211:static void ixgbevf_get_drvinfo(struct net_device *netdev,
--- drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c +4 -4
@@ -448,10 +448,10 @@ static void fm10k_get_drvinfo(struct net_device *dev, {struct fm10k_intfc *interface =netdev_priv (dev); -strncpy (info->driver, fm10k_driver_name, -sizeof (info->driver) -1 ); -strncpy (info->bus_info,pci_name (interface->pdev), -sizeof (info->bus_info) -1 ); +strscpy (info->driver, fm10k_driver_name, +sizeof (info->driver)); +strscpy (info->bus_info,pci_name (interface->pdev), +sizeof (info->bus_info)); } static void fm10k_get_pauseparam(struct net_device *dev,
Signature · 1 line
2.41.0
PATCH 6/9 i40e: use scnprintf over strncpy+strncat
In reply to Jacob KellerFrom: Justin Stitt <[email protected]>
strncpy is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string interfaces.
Moreover, strncat shouldn't really be used either as per fortify-string.h:
* Do not use this function. While FORTIFY_SOURCE tries to avoid
* read and write overflows, this is only possible when the sizes
* of @p and @q are known to the compiler. Prefer building the
* string with formatting, via scnprintf() or similar.
Instead, use scnprintf with "%s%s" format string. This code is now more readable and robust.
--- drivers/net/ethernet/intel/i40e/i40e_ddp.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_ddp.c +3 -4
@@ -456,10 +456,9 @@ int i40e_ddp_flash(struct net_device *netdev, struct ethtool_flash *flash)char profile_name[sizeof (I40E_DDP_PROFILE_PATH ) +I40E_DDP_PROFILE_NAME_MAX ]; - profile_name[sizeof (profile_name) -1 ] =0 ; -strncpy (profile_name,I40E_DDP_PROFILE_PATH , -sizeof (profile_name) -1 ); -strncat (profile_name, flash->data,I40E_DDP_PROFILE_NAME_MAX ); +scnprintf (profile_name,sizeof (profile_name),"%s%s" , +I40E_DDP_PROFILE_PATH , flash->data); +/* Load DDP recipe. */ status =request_firmware (&ddp_config, profile_name, &netdev->dev);
Signature · 1 line
2.41.0
PATCH 7/9 igb: replace deprecated strncpy with strscpy
In reply to Jacob KellerFrom: Justin Stitt <[email protected]>
strncpy is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string interfaces.
We see that netdev->name is expected to be NUL-terminated based on its usage with format strings:
| sprintf(q_vector->name, "%s-TxRx-%u", netdev->name,
| q_vector->rx.ring->queue_index);
Furthermore, NUL-padding is not required as netdev is already zero-allocated:
| netdev = alloc_etherdev_mq(sizeof(struct igb_adapter),
| IGB_MAX_TX_QUEUES);
...alloc_etherdev_mq() -> alloc_etherdev_mqs() -> alloc_netdev_mqs() ...
| p = kvzalloc(alloc_size, GFP_KERNEL_ACCOUNT | __GFP_RETRY_MAYFAIL);
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.
--- drivers/net/ethernet/intel/igb/igb_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/igb/igb_main.c +1 -1
@@ -3263,7 +3263,7 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)igb_set_ethtool_ops (netdev); netdev->watchdog_timeo =5 *HZ ; -strncpy (netdev->name,pci_name (pdev),sizeof (netdev->name) -1 ); +strscpy (netdev->name,pci_name (pdev),sizeof (netdev->name)); netdev->mem_start =pci_resource_start (pdev,0 ); netdev->mem_end =pci_resource_end (pdev,0 );
Signature · 1 line
2.41.0
PATCH 8/9 igbvf: replace deprecated strncpy with strscpy
In reply to Jacob KellerFrom: Justin Stitt <[email protected]>
strncpy is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string interfaces.
We expect netdev->name to be NUL-terminated based on its usage with strlen and format strings:
| if (strlen(netdev->name) < (IFNAMSIZ - 5)) {
| sprintf(adapter->tx_ring->name, "%s-tx-0", netdev->name);
Moreover, we do not need NUL-padding as netdev is already zero-allocated:
| netdev = alloc_etherdev(sizeof(struct igbvf_adapter));
...alloc_etherdev() -> alloc_etherdev_mq() -> alloc_etherdev_mqs() -> alloc_netdev_mqs() ...
| p = kvzalloc(alloc_size, GFP_KERNEL_ACCOUNT | __GFP_RETRY_MAYFAIL);
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.
--- drivers/net/ethernet/intel/igbvf/netdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/igbvf/netdev.c +1 -1
@@ -2785,7 +2785,7 @@ static int igbvf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)igbvf_set_ethtool_ops (netdev); netdev->watchdog_timeo =5 *HZ ; -strncpy (netdev->name,pci_name (pdev),sizeof (netdev->name) -1 ); +strscpy (netdev->name,pci_name (pdev),sizeof (netdev->name)); adapter->bd_number = cards_found++;
Signature · 1 line
2.41.0
PATCH 9/9 igc: replace deprecated strncpy with strscpy
In reply to Jacob KellerFrom: Justin Stitt <[email protected]>
strncpy is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string interfaces.
We expect netdev->name to be NUL-terminated based on its use with format strings:
| if (q_vector->rx.ring && q_vector->tx.ring)
| sprintf(q_vector->name, "%s-TxRx-%u", netdev->name,
Furthermore, we do not need NUL-padding as netdev is already zero-allocated:
| netdev = alloc_etherdev_mq(sizeof(struct igc_adapter),
| IGC_MAX_TX_QUEUES);
...alloc_etherdev() -> alloc_etherdev_mq() -> alloc_etherdev_mqs() -> alloc_netdev_mqs() ...
| p = kvzalloc(alloc_size, GFP_KERNEL_ACCOUNT | __GFP_RETRY_MAYFAIL);
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.
--- drivers/net/ethernet/intel/igc/igc_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/igc/igc_main.c +1 -1
@@ -6935,7 +6935,7 @@ static int igc_probe(struct pci_dev *pdev,*/ igc_get_hw_control (adapter); -strncpy (netdev->name,"eth%d" ,IFNAMSIZ ); +strscpy (netdev->name,"eth%d" ,sizeof (netdev->name)); err =register_netdev (netdev);if (err) goto err_register;
Signature · 1 line
2.41.0
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Tue, 17 Oct 2023 12:04:02 -0700 you wrote:
This series contains cleanups for all the Intel drivers relating to their use of format specifiers and the use of strncpy.
Jesse fixes various -Wformat warnings across all the Intel networking, including various cases where a "%s" string format specifier is preferred, and using kasprintf instead of snprintf.
[...]
Here is the summary with links:
- [net-next,1/9] intel: fix string truncation warnings
https://git.kernel.org/netdev/net-next/c/1978d3ead82c - [net-next,2/9] intel: fix format warnings https://git.kernel.org/netdev/net-next/c/d97af2440a0c - [net-next,3/9] e100: replace deprecated strncpy with strscpy https://git.kernel.org/netdev/net-next/c/7677f635bf80 - [net-next,4/9] e1000: replace deprecated strncpy with strscpy https://git.kernel.org/netdev/net-next/c/341359e034e4 - [net-next,5/9] fm10k: replace deprecated strncpy with strscpy https://git.kernel.org/netdev/net-next/c/48b238461b90 - [net-next,6/9] i40e: use scnprintf over strncpy+strncat https://git.kernel.org/netdev/net-next/c/be39d0a61aed - [net-next,7/9] igb: replace deprecated strncpy with strscpy https://git.kernel.org/netdev/net-next/c/95e71e35e635 - [net-next,8/9] igbvf: replace deprecated strncpy with strscpy https://git.kernel.org/netdev/net-next/c/a6c78d5f8d5d - [net-next,9/9] igc: replace deprecated strncpy with strscpy https://git.kernel.org/netdev/net-next/c/d10d64ad01db
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html