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

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

Checks

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

Commit Message

David Christensen March 23, 2023, 5:01 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>
---
v2:
* Added NULL checks previously performed in parse_user_mac()
---
 drivers/net/tap/rte_eth_tap.c | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)
  

Comments

Ferruh Yigit May 15, 2023, 11:14 p.m. UTC | #1
On 3/23/2023 5:01 PM, David Christensen 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>
> ---
> v2:
> * Added NULL checks previously performed in parse_user_mac()
> ---
>  drivers/net/tap/rte_eth_tap.c | 26 ++------------------------
>  1 file changed, 2 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
> index 089ac202fa..8c50801fd4 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,8 @@ set_mac_type(const char *key __rte_unused,
>  		goto success;
>  	}
>  
> -	if (parse_user_mac(user_mac, value) != 6)
> +	if (value == NULL || user_mac == NULL ||
> +			rte_ether_unformat_addr(value, user_mac) < 0)
>  		goto error;
>  success:
>  	TAP_LOG(DEBUG, "TAP user MAC param (%s)", value);

Hi David,

I confirm the build error, btw it helps to future references to put
build failure to the commit log,

and change is reasonable to convert PMD local parse function to an API,
BUT my concern is they don't behave exactly same, which changes user
interface of the driver.

The 'rte_ether_unformat_addr()' API expects exact "XX:XX:XX:XX:XX:XX or
XXXX:XXXX:XXXX" format.
Like 'parse_user_mac()' accepts 'a:a:a:a:a:a' as input, but API requires
'0A:0A:0A:0A:0A:0A'.

This is a small change but still may create a bad experience if an
existing user/script hit by this, and I believe we don't have a strong
reason to change the interface.


To keep behavior same, we can either update 'rte_ether_unformat_addr()'
to accept singe chars between ':',
or fix the existing 'parse_user_mac()' for compiler warning, what do you
think?
  
Stephen Hemminger May 15, 2023, 11:20 p.m. UTC | #2
On Tue, 16 May 2023 00:14:52 +0100
Ferruh Yigit <ferruh.yigit@amd.com> wrote:

> Hi David,
> 
> I confirm the build error, btw it helps to future references to put
> build failure to the commit log,
> 
> and change is reasonable to convert PMD local parse function to an API,
> BUT my concern is they don't behave exactly same, which changes user
> interface of the driver.
> 
> The 'rte_ether_unformat_addr()' API expects exact "XX:XX:XX:XX:XX:XX or
> XXXX:XXXX:XXXX" format.
> Like 'parse_user_mac()' accepts 'a:a:a:a:a:a' as input, but API requires
> '0A:0A:0A:0A:0A:0A'.
> 
> This is a small change but still may create a bad experience if an
> existing user/script hit by this, and I believe we don't have a strong
> reason to change the interface.
> 
> 
> To keep behavior same, we can either update 'rte_ether_unformat_addr()'
> to accept singe chars between ':',
> or fix the existing 'parse_user_mac()' for compiler warning, what do you
> think?

This is the kind of change where a simple release note will suffice.

Not sure if anyone beyond some test script would ever use this anyway.
  
Ferruh Yigit May 15, 2023, 11:35 p.m. UTC | #3
On 5/16/2023 12:20 AM, Stephen Hemminger wrote:
> On Tue, 16 May 2023 00:14:52 +0100
> Ferruh Yigit <ferruh.yigit@amd.com> wrote:
> 
>> Hi David,
>>
>> I confirm the build error, btw it helps to future references to put
>> build failure to the commit log,
>>
>> and change is reasonable to convert PMD local parse function to an API,
>> BUT my concern is they don't behave exactly same, which changes user
>> interface of the driver.
>>
>> The 'rte_ether_unformat_addr()' API expects exact "XX:XX:XX:XX:XX:XX or
>> XXXX:XXXX:XXXX" format.
>> Like 'parse_user_mac()' accepts 'a:a:a:a:a:a' as input, but API requires
>> '0A:0A:0A:0A:0A:0A'.
>>
>> This is a small change but still may create a bad experience if an
>> existing user/script hit by this, and I believe we don't have a strong
>> reason to change the interface.
>>
>>
>> To keep behavior same, we can either update 'rte_ether_unformat_addr()'
>> to accept singe chars between ':',
>> or fix the existing 'parse_user_mac()' for compiler warning, what do you
>> think?
> 
> This is the kind of change where a simple release note will suffice.
> 
> Not sure if anyone beyond some test script would ever use this anyway.


