From patchwork Sat Mar 27 07:38:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "humin (Q)" X-Patchwork-Id: 89960 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DD78AA0A02; Sat, 27 Mar 2021 08:38:07 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A082B140DAF; Sat, 27 Mar 2021 08:37:53 +0100 (CET) Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by mails.dpdk.org (Postfix) with ESMTP id 6D97B4067B for ; Sat, 27 Mar 2021 08:37:48 +0100 (CET) Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4F6rH45mJtz93yB; Sat, 27 Mar 2021 15:35:44 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.498.0; Sat, 27 Mar 2021 15:37:42 +0800 From: "Min Hu (Connor)" To: CC: , , Date: Sat, 27 Mar 2021 15:38:06 +0800 Message-ID: <1616830688-65506-2-git-send-email-humin29@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1616830688-65506-1-git-send-email-humin29@huawei.com> References: <1616830688-65506-1-git-send-email-humin29@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 1/3] ethdev: fix miss input validation in module EEPROM dump API X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" From: Chengchang Tang The validity verification of input parameters should be performed at API layer, not in the PMD. Fixes: 3a18c44b45df ("ethdev: add access to EEPROM") Fixes: 40ff8b305ab8 ("net/e1000: add module EEPROM callbacks for e1000") Fixes: f2088e785cca ("net/i40e: fix dereference before check when getting EEPROM") Fixes: b74d0cd43e37 ("net/ixgbe: add module EEPROM callbacks for ixgbe") Fixes: 8a6a09f853a0 ("net/mlx5: support reading module EEPROM data") Fixes: 58f6f93c34c1 ("net/octeontx2: add module EEPROM dump") Cc: stable@dpdk.org Signed-off-by: Chengchang Tang Signed-off-by: Min Hu (Connor) Reviewed-by: Ferruh Yigit --- drivers/net/e1000/igb_ethdev.c | 3 --- drivers/net/i40e/i40e_ethdev.c | 3 --- drivers/net/ixgbe/ixgbe_ethdev.c | 3 --- drivers/net/mlx5/linux/mlx5_ethdev_os.c | 4 ++-- drivers/net/octeontx2/otx2_ethdev_ops.c | 3 +-- lib/librte_ethdev/rte_ethdev.c | 4 ++++ lib/librte_ethdev/rte_ethdev.h | 2 ++ 7 files changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c index 1716d6b..11c73f9 100644 --- a/drivers/net/e1000/igb_ethdev.c +++ b/drivers/net/e1000/igb_ethdev.c @@ -5136,9 +5136,6 @@ eth_igb_get_module_eeprom(struct rte_eth_dev *dev, u16 first_word, last_word; int i = 0; - if (info->length == 0) - return -EINVAL; - first_word = info->offset >> 1; last_word = (info->offset + info->length - 1) >> 1; diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c index 9b86bcd..dbcf5c6 100644 --- a/drivers/net/i40e/i40e_ethdev.c +++ b/drivers/net/i40e/i40e_ethdev.c @@ -11591,9 +11591,6 @@ static int i40e_get_module_eeprom(struct rte_eth_dev *dev, uint32_t value = 0; uint32_t i; - if (!info || !info->length || !info->data) - return -EINVAL; - if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP) is_sfp = true; diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c index 8a9a21e..45496f3 100644 --- a/drivers/net/ixgbe/ixgbe_ethdev.c +++ b/drivers/net/ixgbe/ixgbe_ethdev.c @@ -7340,9 +7340,6 @@ ixgbe_get_module_eeprom(struct rte_eth_dev *dev, uint8_t *data = info->data; uint32_t i = 0; - if (info->length == 0) - return -EINVAL; - for (i = info->offset; i < info->offset + info->length; i++) { if (i < RTE_ETH_MODULE_SFF_8079_LEN) status = hw->phy.ops.read_i2c_eeprom(hw, i, &databyte); diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c b/drivers/net/mlx5/linux/mlx5_ethdev_os.c index 0e8de94..ea37c38 100644 --- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c +++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c @@ -1169,7 +1169,7 @@ mlx5_get_module_info(struct rte_eth_dev *dev, }; int ret = 0; - if (!dev || !modinfo) { + if (!dev) { DRV_LOG(WARNING, "missing argument, cannot get module info"); rte_errno = EINVAL; return -rte_errno; @@ -1203,7 +1203,7 @@ int mlx5_get_module_eeprom(struct rte_eth_dev *dev, struct ifreq ifr; int ret = 0; - if (!dev || !info) { + if (!dev) { DRV_LOG(WARNING, "missing argument, cannot get module eeprom"); rte_errno = EINVAL; return -rte_errno; diff --git a/drivers/net/octeontx2/otx2_ethdev_ops.c b/drivers/net/octeontx2/otx2_ethdev_ops.c index 963cc28..9197541 100644 --- a/drivers/net/octeontx2/otx2_ethdev_ops.c +++ b/drivers/net/octeontx2/otx2_ethdev_ops.c @@ -533,8 +533,7 @@ otx2_nix_get_module_eeprom(struct rte_eth_dev *eth_dev, struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev); struct cgx_fw_data *rsp; - if (!info->data || !info->length || - (info->offset + info->length > SFP_EEPROM_SIZE)) + if (info->offset + info->length > SFP_EEPROM_SIZE) return -EINVAL; rsp = nix_get_fwdata(dev); diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 3059aa5..bb195ab 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -5335,6 +5335,8 @@ rte_eth_dev_get_module_info(uint16_t port_id, struct rte_eth_dev *dev; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + if (modinfo == NULL) + return -EINVAL; dev = &rte_eth_devices[port_id]; RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_module_info, -ENOTSUP); @@ -5348,6 +5350,8 @@ rte_eth_dev_get_module_eeprom(uint16_t port_id, struct rte_eth_dev *dev; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + if (info == NULL || info->data == NULL || info->length == 0) + return -EINVAL; dev = &rte_eth_devices[port_id]; RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_module_eeprom, -ENOTSUP); diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h index efda313..78677a5 100644 --- a/lib/librte_ethdev/rte_ethdev.h +++ b/lib/librte_ethdev/rte_ethdev.h @@ -4446,6 +4446,7 @@ int rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info); * - (0) if successful. * - (-ENOTSUP) if hardware doesn't support. * - (-ENODEV) if *port_id* invalid. + * - (-EINVAL) if bad parameter. * - (-EIO) if device is removed. * - others depends on the specific operations implementation. */ @@ -4465,6 +4466,7 @@ int rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info); * - (0) if successful. * - (-ENOTSUP) if hardware doesn't support. * - (-ENODEV) if *port_id* invalid. + * - (-EINVAL) if bad parameter. * - (-EIO) if device is removed. * - others depends on the specific operations implementation. */