patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH v2] common/mlx5: fix bogus assert
       [not found] <20200331060247.10954-1-stephen@networkplumber.org>
@ 2020-05-14  7:09 ` Viacheslav Ovsiienko
  2020-05-14 15:11   ` Alexander Kozyrev
                     ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Viacheslav Ovsiienko @ 2020-05-14  7:09 UTC (permalink / raw)
  To: dev; +Cc: matan, rasland, stephen, akozyrev, stable

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_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.

Fixes: 8e46d4e18f09 ("common/mlx5: improve assert control")
Cc: akozyrev@mellanox.com
Cc: stable@dpdk.org

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>

---
v2: fix asserts
v1: http://patches.dpdk.org/patch/67453/
---
 drivers/common/mlx5/mlx5_nl.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/common/mlx5/mlx5_nl.c b/drivers/common/mlx5/mlx5_nl.c
index c144223..65efcd3 100644
--- a/drivers/common/mlx5/mlx5_nl.c
+++ b/drivers/common/mlx5/mlx5_nl.c
@@ -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);
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-stable] [PATCH v2] common/mlx5: fix bogus assert
  2020-05-14  7:09 ` [dpdk-stable] [PATCH v2] common/mlx5: fix bogus assert Viacheslav Ovsiienko
@ 2020-05-14 15:11   ` Alexander Kozyrev
  2020-05-14 20:38     ` Slava Ovsiienko
  2020-05-17 12:02   ` Matan Azrad
  2020-05-17 12:39   ` Raslan Darawsheh
  2 siblings, 1 reply; 5+ messages in thread
From: Alexander Kozyrev @ 2020-05-14 15:11 UTC (permalink / raw)
  To: Slava Ovsiienko, dev; +Cc: Matan Azrad, Raslan Darawsheh, stephen, stable

These asserts seem redundant for me. Don't you think?
EINVAL is returned, why bother to assert the same condition?

Regards,
Alex  

> -----Original Message-----
> From: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
> Sent: Thursday, May 14, 2020 3:09
> To: dev@dpdk.org
> Cc: Matan Azrad <matan@mellanox.com>; Raslan Darawsheh
> <rasland@mellanox.com>; stephen@networkplumber.org; Alexander Kozyrev
> <akozyrev@mellanox.com>; stable@dpdk.org
> Subject: [PATCH v2] common/mlx5: fix bogus assert
> 
> 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_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.
> 
> Fixes: 8e46d4e18f09 ("common/mlx5: improve assert control")
> Cc: akozyrev@mellanox.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
> 
> ---
> v2: fix asserts
> v1:
> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpatches.d
> pdk.org%2Fpatch%2F67453%2F&amp;data=02%7C01%7Cakozyrev%40mellanox
> .com%7C4f8e2cb5aacd4a33e22a08d7f7d5c7c4%7Ca652971c7d2e4d9ba6a4d14
> 9256f461b%7C0%7C0%7C637250369858023357&amp;sdata=ZI7CTCQDnnmr6n
> pYXTOxOf4%2BBktSgmE%2F3rC4NG3QXxc%3D&amp;reserved=0
> ---
>  drivers/common/mlx5/mlx5_nl.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/common/mlx5/mlx5_nl.c b/drivers/common/mlx5/mlx5_nl.c
> index c144223..65efcd3 100644
> --- a/drivers/common/mlx5/mlx5_nl.c
> +++ b/drivers/common/mlx5/mlx5_nl.c
> @@ -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);
> --
> 1.8.3.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-stable] [PATCH v2] common/mlx5: fix bogus assert
  2020-05-14 15:11   ` Alexander Kozyrev