Yes only some scripts and possible applications that hotplug tap
interface with hardcoded parameters may impacted, don't know how big is
this amount but this ends up breaking something that was working before
upgrading DPDK for them.

And I believe the motivation is weak to break the behavior.

Won't it be better to update 'rte_ether_unformat_addr()' to accept more
flexible syntax, and use it? Is there any disadvantage of this approach?
  
Stephen Hemminger May 16, 2023, 1:28 a.m. UTC | #4
On Tue, 16 May 2023 00:35:56 +0100
Ferruh Yigit <ferruh.yigit@amd.com> wrote:

> Yes only some scripts and possible applications that hotplug tap
> interface with hardcoded parameters may impacted, don't know how big is
> this amount but this ends up breaking something that was working before
> upgrading DPDK for them.
> 
> And I believe the motivation is weak to break the behavior.
> 
> Won't it be better to update 'rte_ether_unformat_addr()' to accept more
> flexible syntax, and use it? Is there any disadvantage of this approach?

It is already more flexible than the standard ether_aton().
  
Ferruh Yigit May 16, 2023, 9:55 a.m. UTC | #5
On 5/16/2023 2:28 AM, Stephen Hemminger wrote:
> On Tue, 16 May 2023 00:35:56 +0100
> Ferruh Yigit <ferruh.yigit@amd.com> wrote:
> 
>> Yes only some scripts and possible applications that hotplug tap
>> interface with hardcoded parameters may impacted, don't know how big is
>> this amount but this ends up breaking something that was working before
>> upgrading DPDK for them.
>>
>> And I believe the motivation is weak to break the behavior.
>>
>> Won't it be better to update 'rte_ether_unformat_addr()' to accept more
>> flexible syntax, and use it? Is there any disadvantage of this approach?
> 
> It is already more flexible than the standard ether_aton().

I mean to accept single chars, as 'tap' currently does, like "a:a:a:a:a:a".

Agree that impact of tap change is small, but if we can eliminate it
completely without any side affect, why not?


As accepting single char will be expanding 'rte_ether_unformat_addr()'
capability, it will be backward compatible, am I missing anything?
  
Ferruh Yigit June 7, 2023, 6:47 p.m. UTC | #6
On 5/16/2023 10:55 AM, Ferruh Yigit wrote:
> On 5/16/2023 2:28 AM, Stephen Hemminger wrote:
>> On Tue, 16 May 2023 00:35:56 +0100
>> Ferruh Yigit <ferruh.yigit@amd.com> wrote:
>>
>>> Yes only some scripts and possible applications that hotplug tap
>>> interface with hardcoded parameters may impacted, don't know how big is
>>> this amount but this ends up breaking something that was working before
>>> upgrading DPDK for them.
>>>
>>> And I believe the motivation is weak to break the behavior.
>>>
>>> Won't it be better to update 'rte_ether_unformat_addr()' to accept more
>>> flexible syntax, and use it? Is there any disadvantage of this approach?
>>
>> It is already more flexible than the standard ether_aton().
> 
> I mean to accept single chars, as 'tap' currently does, like "a:a:a:a:a:a".
> 
> Agree that impact of tap change is small, but if we can eliminate it
> completely without any side affect, why not?
> 
> 
> As accepting single char will be expanding 'rte_ether_unformat_addr()'
> capability, it will be backward compatible, am I missing anything?
> 

Hi David,

If API update is not planned, what do you think to just solve the build
error without changing functionality with a change something like below:

```
 -       (strlen(mac_byte) == strspn(mac_byte,
 -                       ETH_TAP_CMP_MAC_FMT))) {
 +       (strlen(mac_byte) == strspn(mac_byte, ETH_TAP_CMP_MAC_FMT)) &&
 +                       index < RTE_ETHER_ADDR_LEN) {

```
  
Stephen Hemminger June 8, 2023, 2:02 a.m. UTC | #7
On Wed, 7 Jun 2023 19:47:04 +0100
Ferruh Yigit <ferruh.yigit@amd.com> wrote:

