common/mlx5: fix bogus assert
PATCH 1/1 common/mlx5: fix bogus assert
The MLX5 device supports up to 256 MAC addresses.
The code flushes all MAC devices.
If DPDK is compiled with MLX5_DEBUG this would an assert. PANIC in mlx5_nl_mac_addr_flush():
line 775 assert "(size_t)(i) < sizeof(mac_own) * 8" failed
The root cause is that mac_own is a pointer and is being used as a bitmap array. The sizeof(mac_own) would therfore be 64 but the number of entries to be flushed would be 256.
There is a whole set of asserts in MLX5 netlink code with the same bug; that should just be changed into proper error checks.
--- drivers/common/mlx5/mlx5_nl.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/common/mlx5/mlx5_nl.c +9 -3
@@ -671,7 +671,9 @@ mlx5_nl_mac_addr_add(int nlsk_fd, unsigned int iface_idx, ret =mlx5_nl_mac_addr_modify (nlsk_fd, iface_idx, mac,1 );if (!ret) { -MLX5_ASSERT ((size_t )(index) <sizeof (mac_own) *CHAR_BIT ); +if (index >=MLX5_MAX_MAC_ADDRESSES ) +return -EINVAL ; +BITFIELD_SET (mac_own, index); }if (ret == -EEXIST )
@@ -700,7 +702,9 @@ int mlx5_nl_mac_addr_remove(int nlsk_fd, unsigned int iface_idx, uint64_t *mac_own, struct rte_ether_addr *mac, uint32_t index) { - MLX5_ASSERT((size_t)(index) < sizeof(mac_own) * CHAR_BIT); + if (index >= MLX5_MAX_MAC_ADDRESSES) + return -EINVAL; +BITFIELD_RESET (mac_own, index);return mlx5_nl_mac_addr_modify (nlsk_fd, iface_idx, mac,0 ); }
@@ -769,10 +773,12 @@ mlx5_nl_mac_addr_flush(int nlsk_fd, unsigned int iface_idx, {int i; +if (n <=0 || n >=MLX5_MAX_MAC_ADDRESSES ) +return ; +for (i = n -1 ; i >=0 ; --i) {struct rte_ether_addr *m = &mac_addrs[i]; -MLX5_ASSERT ((size_t )(i) <sizeof (mac_own) *CHAR_BIT );if (BITFIELD_ISSET (mac_own, i))mlx5_nl_mac_addr_remove (nlsk_fd, iface_idx, mac_own, m, i);
Signature · 1 line
2.20.1
Hi, Stephen
Thank you for the fix.
The exposed API to set MAC addresses:
- mlx5_mac_addr_set (invoked by rte_mac_addr_set ())
- mlx5_set_mc_addr_list (invoked by rte_eth_dev_set_mc_addr_list())
Both routines call mlx5_internal_mac_addr_add(), it in its turn calls mlx5_nl_mac_addr_add() (that is subject of the patch).
mlx5_nl_mac_addr_add is internal function, not exposed external API,
the wrong parameter means the critical internal bug, so assert looks to be relevant here. I would not remove MLX5_ASSERT at all but fix just it.
Adding the parameter check and return an error is nice.
What do you think?
With best regards, Slava
Quoted 74 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, March 31, 2020 9:03
To: Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; Slava Ovsiienko <[email protected]>
Cc: [email protected]; Stephen Hemminger <[email protected]>; Alexander Kozyrev <[email protected]>
Subject: [PATCH] common/mlx5: fix bogus assertThe MLX5 device supports up to 256 MAC addresses.
The code flushes all MAC devices.If DPDK is compiled with
MLX5_DEBUGthis would an assert. PANIC inmlx5_nl_mac_addr_flush():
line 775 assert "(size_t)(i) <sizeof(mac_own)* 8" failedThe root cause is that
mac_ownis a pointer and is being used as a bitmap array. Thesizeof(mac_own)would therfore be 64 but the number of entries to be flushed would be 256.There is a whole set of asserts in MLX5 netlink code with the same bug; that should just be changed into proper error checks.
Fixes 8e46d4e18f09 ("common/mlx5: improve assert control")Signed-off-by Stephen Hemminger <[email protected]>--- drivers/common/mlx5/mlx5_nl.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)(quoted diff) +0
-0
b/drivers/common/mlx5/mlx5_nl.cindex549e787b04bf..69f5efa50aa8100644drivers/common/mlx5/mlx5_nl.c +3
-1@@ -671,7 +671,9 @@ mlx5_nl_mac_addr_add(int nlsk_fd, unsigned int iface_idx, ret =mlx5_nl_mac_addr_modify (nlsk_fd, iface_idx, mac,1 );if (!ret) { -MLX5_ASSERT ((size_t )(index) <sizeof (mac_own) *CHAR_BIT ); +if (index >=MLX5_MAX_MAC_ADDRESSES ) +return -EINVAL ; +BITFIELD_SET (mac_own, index); }drivers/common/mlx5/mlx5_nl.c +3
-1if (ret == -EEXIST )@@ -700,7 +702,9 @@ int mlx5_nl_mac_addr_remove(int nlsk_fd, unsigned int iface_idx, uint64_t *mac_own, struct rte_ether_addr *mac, uint32_t index) { - MLX5_ASSERT((size_t)(index) < sizeof(mac_own) * CHAR_BIT); + if (index >= MLX5_MAX_MAC_ADDRESSES) + return -EINVAL; +BITFIELD_RESET (mac_own, index); return mlx5_nl_mac_addr_modify(nlsk_fd, iface_idx, mac, 0); } @@ -769,10 +773,12 @@ mlx5_nl_mac_addr_flush(int
nlsk_fd, unsigned intiface_idx, {drivers/common/mlx5/mlx5_nl.c +3
-1int i; +if (n <=0 || n >=MLX5_MAX_MAC_ADDRESSES ) +return ; +for (i = n -1 ; i >=0 ; --i) {struct rte_ether_addr *m = &mac_addrs[i]; -MLX5_ASSERT ((size_t )(i) <sizeof (mac_own) *CHAR_BIT );if (BITFIELD_ISSET (mac_own, i)) mlx5_nl_mac_addr_remove(nlsk_fd, iface_idx,
mac_own, m,
i);
--
2.20.1
Quoted 11 lines · On Tue, 31 Mar 2020 07:31:48 +0000 Slava Ovsiienko <[email protected]>…
Hi, Stephen
Thank you for the fix.
The exposed API to set MAC addresses:
-mlx5_mac_addr_set(invoked byrte_mac_addr_set())
-mlx5_set_mc_addr_list(invoked byrte_eth_dev_set_mc_addr_list())Both routines call
mlx5_internal_mac_addr_add(), it in its turn callsmlx5_nl_mac_addr_add()(that is subject of the patch).
Quoted 7 lines
mlx5_nl_mac_addr_addis internal function, not exposed external API,
the wrong parameter means the critical internal bug, so assert looks to be relevant here. I would not removeMLX5_ASSERTat all but fix just it.
Adding the parameter check and return an error is nice.
What do you think?With best regards, Slava
The real root cause is that sizeof(mac_own) is the wrong thing to do. The error handling is up to you.
Since ASSERT's are compiled out they are never tested and are actually making code less safe.
Quoted 30 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, March 31, 2020 17:55
To: Slava Ovsiienko <[email protected]>
Cc: Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; [email protected]; Alexander Kozyrev <[email protected]>
Subject: Re: [PATCH] common/mlx5: fix bogus assertQuoted 8 lines · On Tue, 31 Mar 2020 07:31:48 +0000 Slava Ovsiienko <[email protected]>…
Hi, Stephen
Thank you for the fix.
The exposed API to set MAC addresses:
-mlx5_mac_addr_set(invoked byrte_mac_addr_set())
-mlx5_set_mc_addr_list(invoked byrte_eth_dev_set_mc_addr_list())Quoted 5 lines
Both routines call
mlx5_internal_mac_addr_add(), it in its turn callsmlx5_nl_mac_addr_add()(that is subject of the patch).
mlx5_nl_mac_addr_addis internal function, not exposed external API, the wrong parameter means the critical internal bug, so assert looks to berelevant here.
Quoted 4 lines
I would not remove
MLX5_ASSERTat all but fix just it. Adding the parameter check and return an error is nice. What do you think?
Quoted 7 lines
Quoted 1 line
With best regards, Slava
The real root cause is that
sizeof(mac_own)is the wrong thing to do. The error handling is up to you.Since ASSERT's are compiled out they are never tested and are actually making code less safe.
Generally speaking assert is not subject to test - I would consider it as a part of debug means. Yes, this assert was with wrong condition and was not tested, but once enabled and a lot of MACs came into game - we got an issue and your patch is here 😊.
Quoted 1 line
Quoted 1 line
making code less safe.
The debug version of code is usually less safe and has no performance.
Adding the check and error return is OK, it works always and improves the code, we do not expect engaging of it here, though. Removing assert (instead of fixing one) reduces our debugging capabilities, so it is not OK, as for me.
With best regards, Slava
Quoted 38 lines · On Tue, 31 Mar 2020 15:09:43 +0000 Slava Ovsiienko <[email protected]>…
Quoted 30 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, March 31, 2020 17:55
To: Slava Ovsiienko <[email protected]>
Cc: Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; [email protected]; Alexander Kozyrev <[email protected]>
Subject: Re: [PATCH] common/mlx5: fix bogus assertQuoted 8 lines · On Tue, 31 Mar 2020 07:31:48 +0000 Slava Ovsiienko <[email protected]>…
Hi, Stephen
Thank you for the fix.
The exposed API to set MAC addresses:
-mlx5_mac_addr_set(invoked byrte_mac_addr_set())
-mlx5_set_mc_addr_list(invoked byrte_eth_dev_set_mc_addr_list())Quoted 5 lines
Both routines call
mlx5_internal_mac_addr_add(), it in its turn callsmlx5_nl_mac_addr_add()(that is subject of the patch).
mlx5_nl_mac_addr_addis internal function, not exposed external API, the wrong parameter means the critical internal bug, so assert looks to berelevant here.
Quoted 4 lines
I would not remove
MLX5_ASSERTat all but fix just it. Adding the parameter check and return an error is nice. What do you think?Quoted 7 lines
Quoted 1 line
With best regards, Slava
The real root cause is that
sizeof(mac_own)is the wrong thing to do. The error handling is up to you.Since ASSERT's are compiled out they are never tested and are actually making code less safe.
Quoted 8 lines
Generally speaking assert is not subject to test - I would consider it as a part of debug means. Yes, this assert was with wrong condition and was not tested, but once enabled and a lot of MACs came into game - we got an issue and your patch is here 😊.
Quoted 1 line
Quoted 1 line
making code less safe.
The debug version of code is usually less safe and has no performance.
Adding the check and error return is OK, it works always and improves the code, we do not expect engaging of it here, though.
I am done being diplomatic.
You have repeatedly ignored the fact that doing sizeof a pointer is not correct here. mac_own is a pointer so doing sizeof(mac_own) will not give what you want. You probably thought mac_own was an array, or that compiler would know that the pointer was an array.
Any visible config option should work correctly. The code should not break. Any not visible config option #ifdefs should be expunged from the upstream code.
Either take the patch, or fix your code please
Quoted 62 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Friday, April 10, 2020 20:15
To: Slava Ovsiienko <[email protected]>
Cc: Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; [email protected]; Alexander Kozyrev <[email protected]>
Subject: Re: [PATCH] common/mlx5: fix bogus assertQuoted 35 lines · On Tue, 31 Mar 2020 15:09:43 +0000 Slava Ovsiienko <[email protected]>…
Quoted 35 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, March 31, 2020 17:55
To: Slava Ovsiienko <[email protected]>
Cc: Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; [email protected]; Alexander Kozyrev <[email protected]>
Subject: Re: [PATCH] common/mlx5: fix bogus assertQuoted 9 lines · On Tue, 31 Mar 2020 07:31:48 +0000 Slava Ovsiienko <[email protected]>…
Hi, Stephen
Thank you for the fix.
The exposed API to set MAC addresses:
-mlx5_mac_addr_set(invoked byrte_mac_addr_set())
-mlx5_set_mc_addr_list(invoked byrte_eth_dev_set_mc_addr_list())Quoted 7 lines
Both routines call
mlx5_internal_mac_addr_add(), it in its turn callsmlx5_nl_mac_addr_add()(that is subject of the patch).
mlx5_nl_mac_addr_addis internal function, not exposed external API, the wrong parameter means the critical internal bug, so assert looks to berelevant here.
Quoted 5 lines
I would not remove
MLX5_ASSERTat all but fix just it. Adding the parameter check and return an error is nice. What do you think?With best regards, Slava
Quoted 7 lines
Quoted 5 lines
The real root cause is that
sizeof(mac_own)is the wrong thing to do. The error handling is up to you.Since ASSERT's are compiled out they are never tested and are actually making code less safe.
Generally speaking assert is not subject to test - I would consider it as a part
of debug means.
Quoted 2 lines
Yes, this assert was with wrong condition and was not tested, but once enabled and a lot of MACs came into game - we got an issue and your patch
is here 😊.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
making code less safe.
Quoted 8 lines
Quoted 2 lines
The debug version of code is usually less safe and has no performance. Adding the check and error return is OK, it works always and improves the
code, we do not expect engaging of it here, though.
Quoted 1 line
I am done being diplomatic.
You have repeatedly ignored the fact that doing sizeof a pointer is not correct here.
You are quite right. It is obvious bug and must be fixed, thank you for the patch. And let me make you sure I did not mind fixing in anyway.
My only proposal was to fix ASSERT as well instead of dropping one, sorry if I did not express it in clear way.
Something like this:MLX5_ASSERT(index < MLX5_MAX_MAC_ADDRESSES);
Quoted 9 lines
mac_ownis a pointer so doingsizeof(mac_own)will not give what you want. You probably thoughtmac_ownwas an array, or that compiler would know that the pointer was an array.Any visible config option should work correctly. The code should not break. Any not visible config option #ifdefs should be expunged from the upstream code.
Either take the patch, or fix your code please
Whatever you'd prefer - please, fix ASSERT, or let me know if I should.
Thanks in advance,
Slava
PATCH v2 1/1 common/mlx5: fix bogus assert
In reply to Stephen HemmingerThe MLX5 device supports up to MLX5_MAX_MAC_ADDRESSES (256) MAC addresses. The code flushes all MAC devices.
If DPDK is compiled with MLX5_DEBUG this would an assert. PANIC in mlx5_nl_mac_addr_flush():
line 775 assert "(size_t)(i) < sizeof(mac_own) * 8" failed
The root cause is that mac_own is a pointer and is being used as a bitmap array. The sizeof(mac_own) would therefore be 64 but the number of entries to be flushed would be 256.
There is a whole set of asserts in MLX5 netlink code with the same bug; that should just be changed into proper error checks.
---
v2: fix asserts
v1: http://patches.dpdk.org/patch/67453/
--- drivers/common/mlx5/mlx5_nl.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/common/mlx5/mlx5_nl.c +11 -3
@@ -671,7 +671,10 @@ struct mlx5_nl_ifindex_data { ret =mlx5_nl_mac_addr_modify (nlsk_fd, iface_idx, mac,1 );if (!ret) { -MLX5_ASSERT ((size_t )(index) <sizeof (mac_own) *CHAR_BIT ); +MLX5_ASSERT (index <MLX5_MAX_MAC_ADDRESSES ); +if (index >=MLX5_MAX_MAC_ADDRESSES ) +return -EINVAL ; +BITFIELD_SET (mac_own, index); }if (ret == -EEXIST )
@@ -700,7 +703,10 @@ struct mlx5_nl_ifindex_data { mlx5_nl_mac_addr_remove(int nlsk_fd, unsigned int iface_idx, uint64_t *mac_own, struct rte_ether_addr *mac, uint32_t index) { - MLX5_ASSERT((size_t)(index) < sizeof(mac_own) * CHAR_BIT); + MLX5_ASSERT(index < MLX5_MAX_MAC_ADDRESSES); +if (index >=MLX5_MAX_MAC_ADDRESSES ) +return -EINVAL ; +BITFIELD_RESET (mac_own, index);return mlx5_nl_mac_addr_modify (nlsk_fd, iface_idx, mac,0 ); }
@@ -769,10 +775,12 @@ struct mlx5_nl_ifindex_data { {int i; +if (n <=0 || n >=MLX5_MAX_MAC_ADDRESSES ) +return ; +for (i = n -1 ; i >=0 ; --i) {struct rte_ether_addr *m = &mac_addrs[i]; -MLX5_ASSERT ((size_t )(i) <sizeof (mac_own) *CHAR_BIT );if (BITFIELD_ISSET (mac_own, i))mlx5_nl_mac_addr_remove (nlsk_fd, iface_idx, mac_own, m, i);
Signature · 1 line
1.8.3.1
These asserts seem redundant for me. Don't you think? EINVAL is returned, why bother to assert the same condition?
Regards,
Alex
Quoted 86 lines
-----Original Message-----
From: Viacheslav Ovsiienko <[email protected]>
Sent: Thursday, May 14, 2020 3:09
To: [email protected]
Cc: Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; Alexander Kozyrev <[email protected]>; [email protected]
Subject: [PATCH v2] common/mlx5: fix bogus assertThe MLX5 device supports up to
MLX5_MAX_MAC_ADDRESSES(256) MAC addresses.
The code flushes all MAC devices.If DPDK is compiled with
MLX5_DEBUGthis would an assert. PANIC inmlx5_nl_mac_addr_flush():
line 775 assert "(size_t)(i) <sizeof(mac_own)* 8" failedThe root cause is that
mac_ownis a pointer and is being used as a bitmap array. Thesizeof(mac_own)would therefore be 64 but the number of entries to be flushed would be 256.There is a whole set of asserts in MLX5 netlink code with the same bug; that should just be changed into proper error checks.
Signed-off-by Stephen Hemminger <[email protected]>Signed-off-by Viacheslav Ovsiienko <[email protected]>---
v2: fix asserts
v1:
https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpatches.d
pdk.org%2Fpatch%2F67453%2F&data=02%7C01%7Cakozyrev%40mellanox .com%7C4f8e2cb5aacd4a33e22a08d7f7d5c7c4%7Ca652971c7d2e4d9ba6a4d14 9256f461b%7C0%7C0%7C637250369858023357&sdata=ZI7CTCQDnnmr6n pYXTOxOf4%2BBktSgmE%2F3rC4NG3QXxc%3D&reserved=0--- drivers/common/mlx5/mlx5_nl.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)drivers/common/mlx5/mlx5_nl.c +4
-1@@ -671,7 +671,10 @@ struct mlx5_nl_ifindex_data { ret =mlx5_nl_mac_addr_modify (nlsk_fd, iface_idx, mac,1 );if (!ret) { -MLX5_ASSERT ((size_t )(index) <sizeof (mac_own) *CHAR_BIT ); +MLX5_ASSERT (index <MLX5_MAX_MAC_ADDRESSES ); +if (index >=MLX5_MAX_MAC_ADDRESSES ) +return -EINVAL ; +BITFIELD_SET (mac_own, index); }if (ret == -EEXIST )@@ -700,7 +703,10 @@ struct mlx5_nl_ifindex_data {mlx5_nl_mac_addr_remove(int
nlsk_fd, unsigned intiface_idx,uint64_t*mac_own,drivers/common/mlx5/mlx5_nl.c +4
-1struct rte_ether_addr *mac, uint32_t index) { -MLX5_ASSERT ((size_t )(index) <sizeof (mac_own) *CHAR_BIT ); +MLX5_ASSERT (index <MLX5_MAX_MAC_ADDRESSES ); +if (index >=MLX5_MAX_MAC_ADDRESSES ) +return -EINVAL ; +BITFIELD_RESET (mac_own, index); return mlx5_nl_mac_addr_modify(nlsk_fd, iface_idx, mac, 0); } @@ -769,10 +775,12 @@ struct
mlx5_nl_ifindex_data{ {drivers/common/mlx5/mlx5_nl.c +3
-1int i; +if (n <=0 || n >=MLX5_MAX_MAC_ADDRESSES ) +return ; +for (i = n -1 ; i >=0 ; --i) {struct rte_ether_addr *m = &mac_addrs[i]; -MLX5_ASSERT ((size_t )(i) <sizeof (mac_own) *CHAR_BIT );if (BITFIELD_ISSET (mac_own, i)) mlx5_nl_mac_addr_remove(nlsk_fd, iface_idx,
mac_own, m,
i);
--
1.8.3.1
Quoted 10 lines
-----Original Message-----
From: Alexander Kozyrev <[email protected]>
Sent: Thursday, May 14, 2020 18:11
To: Slava Ovsiienko <[email protected]>; [email protected]
Cc: Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]
Subject: RE: [PATCH v2] common/mlx5: fix bogus assertThese asserts seem redundant for me. Don't you think? EINVAL is returned, why bother to assert the same condition?
To stop the wrong conditions evolving on debug ?
Quoted 101 lines
Regards,
AlexQuoted 6 lines
-----Original Message-----
From: Viacheslav Ovsiienko <[email protected]>
Sent: Thursday, May 14, 2020 3:09
To: [email protected]
Cc: Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; AlexanderKozyrev
Quoted 7 lines
<[email protected]>; [email protected]
Subject: [PATCH v2] common/mlx5: fix bogus assertThe MLX5 device supports up to
MLX5_MAX_MAC_ADDRESSES(256) MAC addresses.
The code flushes all MAC devices.Quoted 5 lines
If DPDK is compiled with
MLX5_DEBUGthis would an assert. PANIC inmlx5_nl_mac_addr_flush():
line 775 assert "(size_t)(i) <sizeof(mac_own)* 8" failedThe root cause is that
mac_ownis a pointer and is being used as a bitmaparray.
Quoted 10 lines
The
sizeof(mac_own)would therefore be 64 but the number of entries to be flushed would be 256.There is a whole set of asserts in MLX5 netlink code with the same bug; that should just be changed into proper error checks.
Quoted 7 lines
Signed-off-by Stephen Hemminger <[email protected]>Signed-off-by Viacheslav Ovsiienko <[email protected]>---
v2: fix asserts
v1:https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpatch
Quoted 1 line
es.d
pdk.org%2Fpatch%2F67453%2F&data=02%7C01%7Cakozyrev%40mella nox
Quoted 1 line
.com%7C4f8e2cb5aacd4a33e22a08d7f7d5c7c4%7Ca652971c7d2e4d9ba6a4 d14
Quoted 1 line
9256f461b%7C0%7C0%7C637250369858023357&sdata=ZI7CTCQDnnm r6n
Quoted 10 lines
pYXTOxOf4%2BBktSgmE%2F3rC4NG3QXxc%3D&reserved=0
--- drivers/common/mlx5/mlx5_nl.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)(quoted diff) +0
-0
b/drivers/common/mlx5/mlx5_nl.cindex c144223..65efcd3 100644drivers/common/mlx5/mlx5_nl.c struct mlx5_nl_ifindex_data { · line 674
Quoted 4 lines
drivers/common/mlx5/mlx5_nl.c +0
-1@@ -671,7 +671,10 @@ struct mlx5_nl_ifindex_data { ret =mlx5_nl_mac_addr_modify (nlsk_fd, iface_idx, mac,1 );if (!ret) { - MLX5_ASSERT((size_t)(index) < sizeof(mac_own) *
CHAR_BIT);Quoted 10 lines
drivers/common/mlx5/mlx5_nl.c +4
-0+MLX5_ASSERT (index <MLX5_MAX_MAC_ADDRESSES ); +if (index >=MLX5_MAX_MAC_ADDRESSES ) +return -EINVAL ; +BITFIELD_SET (mac_own, index); }if (ret == -EEXIST )@@ -700,7 +703,10 @@ struct mlx5_nl_ifindex_data {mlx5_nl_mac_addr_remove(int
nlsk_fd, unsigned intiface_idx,uint64_t*mac_own,drivers/common/mlx5/mlx5_nl.c struct mlx5_nl_ifindex_data {
Quoted 8 lines
drivers/common/mlx5/mlx5_nl.c +4
-1struct rte_ether_addr *mac, uint32_t index) { -MLX5_ASSERT ((size_t )(index) <sizeof (mac_own) *CHAR_BIT ); +MLX5_ASSERT (index <MLX5_MAX_MAC_ADDRESSES ); +if (index >=MLX5_MAX_MAC_ADDRESSES ) +return -EINVAL ; +BITFIELD_RESET (mac_own, index); return mlx5_nl_mac_addr_modify(nlsk_fd, iface_idx, mac, 0); } @@-
drivers/common/mlx5/mlx5_nl.c struct mlx5_nl_ifindex_data {
Quoted 12 lines
769,10 +775,12 @@ struct
mlx5_nl_ifindex_data{ {drivers/common/mlx5/mlx5_nl.c +3
-1int i; +if (n <=0 || n >=MLX5_MAX_MAC_ADDRESSES ) +return ; +for (i = n -1 ; i >=0 ; --i) {struct rte_ether_addr *m = &mac_addrs[i]; -MLX5_ASSERT ((size_t )(i) <sizeof (mac_own) *CHAR_BIT );if (BITFIELD_ISSET (mac_own, i)) mlx5_nl_mac_addr_remove(nlsk_fd, iface_idx,
mac_own, m,Quoted 3 lines
i);
--
1.8.3.1
From: Viacheslav Ovsiienko
Quoted 15 lines
The MLX5 device supports up to
MLX5_MAX_MAC_ADDRESSES(256) MAC addresses.
The code flushes all MAC devices.If DPDK is compiled with
MLX5_DEBUGthis would an assert. PANIC inmlx5_nl_mac_addr_flush():
line 775 assert "(size_t)(i) <sizeof(mac_own)* 8" failedThe root cause is that
mac_ownis a pointer and is being used as a bitmap array. Thesizeof(mac_own)would therefore be 64 but the number of entries to be flushed would be 256.There is a whole set of asserts in MLX5 netlink code with the same bug; that should just be changed into proper error checks.
Quoted 6 lines
Signed-off-by Stephen Hemminger <[email protected]>Signed-off-by Viacheslav Ovsiienko <[email protected]>
Hi,
Quoted 88 lines
-----Original Message-----
From: Viacheslav Ovsiienko <[email protected]>
Sent: Thursday, May 14, 2020 10:09 AM
To: [email protected]
Cc: Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; Alexander Kozyrev <[email protected]>; [email protected]
Subject: [PATCH v2] common/mlx5: fix bogus assertThe MLX5 device supports up to
MLX5_MAX_MAC_ADDRESSES(256) MAC addresses.
The code flushes all MAC devices.If DPDK is compiled with
MLX5_DEBUGthis would an assert. PANIC inmlx5_nl_mac_addr_flush():
line 775 assert "(size_t)(i) <sizeof(mac_own)* 8" failedThe root cause is that
mac_ownis a pointer and is being used as a bitmap array. Thesizeof(mac_own)would therefore be 64 but the number of entries to be flushed would be 256.There is a whole set of asserts in MLX5 netlink code with the same bug; that should just be changed into proper error checks.
Signed-off-by Stephen Hemminger <[email protected]>Signed-off-by Viacheslav Ovsiienko <[email protected]>---
v2: fix asserts
v1:
https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpatch
es.dpdk.org%2Fpatch%2F67453%2F&data=02%7C01%7Crasland%40mell anox.com%7C71b3b1e727b8493f98fe08d7f7d5ce48%7Ca652971c7d2e4d9ba6 a4d149256f461b%7C0%7C0%7C637250369975781842&sdata=RI5eahOH MTb7khPqPkYe0AD3bRB6vPtuRh9INSJa8N0%3D&reserved=0--- drivers/common/mlx5/mlx5_nl.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)drivers/common/mlx5/mlx5_nl.c +4
-1@@ -671,7 +671,10 @@ struct mlx5_nl_ifindex_data { ret =mlx5_nl_mac_addr_modify (nlsk_fd, iface_idx, mac,1 );if (!ret) { -MLX5_ASSERT ((size_t )(index) <sizeof (mac_own) * CHAR_BIT); +MLX5_ASSERT (index <MLX5_MAX_MAC_ADDRESSES ); +if (index >=MLX5_MAX_MAC_ADDRESSES ) +return -EINVAL ; +BITFIELD_SET (mac_own, index); }drivers/common/mlx5/mlx5_nl.c +4
-1if (ret == -EEXIST )@@ -700,7 +703,10 @@ struct mlx5_nl_ifindex_data { mlx5_nl_mac_addr_remove(int nlsk_fd, unsigned int iface_idx, uint64_t *mac_own, struct rte_ether_addr *mac, uint32_t index) { - MLX5_ASSERT((size_t)(index) < sizeof(mac_own) * CHAR_BIT); + MLX5_ASSERT(index < MLX5_MAX_MAC_ADDRESSES); +if (index >=MLX5_MAX_MAC_ADDRESSES ) +return -EINVAL ; +BITFIELD_RESET (mac_own, index);return mlx5_nl_mac_addr_modify (nlsk_fd, iface_idx, mac,0 );}
drivers/common/mlx5/mlx5_nl.c +3
-1@@ -769,10 +775,12 @@ struct mlx5_nl_ifindex_data { {int i; +if (n <=0 || n >=MLX5_MAX_MAC_ADDRESSES ) +return ; +for (i = n -1 ; i >=0 ; --i) {struct rte_ether_addr *m = &mac_addrs[i]; -MLX5_ASSERT ((size_t )(i) <sizeof (mac_own) *CHAR_BIT );if (BITFIELD_ISSET (mac_own, i)) mlx5_nl_mac_addr_remove(nlsk_fd, iface_idx, mac_own, m,
Quoted 3 lines
i);
--
1.8.3.1
Patch applied to next-net-mlx,
Kindest regards
Raslan Darawsheh