From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id D379EA00C3; Thu, 14 May 2020 09:09:15 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B133C1D643; Thu, 14 May 2020 09:09:15 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 331381D54C for ; Thu, 14 May 2020 09:09:14 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from viacheslavo@mellanox.com) with ESMTPS (AES256-SHA encrypted); 14 May 2020 10:09:10 +0300 Received: from pegasus12.mtr.labs.mlnx (pegasus12.mtr.labs.mlnx [10.210.17.40]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 04E79A15028075; Thu, 14 May 2020 10:09:10 +0300 Received: from pegasus12.mtr.labs.mlnx (localhost [127.0.0.1]) by pegasus12.mtr.labs.mlnx (8.14.7/8.14.7) with ESMTP id 04E79Aph007234; Thu, 14 May 2020 07:09:10 GMT Received: (from viacheslavo@localhost) by pegasus12.mtr.labs.mlnx (8.14.7/8.14.7/Submit) id 04E799H0007233; Thu, 14 May 2020 07:09:09 GMT X-Authentication-Warning: pegasus12.mtr.labs.mlnx: viacheslavo set sender to viacheslavo@mellanox.com using -f From: Viacheslav Ovsiienko To: dev@dpdk.org Cc: matan@mellanox.com, rasland@mellanox.com, stephen@networkplumber.org, akozyrev@mellanox.com, stable@dpdk.org Date: Thu, 14 May 2020 07:09:02 +0000 Message-Id: <1589440142-7197-1-git-send-email-viacheslavo@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <20200331060247.10954-1-stephen@networkplumber.org> References: <20200331060247.10954-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH v2] common/mlx5: fix bogus assert X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 Signed-off-by: Viacheslav Ovsiienko --- 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