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 ADA71A0562; Tue, 31 Mar 2020 08:02:58 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AE6012C15; Tue, 31 Mar 2020 08:02:57 +0200 (CEST) Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) by dpdk.org (Postfix) with ESMTP id 96DD0FFA for ; Tue, 31 Mar 2020 08:02:56 +0200 (CEST) Received: by mail-pj1-f67.google.com with SMTP id kx8so617929pjb.5 for ; Mon, 30 Mar 2020 23:02:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NeeNySOyntTvTPGrEH/KTxl+AGCp43K9+Hv8sGCCcFs=; b=Uhe50/UeFS0GaT6WlWpcZXDG6Yb7jy9VAYJZBZBrPQWtqjKkuK2k6gdFjklnP/9pYZ f5mMzzCbAlN7yj3hVdIqdJGyNWUQGfSojuqQthaLxNrdR2azl21ikIM/PLVrevrdvYMQ xEIa2rwALqGnjbGE+8INTEd5pe1ZHlX79sppcN/o1oroKJdkoaxJlPx/MiObykL8bdf3 Cv0K9J/chH3aB2FD7OKviGVcfDjKhOm+rcqXaTJLc4sAmbFsMKzLq+KfhDulyl2c33Nj 8PzsszQGUkfwgNMBRnw6/B8U5MA1AaDJQkRGqQc/BwyTw4DlBwnAHK+MfY67NpqcHHkO 3CwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NeeNySOyntTvTPGrEH/KTxl+AGCp43K9+Hv8sGCCcFs=; b=JMjkrz3iejeN4aVx6MDm3bg5dl719ptgSU1qm0QiFOVkfySUtnWySv1KGx68a0Ba2l 5oDNR3DQ37eMUueLU4F2vbVhTy8yoyY1E/zYadKZDzlH+4bQgIET7EJbO7VVaj8o8m+G iaZgY9vSXJPx8P5qcfQbAcnAm/Hes7xjT1djkYEaL9rLZh1gWaGvZjN1EK4mHPt/tgCO Rmhr8I/5h6EO0Th5F/zGDUjfg24Tpgt5tYrFqny+vgcmFcvsqDWjxiNRVFvH/xXL0EE3 gbguaPS8jJzj18GgLZfv69qep+T+xgWn2dSRgz3991iSFzi7EiaMu+zfPq3ubbqYqT36 V5mg== X-Gm-Message-State: AGi0PuZP14Jb+d1B34qNuHK304Jkm0/lk2aSlw4ZkO6sQcx9Cz2RIs0W LGBH/ivY8RErM/T5LTJtAgjjiA== X-Google-Smtp-Source: APiQypKAJG9nB5/UmZ917sXWL2WQC17OY3SWybsq1xulGTUSAfmtpmtw8JP8v4phkc3dY2P9MKN+3g== X-Received: by 2002:a17:90a:198e:: with SMTP id 14mr1948440pji.164.1585634575546; Mon, 30 Mar 2020 23:02:55 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id c1sm997228pje.24.2020.03.30.23.02.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Mar 2020 23:02:54 -0700 (PDT) From: Stephen Hemminger To: matan@mellanox.com, shahafs@mellanox.com, viacheslavo@mellanox.com Cc: dev@dpdk.org, Stephen Hemminger , akozyrev@mellanox.com Date: Mon, 30 Mar 2020 23:02:47 -0700 Message-Id: <20200331060247.10954-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] 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 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. Fixes: 8e46d4e18f09 ("common/mlx5: improve assert control") Cc: akozyrev@mellanox.com Signed-off-by: Stephen Hemminger --- drivers/common/mlx5/mlx5_nl.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/common/mlx5/mlx5_nl.c b/drivers/common/mlx5/mlx5_nl.c index 549e787b04bf..69f5efa50aa8 100644 --- a/drivers/common/mlx5/mlx5_nl.c +++ b/drivers/common/mlx5/mlx5_nl.c @@ -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); -- 2.20.1