net/tap: resolve stringop-overflow with gcc 12 on ppc64le

Message ID 20230322212439.524725-1-drc@linux.vnet.ibm.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series net/tap: resolve stringop-overflow with gcc 12 on ppc64le |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-abi-testing success Testing PASS
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-unit-testing success Testing PASS

Commit Message

David Christensen March 22, 2023, 9:24 p.m. UTC
  Building DPDK with gcc 12 on a ppc64le system generates a
stringop-overflow warning. Replace the local MAC address
validation function parse_user_mac() with a call to
rte_ether_unformat_addr() instead.

Bugzilla ID: 1197
Cc: stable@dpdk.org

Signed-off-by: David Christensen <drc@linux.vnet.ibm.com>
---
 drivers/net/tap/rte_eth_tap.c | 25 +------------------------
 1 file changed, 1 insertion(+), 24 deletions(-)
  

Comments

Stephen Hemminger March 22, 2023, 11:43 p.m. UTC | #1
On Wed, 22 Mar 2023 17:24:39 -0400
David Christensen <drc@linux.vnet.ibm.com> wrote:

> Building DPDK with gcc 12 on a ppc64le system generates a
> stringop-overflow warning. Replace the local MAC address
> validation function parse_user_mac() with a call to
> rte_ether_unformat_addr() instead.
> 
> Bugzilla ID: 1197
> Cc: stable@dpdk.org
> 
> Signed-off-by: David Christensen <drc@linux.vnet.ibm.com>
> ---
>  drivers/net/tap/rte_eth_tap.c | 25 +------------------------
>  1 file changed, 1 insertion(+), 24 deletions(-)
> 
> diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
> index 089ac202fa..1f83f49c0e 100644
> --- a/drivers/net/tap/rte_eth_tap.c
> +++ b/drivers/net/tap/rte_eth_tap.c
> @@ -2267,29 +2267,6 @@ set_remote_iface(const char *key __rte_unused,
>  	return 0;
>  }
>  
> -static int parse_user_mac(struct rte_ether_addr *user_mac,
> -		const char *value)
> -{
> -	unsigned int index = 0;
> -	char mac_temp[strlen(ETH_TAP_USR_MAC_FMT) + 1], *mac_byte = NULL;
> -
> -	if (user_mac == NULL || value == NULL)
> -		return 0;
> -
> -	strlcpy(mac_temp, value, sizeof(mac_temp));
> -	mac_byte = strtok(mac_temp, ":");
> -
> -	while ((mac_byte != NULL) &&
> -			(strlen(mac_byte) <= 2) &&
> -			(strlen(mac_byte) == strspn(mac_byte,
> -					ETH_TAP_CMP_MAC_FMT))) {
> -		user_mac->addr_bytes[index++] = strtoul(mac_byte, NULL, 16);
> -		mac_byte = strtok(NULL, ":");
> -	}
> -
> -	return index;
> -}
> -
>  static int
>  set_mac_type(const char *key __rte_unused,
>  	     const char *value,
> @@ -2311,7 +2288,7 @@ set_mac_type(const char *key __rte_unused,
>  		goto success;
>  	}
>  
> -	if (parse_user_mac(user_mac, value) != 6)
> +	if (rte_ether_unformat_addr(value, user_mac) < 0)
>  		goto error;
>  success:
>  	TAP_LOG(DEBUG, "TAP user MAC param (%s)", value);

There might still be case where user_mac == NULL since it comes
from extra_args.

Also, this code has this suspicious code:

	if (!strncasecmp(ETH_TAP_MAC_FIXED, value, strlen(ETH_TAP_MAC_FIXED))) {
		static int iface_idx;

		/* fixed mac = 00:64:74:61:70:<iface_idx> */
		memcpy((char *)user_mac->addr_bytes, "\0dtap",
			RTE_ETHER_ADDR_LEN);
		user_mac->addr_bytes[RTE_ETHER_ADDR_LEN - 1] =
			iface_idx++ + '0';
		goto success;
	}

The OUI for that MAC address is not registered but it might be someday.
Choosing magic constants in IANA assigned space is not best practice.
Unless some vendor wants to spend lots of time registering these.

Better to use locally assigned value.  See RFC7042 for more details.
  
David Christensen March 23, 2023, 4:45 p.m. UTC | #2
On 3/22/23 4:43 PM, Stephen Hemminger wrote:
>>   static int
>>   set_mac_type(const char *key __rte_unused,
>>   	     const char *value,
>> @@ -2311,7 +2288,7 @@ set_mac_type(const char *key __rte_unused,
>>   		goto success;
>>   	}
>>   
>> -	if (parse_user_mac(user_mac, value) != 6)
>> +	if (rte_ether_unformat_addr(value, user_mac) < 0)
>>   		goto error;
>>   success:
>>   	TAP_LOG(DEBUG, "TAP user MAC param (%s)", value);
> 
> There might still be case where user_mac == NULL since it comes
> from extra_args.

Ok, I'll fix in v2.

> Also, this code has this suspicious code:
> 
> 	if (!strncasecmp(ETH_TAP_MAC_FIXED, value, strlen(ETH_TAP_MAC_FIXED))) {
> 		static int iface_idx;
> 
> 		/* fixed mac = 00:64:74:61:70:<iface_idx> */
> 		memcpy((char *)user_mac->addr_bytes, "\0dtap",
> 			RTE_ETHER_ADDR_LEN);
> 		user_mac->addr_bytes[RTE_ETHER_ADDR_LEN - 1] =
> 			iface_idx++ + '0';
> 		goto success;
> 	}
> 
> The OUI for that MAC address is not registered but it might be someday.
> Choosing magic constants in IANA assigned space is not best practice.
> Unless some vendor wants to spend lots of time registering these.
> 
> Better to use locally assigned value.  See RFC7042 for more details.

I think that's out of scope for this issue.  Opened a DPDK Bugzilla to 
document the concern which changes "\0dtap" to "\002dtap" to set the 
local bit as required by the RFC.  I'll send out the patch for code and 
documentation after 23.03 is released.

Dave
  

Patch

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 089ac202fa..1f83f49c0e 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -2267,29 +2267,6 @@  set_remote_iface(const char *key __rte_unused,
 	return 0;
 }
 
-static int parse_user_mac(struct rte_ether_addr *user_mac,
-		const char *value)
-{
-	unsigned int index = 0;
-	char mac_temp[strlen(ETH_TAP_USR_MAC_FMT) + 1], *mac_byte = NULL;
-
-	if (user_mac == NULL || value == NULL)
-		return 0;
-
-	strlcpy(mac_temp, value, sizeof(mac_temp));
-	mac_byte = strtok(mac_temp, ":");
-
-	while ((mac_byte != NULL) &&
-			(strlen(mac_byte) <= 2) &&
-			(strlen(mac_byte) == strspn(mac_byte,
-					ETH_TAP_CMP_MAC_FMT))) {
-		user_mac->addr_bytes[index++] = strtoul(mac_byte, NULL, 16);
-		mac_byte = strtok(NULL, ":");
-	}
-
-	return index;
-}
-
 static int
 set_mac_type(const char *key __rte_unused,
 	     const char *value,
@@ -2311,7 +2288,7 @@  set_mac_type(const char *key __rte_unused,
 		goto success;
 	}
 
-	if (parse_user_mac(user_mac, value) != 6)
+	if (rte_ether_unformat_addr(value, user_mac) < 0)
 		goto error;
 success:
 	TAP_LOG(DEBUG, "TAP user MAC param (%s)", value);