> On 5/16/2023 10:55 AM, Ferruh Yigit wrote:
> > On 5/16/2023 2:28 AM, Stephen Hemminger wrote:  
> >> On Tue, 16 May 2023 00:35:56 +0100
> >> Ferruh Yigit <ferruh.yigit@amd.com> wrote:
> >>  
> >>> Yes only some scripts and possible applications that hotplug tap
> >>> interface with hardcoded parameters may impacted, don't know how big is
> >>> this amount but this ends up breaking something that was working before
> >>> upgrading DPDK for them.
> >>>
> >>> And I believe the motivation is weak to break the behavior.
> >>>
> >>> Won't it be better to update 'rte_ether_unformat_addr()' to accept more
> >>> flexible syntax, and use it? Is there any disadvantage of this approach?  
> >>
> >> It is already more flexible than the standard ether_aton().  
> > 
> > I mean to accept single chars, as 'tap' currently does, like "a:a:a:a:a:a".
> > 
> > Agree that impact of tap change is small, but if we can eliminate it
> > completely without any side affect, why not?
> > 
> > 
> > As accepting single char will be expanding 'rte_ether_unformat_addr()'
> > capability, it will be backward compatible, am I missing anything?

I did a little poking around. The single character format is actually non
standard.  It would be good to extend rte_unformat_ether_addr to allow a wider
range of formats including all those used by Windows, IEEE, and network vendors.
  
Ferruh Yigit Sept. 29, 2023, 1:48 p.m. UTC | #8
On 6/7/2023 7:47 PM, Ferruh Yigit wrote:
> On 5/16/2023 10:55 AM, Ferruh Yigit wrote:
>> On 5/16/2023 2:28 AM, Stephen Hemminger wrote:
>>> On Tue, 16 May 2023 00:35:56 +0100
>>> Ferruh Yigit <ferruh.yigit@amd.com> wrote:
>>>
>>>> Yes only some scripts and possible applications that hotplug tap
>>>> interface with hardcoded parameters may impacted, don't know how big is
>>>> this amount but this ends up breaking something that was working before
>>>> upgrading DPDK for them.
>>>>
>>>> And I believe the motivation is weak to break the behavior.
>>>>
>>>> Won't it be better to update 'rte_ether_unformat_addr()' to accept more
>>>> flexible syntax, and use it? Is there any disadvantage of this approach?
>>>
>>> It is already more flexible than the standard ether_aton().
>>
>> I mean to accept single chars, as 'tap' currently does, like "a:a:a:a:a:a".
>>
>> Agree that impact of tap change is small, but if we can eliminate it
>> completely without any side affect, why not?
>>
>>
>> As accepting single char will be expanding 'rte_ether_unformat_addr()'
>> capability, it will be backward compatible, am I missing anything?
>>
> 
> Hi David,
> 
> If API update is not planned, what do you think to just solve the build
> error without changing functionality with a change something like below:
> 
> ```
>  -       (strlen(mac_byte) == strspn(mac_byte,
>  -                       ETH_TAP_CMP_MAC_FMT))) {
>  +       (strlen(mac_byte) == strspn(mac_byte, ETH_TAP_CMP_MAC_FMT)) &&
>  +                       index < RTE_ETHER_ADDR_LEN) {
> 
> ```

Hi David,

If you can confirm above fixes the issue, I can send a patch for it.
  
David Christensen Oct. 6, 2023, 6:31 p.m. UTC | #9
On 9/29/23 6:48 AM, Ferruh Yigit wrote:
> On 6/7/2023 7:47 PM, Ferruh Yigit wrote:
>> On 5/16/2023 10:55 AM, Ferruh Yigit wrote:
>>> On 5/16/2023 2:28 AM, Stephen Hemminger wrote:
>>>> On Tue, 16 May 2023 00:35:56 +0100
>>>> Ferruh Yigit <ferruh.yigit@amd.com> wrote:
>>>>
>>>>> Yes only some scripts and possible applications that hotplug tap
>>>>> interface with hardcoded parameters may impacted, don't know how big is
>>>>> this amount but this ends up breaking something that was working before
>>>>> upgrading DPDK for them.
>>>>>
>>>>> And I believe the motivation is weak to break the behavior.
>>>>>
>>>>> Won't it be better to update 'rte_ether_unformat_addr()' to accept more
>>>>> flexible syntax, and use it? Is there any disadvantage of this approach?
>>>>
>>>> It is already more flexible than the standard ether_aton().
>>>
>>> I mean to accept single chars, as 'tap' currently does, like "a:a:a:a:a:a".
>>>
>>> Agree that impact of tap change is small, but if we can eliminate it
>>> completely without any side affect, why not?
>>>
>>>
>>> As accepting single char will be expanding 'rte_ether_unformat_addr()'
>>> capability, it will be backward compatible, am I missing anything?
>>>
>>
>> Hi David,
>>
>> If API update is not planned, what do you think to just solve the build
>> error without changing functionality with a change something like below:
>>
>> ```
>>   -       (strlen(mac_byte) == strspn(mac_byte,
>>   -                       ETH_TAP_CMP_MAC_FMT))) {
>>   +       (strlen(mac_byte) == strspn(mac_byte, ETH_TAP_CMP_MAC_FMT)) &&
>>   +                       index < RTE_ETHER_ADDR_LEN) {
>>
>> ```
> 
> Hi David,
> 
> If you can confirm above fixes the issue, I can send a patch for it.