@ 2020-05-14 20:38     ` Slava Ovsiienko
  0 siblings, 0 replies; 5+ messages in thread
From: Slava Ovsiienko @ 2020-05-14 20:38 UTC (permalink / raw)
  To: Alexander Kozyrev, dev; +Cc: Matan Azrad, Raslan Darawsheh, stephen, stable

> -----Original Message-----
> From: Alexander Kozyrev <akozyrev@mellanox.com>
> Sent: Thursday, May 14, 2020 18:11
> To: Slava Ovsiienko <viacheslavo@mellanox.com>; dev@dpdk.org
> Cc: Matan Azrad <matan@mellanox.com>; Raslan Darawsheh
> <rasland@mellanox.com>; stephen@networkplumber.org; stable@dpdk.org
> Subject: RE: [PATCH v2] common/mlx5: fix bogus assert
> 
> These 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 ?

> 
> Regards,
> Alex
> 
> > -----Original Message-----
> > From: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
> > Sent: Thursday, May 14, 2020 3:09
> > To: dev@dpdk.org
> > Cc: Matan Azrad <matan@mellanox.com>; Raslan Darawsheh
> > <rasland@mellanox.com>; stephen@networkplumber.org; Alexander
> Kozyrev
> > <akozyrev@mellanox.com>; stable@dpdk.org
> > Subject: [PATCH v2] common/mlx5: fix bogus assert
> >
> > 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_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.
> >
> > Fixes: 8e46d4e18f09 ("common/mlx5: improve assert control")
> > Cc: akozyrev@mellanox.com
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
> >
> > ---
> > v2: fix asserts
> > v1:
> >
> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpatch
> > es.d
> pdk.org%2Fpatch%2F67453%2F&amp;data=02%7C01%7Cakozyrev%40mella
> nox
> >
> .com%7C4f8e2cb5aacd4a33e22a08d7f7d5c7c4%7Ca652971c7d2e4d9ba6a4
> d14
> >
> 9256f461b%7C0%7C0%7C637250369858023357&amp;sdata=ZI7CTCQDnnm
> r6n
> > pYXTOxOf4%2BBktSgmE%2F3rC4NG3QXxc%3D&amp;reserved=0
> > ---
> >  drivers/common/mlx5/mlx5_nl.c | 14 +++++++++++---
> >  1 file changed, 11 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/common/mlx5/mlx5_nl.c
> > b/drivers/common/mlx5/mlx5_nl.c index c144223..65efcd3 100644
> > --- a/drivers/common/mlx5/mlx5_nl.c
> > +++ b/drivers/common/mlx5/mlx5_nl.c
> > @@ -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);
> > --
> > 1.8.3.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-stable] [PATCH v2] common/mlx5: fix bogus assert
  2020-05-14  7:09 ` [dpdk-stable] [PATCH v2] common/mlx5: fix bogus assert Viacheslav Ovsiienko
  2020-05-14 15:11   ` Alexander Kozyrev
@ 2020-05-17 12:02   ` Matan Azrad
  2020-05-17 12:39   ` Raslan Darawsheh
  2 siblings, 0 replies; 5+ messages in thread
From: Matan Azrad @ 2020-05-17 12:02 UTC (permalink / raw)
  To: Slava Ovsiienko, dev; +Cc: Raslan Darawsheh, stephen, Alexander Kozyrev, stable



From: Viacheslav Ovsiienko
> 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_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.
> 
> Fixes: 8e46d4e18f09 ("common/mlx5: improve assert control")
> Cc: akozyrev@mellanox.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
Acked-by: Matan Azrad <matan@mellanox.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-stable] [PATCH v2] common/mlx5: fix bogus assert
  2020-05-14  7:09 ` [dpdk-stable] [PATCH v2] common/mlx5: fix bogus assert Viacheslav Ovsiienko
  2020-05-14 15:11   ` Alexander Kozyrev
  2020-05-17 12:02   ` Matan Azrad
@ 2020-05-17 12:39   ` Raslan Darawsheh
  2 siblings, 0 replies; 5+ messages in thread
From: Raslan Darawsheh @ 2020-05-17 12:39 UTC (permalink / raw)
  To: Slava Ovsiienko, dev; +Cc: Matan Azrad, stephen, Alexander Kozyrev, stable

Hi,

> -----Original Message-----
> From: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
> Sent: Thursday, May 14, 2020 10:09 AM
> To: dev@dpdk.org
> Cc: Matan Azrad <matan@mellanox.com>; Raslan Darawsheh
> <rasland@mellanox.com>; stephen@networkplumber.org; Alexander
> Kozyrev <akozyrev@mellanox.com>; stable@dpdk.org
> Subject: [PATCH v2] common/mlx5: fix bogus assert
> 
> 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_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.
> 
> Fixes: 8e46d4e18f09 ("common/mlx5: improve assert control")
> Cc: akozyrev@mellanox.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
> 
> ---
> v2: fix asserts
> v1:
> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpatch
> es.dpdk.org%2Fpatch%2F67453%2F&amp;data=02%7C01%7Crasland%40mell
> anox.com%7C71b3b1e727b8493f98fe08d7f7d5ce48%7Ca652971c7d2e4d9ba6
> a4d149256f461b%7C0%7C0%7C637250369975781842&amp;sdata=RI5eahOH
> MTb7khPqPkYe0AD3bRB6vPtuRh9INSJa8N0%3D&amp;reserved=0
> ---
>  drivers/common/mlx5/mlx5_nl.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/common/mlx5/mlx5_nl.c
> b/drivers/common/mlx5/mlx5_nl.c
> index c144223..65efcd3 100644
> --- a/drivers/common/mlx5/mlx5_nl.c
> +++ b/drivers/common/mlx5/mlx5_nl.c
> @@ -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);
> --
> 1.8.3.1


Patch applied to next-net-mlx,

Kindest regards
Raslan Darawsheh

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-05-17 12:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200331060247.10954-1-stephen@networkplumber.org>
2020-05-14  7:09 ` [dpdk-stable] [PATCH v2] common/mlx5: fix bogus assert Viacheslav Ovsiienko
2020-05-14 15:11   ` Alexander Kozyrev
2020-05-14 20:38     ` Slava Ovsiienko
2020-05-17 12:02   ` Matan Azrad
2020-05-17 12:39   ` Raslan Darawsheh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).