net/tap: resolve stringop-overflow with gcc 12 on ppc64le
PATCH 1/1 net/tap: resolve stringop-overflow with gcc 12 on ppc64le
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: [email protected]
--- drivers/net/tap/rte_eth_tap.c | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-)
drivers/net/tap/rte_eth_tap.c +1 -24
@@ -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);
Signature · 1 line
2.31.1
Quoted 48 lines · On Wed, 22 Mar 2023 17:24:39 -0400 David Christensen <[email protected]>…
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 torte_ether_unformat_addr()instead.Bugzilla ID: 1197
Cc: [email protected]Signed-off-by David Christensen <[email protected]>--- drivers/net/tap/rte_eth_tap.c | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-)drivers/net/tap/rte_eth_tap.c +0
-23@@ -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,
drivers/net/tap/rte_eth_tap.c set_mac_type(const char *key __rte_unused, · line 2294
Quoted 8 lines
drivers/net/tap/rte_eth_tap.c +1
-1@@ -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.
Quoted 7 lines · Stephen Hemminger
Quoted 7 lines
static int
set_mac_type(const char *key__rte_unused,
const char *value,drivers/net/tap/rte_eth_tap.c +0
-0@@ -2311,7 +2288,7 @@ set_mac_type(const char *key __rte_unused, goto success; }
Quoted 8 lines
drivers/net/tap/rte_eth_tap.c set_mac_type(const char *key __rte_unused, · line 2294
Quoted 5 lines
drivers/net/tap/rte_eth_tap.c +1
-1-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 fromextra_args.
Ok, I'll fix in v2.
Quoted 13 lines
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; }
Quoted 5 lines
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 v2 1/1 net/tap: resolve stringop-overflow with gcc 12 on ppc64le
In reply to David ChristensenBuilding 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: [email protected]
---
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(-)
drivers/net/tap/rte_eth_tap.c +2 -24
@@ -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);
Signature · 1 line
2.31.1
Quoted 51 lines · David Christensen
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 torte_ether_unformat_addr()instead.Bugzilla ID: 1197
Cc: [email protected]Signed-off-by David Christensen <[email protected]>---
v2:
* Added NULL checks previously performed inparse_user_mac()--- drivers/net/tap/rte_eth_tap.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-)drivers/net/tap/rte_eth_tap.c +0
-23@@ -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,
drivers/net/tap/rte_eth_tap.c set_mac_type(const char *key __rte_unused, · line 2295
Quoted 9 lines
drivers/net/tap/rte_eth_tap.c +2
-1@@ -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?
Quoted 19 lines · On Tue, 16 May 2023 00:14:52 +0100 Ferruh Yigit <[email protected]> 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.
Quoted 4 lines
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.
Quoted 22 lines · Stephen Hemminger
Quoted 19 lines · On Tue, 16 May 2023 00:14:52 +0100 Ferruh Yigit <[email protected]> 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.
Quoted 8 lines
Quoted 4 lines
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?
Quoted 9 lines · On Tue, 16 May 2023 00:35:56 +0100 Ferruh Yigit <[email protected]> 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().
Quoted 8 lines · Stephen Hemminger
Quoted 5 lines · On Tue, 16 May 2023 00:35:56 +0100 Ferruh Yigit <[email protected]> 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.
Quoted 6 lines
Quoted 4 lines
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?
Quoted 16 lines · Ferruh Yigit
Quoted 8 lines · Stephen Hemminger
Quoted 5 lines · On Tue, 16 May 2023 00:35:56 +0100 Ferruh Yigit <[email protected]> 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.
Quoted 6 lines
Quoted 4 lines
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().
Quoted 9 lines
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) {
```Quoted 17 lines · On Wed, 7 Jun 2023 19:47:04 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 16 lines · Ferruh Yigit
Quoted 14 lines · Stephen Hemminger
Quoted 9 lines · On Tue, 16 May 2023 00:35:56 +0100 Ferruh Yigit <[email protected]> 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().
Quoted 8 lines
Quoted 8 lines
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.
Quoted 32 lines · Ferruh Yigit
Quoted 16 lines · Ferruh Yigit
Quoted 8 lines · Stephen Hemminger
Quoted 5 lines · On Tue, 16 May 2023 00:35:56 +0100 Ferruh Yigit <[email protected]> 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.
Quoted 6 lines
Quoted 4 lines
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().Quoted 9 lines
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:
Quoted 7 lines
```
- (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.
Quoted 39 lines · Ferruh Yigit
Quoted 38 lines · Ferruh Yigit
Quoted 16 lines · Ferruh Yigit
Quoted 8 lines · Stephen Hemminger
Quoted 5 lines · On Tue, 16 May 2023 00:35:56 +0100 Ferruh Yigit <[email protected]> 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.
Quoted 6 lines
Quoted 4 lines
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().Quoted 9 lines
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) {
Quoted 5 lines
Quoted 1 line
```
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
Quoted 47 lines · David Christensen
Quoted 44 lines · Ferruh Yigit
Quoted 43 lines · Ferruh Yigit
Quoted 23 lines · Ferruh Yigit
Quoted 10 lines · Stephen Hemminger
Quoted 7 lines · On Tue, 16 May 2023 00:35:56 +0100 Ferruh Yigit <[email protected]> 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.Quoted 8 lines
Quoted 6 lines
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".
Quoted 7 lines
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) {
Quoted 10 lines
Quoted 5 lines
Quoted 1 line
```
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/[email protected]/
[2]
https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/