Confirmed that your proposed change resolves the build issue on ppc64le. 
  Appreciate if you can submit the patch.

Dave
  
Ferruh Yigit Oct. 9, 2023, 9:17 a.m. UTC | #10
On 10/6/2023 7:31 PM, David Christensen wrote:
> 
> 
> On 9/29/23 6:48 AM, Ferruh Yigit wrote:
>> On 6/7/2023 7:47 PM, Ferruh Yigit wrote:
>>> On 5/16/2023 10:55 AM, Ferruh Yigit wrote:
>>>> On 5/16/2023 2:28 AM, Stephen Hemminger wrote:
>>>>> On Tue, 16 May 2023 00:35:56 +0100
>>>>> Ferruh Yigit <ferruh.yigit@amd.com> wrote:
>>>>>
>>>>>> Yes only some scripts and possible applications that hotplug tap
>>>>>> interface with hardcoded parameters may impacted, don't know how
>>>>>> big is
>>>>>> this amount but this ends up breaking something that was working
>>>>>> before
>>>>>> upgrading DPDK for them.
>>>>>>
>>>>>> And I believe the motivation is weak to break the behavior.
>>>>>>
>>>>>> Won't it be better to update 'rte_ether_unformat_addr()' to accept
>>>>>> more
>>>>>> flexible syntax, and use it? Is there any disadvantage of this
>>>>>> approach?
>>>>>
>>>>> It is already more flexible than the standard ether_aton().
>>>>
>>>> I mean to accept single chars, as 'tap' currently does, like
>>>> "a:a:a:a:a:a".
>>>>
>>>> Agree that impact of tap change is small, but if we can eliminate it
>>>> completely without any side affect, why not?
>>>>
>>>>
>>>> As accepting single char will be expanding 'rte_ether_unformat_addr()'
>>>> capability, it will be backward compatible, am I missing anything?
>>>>
>>>
>>> Hi David,
>>>
>>> If API update is not planned, what do you think to just solve the build
>>> error without changing functionality with a change something like below:
>>>
>>> ```
>>>   -       (strlen(mac_byte) == strspn(mac_byte,
>>>   -                       ETH_TAP_CMP_MAC_FMT))) {
>>>   +       (strlen(mac_byte) == strspn(mac_byte, ETH_TAP_CMP_MAC_FMT)) &&
>>>   +                       index < RTE_ETHER_ADDR_LEN) {
>>>
>>> ```
>>
>> Hi David,
>>
>> If you can confirm above fixes the issue, I can send a patch for it.
> 
> Confirmed that your proposed change resolves the build issue on ppc64le.
>  Appreciate if you can submit the patch.
> 
> 

Thanks for checking, but Stephen updated the 'rte_ether_unformat_addr()'
API [1] and sent a new version of this patch [2], which is merged in
next-net [3] now.
Build error for PPC should be fixed now.


[1]
https://patchwork.dpdk.org/project/dpdk/patch/20231003202909.391330-3-stephen@networkplumber.org/

[2]
https://patchwork.dpdk.org/project/dpdk/patch/20231003202909.391330-5-stephen@networkplumber.org/

[3]
https://git.dpdk.org/next/dpdk-next-net/log/
  

Patch

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 089ac202fa..8c50801fd4 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,8 @@  set_mac_type(const char *key __rte_unused,
 		goto success;
 	}
 
-	if (parse_user_mac(user_mac, value) != 6)
+	if (value == NULL || user_mac == NULL ||
+			rte_ether_unformat_addr(value, user_mac) < 0)
 		goto error;
 success:
 	TAP_LOG(DEBUG, "TAP user MAC param (%s)", value);