From e9a8ac59b6e279a29455eade7578b1d953bd5282 Mon Sep 17 00:00:00 2001 From: Viacheslav Ovsiienko Date: Thu, 14 May 2020 07:09:02 +0000 Subject: [PATCH] common/mlx5: fix MAC addresses 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: stable@dpdk.org Signed-off-by: Stephen Hemminger Signed-off-by: Viacheslav Ovsiienko Acked-by: Matan Azrad --- 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 c144223aad..65efcd3df2 100644 --- a/drivers/common/mlx5/mlx5_nl.c +++ b/drivers/common/mlx5/mlx5_nl.c @@ -671,7 +671,10 @@ 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); + 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 @@ 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); + 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 @@ 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); -- 2.20.1