DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 0/3] fix miss input validation
@ 2021-03-27  7:38 Min Hu (Connor)
  2021-03-27  7:38 ` [dpdk-dev] [PATCH 1/3] ethdev: fix miss input validation in module EEPROM dump API Min Hu (Connor)
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Min Hu (Connor) @ 2021-03-27  7:38 UTC (permalink / raw)
  To: dev; +Cc: ferruh.yigit, thomas, andrew.rybchenko

The validity verification of input parameters should be performed at
API layer, not in the PMD.

This set of patches fix miss input validation.

Chengchang Tang (3):
  ethdev: fix miss input validation in module EEPROM dump API
  ethdev: fix miss input validation when access reg info
  ethdev: fix miss input validation when access EEPROM info

 drivers/net/e1000/igb_ethdev.c          |  3 ---
 drivers/net/hns3/hns3_regs.c            |  5 -----
 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          | 10 ++++++++++
 lib/librte_ethdev/rte_ethdev.h          |  5 +++++
 8 files changed, 18 insertions(+), 18 deletions(-)

-- 
2.7.4


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

* [dpdk-dev] [PATCH 1/3] ethdev: fix miss input validation in module EEPROM dump API
  2021-03-27  7:38 [dpdk-dev] [PATCH 0/3] fix miss input validation Min Hu (Connor)
@ 2021-03-27  7:38 ` Min Hu (Connor)
  2021-04-01 15:15   ` Ferruh Yigit
  2021-03-27  7:38 ` [dpdk-dev] [PATCH 2/3] ethdev: fix miss input validation when access reg info Min Hu (Connor)
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Min Hu (Connor) @ 2021-03-27  7:38 UTC (permalink / raw)
  To: dev; +Cc: ferruh.yigit, thomas, andrew.rybchenko

From: Chengchang Tang <tangchengchang@huawei.com>

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 <tangchengchang@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 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.
  */
-- 
2.7.4


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

* [dpdk-dev] [PATCH 2/3] ethdev: fix miss input validation when access reg info
  2021-03-27  7:38 [dpdk-dev] [PATCH 0/3] fix miss input validation Min Hu (Connor)
  2021-03-27  7:38 ` [dpdk-dev] [PATCH 1/3] ethdev: fix miss input validation in module EEPROM dump API Min Hu (Connor)
@ 2021-03-27  7:38 ` Min Hu (Connor)
  2021-04-01 15:15   ` Ferruh Yigit
  2021-03-27  7:38 ` [dpdk-dev] [PATCH 3/3] ethdev: fix miss input validation when access EEPROM info Min Hu (Connor)
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Min Hu (Connor) @ 2021-03-27  7:38 UTC (permalink / raw)
  To: dev; +Cc: ferruh.yigit, thomas, andrew.rybchenko

From: Chengchang Tang <tangchengchang@huawei.com>

This patch adds validity check of input pointer in regs dump API.

Fixes: 7a3f27cbf59b ("ethdev: add access to specific device info")
Fixes: 936eda25e8da ("net/hns3: support dump register")
Cc: stable@dpdk.org

Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 drivers/net/hns3/hns3_regs.c   | 5 -----
 lib/librte_ethdev/rte_ethdev.c | 2 ++
 lib/librte_ethdev/rte_ethdev.h | 1 +
 3 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/hns3/hns3_regs.c b/drivers/net/hns3/hns3_regs.c
index 4022bb9..f23e5c2 100644
--- a/drivers/net/hns3/hns3_regs.c
+++ b/drivers/net/hns3/hns3_regs.c
@@ -484,11 +484,6 @@ hns3_get_regs(struct rte_eth_dev *eth_dev, struct rte_dev_reg_info *regs)
 	uint32_t *data;
 	int ret;
 
-	if (regs == NULL) {
-		hns3_err(hw, "the input parameter regs is NULL!");
-		return -EINVAL;
-	}
-
 	ret = hns3_get_regs_length(hw, &length);
 	if (ret)
 		return ret;
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index bb195ab..3fe200d 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -5286,6 +5286,8 @@ rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	if (info == NULL)
+		return -EINVAL;
 
 	dev = &rte_eth_devices[port_id];
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
index 78677a5..5747307 100644
--- a/lib/librte_ethdev/rte_ethdev.h
+++ b/lib/librte_ethdev/rte_ethdev.h
@@ -4397,6 +4397,7 @@ int rte_eth_get_monitor_addr(uint16_t port_id, uint16_t queue_id,
  * @return
  *   - (0) if successful.
  *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-EINVAL) if bad parameter.
  *   - (-ENODEV) if *port_id* invalid.
  *   - (-EIO) if device is removed.
  *   - others depends on the specific operations implementation.
-- 
2.7.4


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

* [dpdk-dev] [PATCH 3/3] ethdev: fix miss input validation when access EEPROM info
  2021-03-27  7:38 [dpdk-dev] [PATCH 0/3] fix miss input validation Min Hu (Connor)
  2021-03-27  7:38 ` [dpdk-dev] [PATCH 1/3] ethdev: fix miss input validation in module EEPROM dump API Min Hu (Connor)
  2021-03-27  7:38 ` [dpdk-dev] [PATCH 2/3] ethdev: fix miss input validation when access reg info Min Hu (Connor)
@ 2021-03-27  7:38 ` Min Hu (Connor)
  2021-04-01 15:27   ` Ferruh Yigit
  2021-04-01 15:37 ` [dpdk-dev] [PATCH 0/3] fix miss input validation Ferruh Yigit
  2021-04-02  2:58 ` [dpdk-dev] [PATCH v2 " Min Hu (Connor)
  4 siblings, 1 reply; 15+ messages in thread
From: Min Hu (Connor) @ 2021-03-27  7:38 UTC (permalink / raw)
  To: dev; +Cc: ferruh.yigit, thomas, andrew.rybchenko

From: Chengchang Tang <tangchengchang@huawei.com>

This patch adds validity check of input pointer in EEPROM dump API.

Fixes: 7a3f27cbf59b ("ethdev: add access to specific device info")
Cc: stable@dpdk.org

Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 lib/librte_ethdev/rte_ethdev.c | 4 ++++
 lib/librte_ethdev/rte_ethdev.h | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 3fe200d..6b5cfd6 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -5312,6 +5312,8 @@ rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	if (info == NULL)
+		return -EINVAL;
 
 	dev = &rte_eth_devices[port_id];
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
@@ -5324,6 +5326,8 @@ rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	if (info == NULL)
+		return -EINVAL;
 
 	dev = &rte_eth_devices[port_id];
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
index 5747307..1a0382e 100644
--- a/lib/librte_ethdev/rte_ethdev.h
+++ b/lib/librte_ethdev/rte_ethdev.h
@@ -4429,6 +4429,7 @@ int rte_eth_dev_get_eeprom_length(uint16_t port_id);
  * @return
  *   - (0) if successful.
  *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-EINVAL) if bad parameter.
  *   - (-ENODEV) if *port_id* invalid.
  *   - (-EIO) if device is removed.
  *   - others depends on the specific operations implementation.
@@ -4490,6 +4491,7 @@ rte_eth_dev_get_module_info(uint16_t port_id,
  * @return
  *   - (0) if successful.
  *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-EINVAL) if bad parameter.
  *   - (-ENODEV) if *port_id* invalid.
  *   - (-EIO) if device is removed.
  *   - others depends on the specific operations implementation.
-- 
2.7.4


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

* Re: [dpdk-dev] [PATCH 1/3] ethdev: fix miss input validation in module EEPROM dump API
  2021-03-27  7:38 ` [dpdk-dev] [PATCH 1/3] ethdev: fix miss input validation in module EEPROM dump API Min Hu (Connor)
@ 2021-04-01 15:15   ` Ferruh Yigit
  0 siblings, 0 replies; 15+ messages in thread
From: Ferruh Yigit @ 2021-04-01 15:15 UTC (permalink / raw)
  To: Min Hu (Connor), dev; +Cc: thomas, andrew.rybchenko

On 3/27/2021 7:38 AM, Min Hu (Connor) wrote:
> From: Chengchang Tang <tangchengchang@huawei.com>
> 
> 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 <tangchengchang@huawei.com>
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>

Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>


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

* Re: [dpdk-dev] [PATCH 2/3] ethdev: fix miss input validation when access reg info
  2021-03-27  7:38 ` [dpdk-dev] [PATCH 2/3] ethdev: fix miss input validation when access reg info Min Hu (Connor)
@ 2021-04-01 15:15   ` Ferruh Yigit
  0 siblings, 0 replies; 15+ messages in thread
From: Ferruh Yigit @ 2021-04-01 15:15 UTC (permalink / raw)
  To: Min Hu (Connor), dev; +Cc: thomas, andrew.rybchenko

On 3/27/2021 7:38 AM, Min Hu (Connor) wrote:
> From: Chengchang Tang <tangchengchang@huawei.com>
> 
> This patch adds validity check of input pointer in regs dump API.
> 
> Fixes: 7a3f27cbf59b ("ethdev: add access to specific device info")
> Fixes: 936eda25e8da ("net/hns3: support dump register")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>

Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>

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

* Re: [dpdk-dev] [PATCH 3/3] ethdev: fix miss input validation when access EEPROM info
  2021-03-27  7:38 ` [dpdk-dev] [PATCH 3/3] ethdev: fix miss input validation when access EEPROM info Min Hu (Connor)
@ 2021-04-01 15:27   ` Ferruh Yigit
  0 siblings, 0 replies; 15+ messages in thread
From: Ferruh Yigit @ 2021-04-01 15:27 UTC (permalink / raw)
  To: Min Hu (Connor), dev; +Cc: thomas, andrew.rybchenko

On 3/27/2021 7:38 AM, Min Hu (Connor) wrote:
> From: Chengchang Tang <tangchengchang@huawei.com>
> 
> This patch adds validity check of input pointer in EEPROM dump API.
> 
> Fixes: 7a3f27cbf59b ("ethdev: add access to specific device info")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>

Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>


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

* Re: [dpdk-dev] [PATCH 0/3] fix miss input validation
  2021-03-27  7:38 [dpdk-dev] [PATCH 0/3] fix miss input validation Min Hu (Connor)
                   ` (2 preceding siblings ...)
  2021-03-27  7:38 ` [dpdk-dev] [PATCH 3/3] ethdev: fix miss input validation when access EEPROM info Min Hu (Connor)
@ 2021-04-01 15:37 ` Ferruh Yigit
  2021-04-02  2:59   ` Min Hu (Connor)
  2021-04-02  2:58 ` [dpdk-dev] [PATCH v2 " Min Hu (Connor)
  4 siblings, 1 reply; 15+ messages in thread
From: Ferruh Yigit @ 2021-04-01 15:37 UTC (permalink / raw)
  To: Min Hu (Connor), dev; +Cc: thomas, andrew.rybchenko

On 3/27/2021 7:38 AM, Min Hu (Connor) wrote:
> The validity verification of input parameters should be performed at
> API layer, not in the PMD.
> 
> This set of patches fix miss input validation.
> 
> Chengchang Tang (3):
>    ethdev: fix miss input validation in module EEPROM dump API
>    ethdev: fix miss input validation when access reg info
>    ethdev: fix miss input validation when access EEPROM info
> 

The function updated in ethdev header file, and the ethdev .c file seems mixes 
within the patches [1], can you please send a new version to fix it, you can 
keep the acks to this version.

[1]
1/3:
* in .h: 'rte_eth_dev_get_module_info()', 'rte_eth_dev_set_eeprom()'
* in .c: 'rte_eth_dev_get_module_info()', 'rte_eth_dev_get_module_eeprom()'

3/3:
* in .h: 'rte_eth_dev_get_eeprom()', 'rte_eth_dev_get_module_eeprom()'
* in .c: 'rte_eth_dev_get_eeprom()', 'rte_eth_dev_set_eeprom()'

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

* [dpdk-dev] [PATCH v2 0/3] fix miss input validation
  2021-03-27  7:38 [dpdk-dev] [PATCH 0/3] fix miss input validation Min Hu (Connor)
                   ` (3 preceding siblings ...)
  2021-04-01 15:37 ` [dpdk-dev] [PATCH 0/3] fix miss input validation Ferruh Yigit
@ 2021-04-02  2:58 ` Min Hu (Connor)
  2021-04-02  2:58   ` [dpdk-dev] [PATCH v2 1/3] ethdev: fix miss input validation in module EEPROM dump API Min Hu (Connor)
                     ` (3 more replies)
  4 siblings, 4 replies; 15+ messages in thread
From: Min Hu (Connor) @ 2021-04-02  2:58 UTC (permalink / raw)
  To: dev; +Cc: ferruh.yigit

The validity verification of input parameters should be performed at
API layer, not in the PMD.

This set of patches fix miss input validation.
---
v2:
* Fixed mixes in ethdev header file and ethdev .c file.

Chengchang Tang (3):
  ethdev: fix miss input validation in module EEPROM dump API
  ethdev: fix miss input validation when access reg info
  ethdev: fix miss input validation when access EEPROM info

 drivers/net/e1000/igb_ethdev.c          |  3 ---
 drivers/net/hns3/hns3_regs.c            |  5 -----
 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          | 10 ++++++++++
 lib/librte_ethdev/rte_ethdev.h          |  5 +++++
 8 files changed, 18 insertions(+), 18 deletions(-)

-- 
2.7.4


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

* [dpdk-dev] [PATCH v2 1/3] ethdev: fix miss input validation in module EEPROM dump API
  2021-04-02  2:58 ` [dpdk-dev] [PATCH v2 " Min Hu (Connor)
@ 2021-04-02  2:58   ` Min Hu (Connor)
  2021-04-02  2:58   ` [dpdk-dev] [PATCH v2 2/3] ethdev: fix miss input validation when access reg info Min Hu (Connor)
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 15+ messages in thread
From: Min Hu (Connor) @ 2021-04-02  2:58 UTC (permalink / raw)
  To: dev; +Cc: ferruh.yigit

From: Chengchang Tang <tangchengchang@huawei.com>

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 <tangchengchang@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 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 17ee6e9..5981e95 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -5119,9 +5119,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 fcf150e..41cb8ce 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -11659,9 +11659,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 31faff0..5dd063c 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -7330,9 +7330,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 e8aaa0d..bca0a36 100644
--- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c
+++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
@@ -1197,7 +1197,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;
@@ -1231,7 +1231,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 9e3f809..6f0cdc5 100644
--- a/drivers/net/octeontx2/otx2_ethdev_ops.c
+++ b/drivers/net/octeontx2/otx2_ethdev_ops.c
@@ -520,8 +520,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..7cdb3fa 100644
--- a/lib/librte_ethdev/rte_ethdev.h
+++ b/lib/librte_ethdev/rte_ethdev.h
@@ -4465,6 +4465,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.
  */
@@ -4487,6 +4488,7 @@ rte_eth_dev_get_module_info(uint16_t port_id,
  * @return
  *   - (0) if successful.
  *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-EINVAL) if bad parameter.
  *   - (-ENODEV) if *port_id* invalid.
  *   - (-EIO) if device is removed.
  *   - others depends on the specific operations implementation.
-- 
2.7.4


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

* [dpdk-dev] [PATCH v2 2/3] ethdev: fix miss input validation when access reg info
  2021-04-02  2:58 ` [dpdk-dev] [PATCH v2 " Min Hu (Connor)
  2021-04-02  2:58   ` [dpdk-dev] [PATCH v2 1/3] ethdev: fix miss input validation in module EEPROM dump API Min Hu (Connor)
@ 2021-04-02  2:58   ` Min Hu (Connor)
  2021-04-02  2:58   ` [dpdk-dev] [PATCH v2 3/3] ethdev: fix miss input validation when access EEPROM info Min Hu (Connor)
  2021-04-06  7:53   ` [dpdk-dev] [PATCH v2 0/3] fix miss input validation Ferruh Yigit
  3 siblings, 0 replies; 15+ messages in thread
From: Min Hu (Connor) @ 2021-04-02  2:58 UTC (permalink / raw)
  To: dev; +Cc: ferruh.yigit

From: Chengchang Tang <tangchengchang@huawei.com>

This patch adds validity check of input pointer in regs dump API.

Fixes: 7a3f27cbf59b ("ethdev: add access to specific device info")
Fixes: 936eda25e8da ("net/hns3: support dump register")
Cc: stable@dpdk.org

Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 drivers/net/hns3/hns3_regs.c   | 5 -----
 lib/librte_ethdev/rte_ethdev.c | 2 ++
 lib/librte_ethdev/rte_ethdev.h | 1 +
 3 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/hns3/hns3_regs.c b/drivers/net/hns3/hns3_regs.c
index 4022bb9..f23e5c2 100644
--- a/drivers/net/hns3/hns3_regs.c
+++ b/drivers/net/hns3/hns3_regs.c
@@ -484,11 +484,6 @@ hns3_get_regs(struct rte_eth_dev *eth_dev, struct rte_dev_reg_info *regs)
 	uint32_t *data;
 	int ret;
 
-	if (regs == NULL) {
-		hns3_err(hw, "the input parameter regs is NULL!");
-		return -EINVAL;
-	}
-
 	ret = hns3_get_regs_length(hw, &length);
 	if (ret)
 		return ret;
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index bb195ab..3fe200d 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -5286,6 +5286,8 @@ rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	if (info == NULL)
+		return -EINVAL;
 
 	dev = &rte_eth_devices[port_id];
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
index 7cdb3fa..554d11f 100644
--- a/lib/librte_ethdev/rte_ethdev.h
+++ b/lib/librte_ethdev/rte_ethdev.h
@@ -4397,6 +4397,7 @@ int rte_eth_get_monitor_addr(uint16_t port_id, uint16_t queue_id,
  * @return
  *   - (0) if successful.
  *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-EINVAL) if bad parameter.
  *   - (-ENODEV) if *port_id* invalid.
  *   - (-EIO) if device is removed.
  *   - others depends on the specific operations implementation.
-- 
2.7.4


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

* [dpdk-dev] [PATCH v2 3/3] ethdev: fix miss input validation when access EEPROM info
  2021-04-02  2:58 ` [dpdk-dev] [PATCH v2 " Min Hu (Connor)
  2021-04-02  2:58   ` [dpdk-dev] [PATCH v2 1/3] ethdev: fix miss input validation in module EEPROM dump API Min Hu (Connor)
  2021-04-02  2:58   ` [dpdk-dev] [PATCH v2 2/3] ethdev: fix miss input validation when access reg info Min Hu (Connor)
@ 2021-04-02  2:58   ` Min Hu (Connor)
  2021-04-06  7:53   ` [dpdk-dev] [PATCH v2 0/3] fix miss input validation Ferruh Yigit
  3 siblings, 0 replies; 15+ messages in thread
From: Min Hu (Connor) @ 2021-04-02  2:58 UTC (permalink / raw)
  To: dev; +Cc: ferruh.yigit

From: Chengchang Tang <tangchengchang@huawei.com>

This patch adds validity check of input pointer in EEPROM dump API.

Fixes: 7a3f27cbf59b ("ethdev: add access to specific device info")
Cc: stable@dpdk.org

Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 lib/librte_ethdev/rte_ethdev.c | 4 ++++
 lib/librte_ethdev/rte_ethdev.h | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 3fe200d..6b5cfd6 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -5312,6 +5312,8 @@ rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	if (info == NULL)
+		return -EINVAL;
 
 	dev = &rte_eth_devices[port_id];
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
@@ -5324,6 +5326,8 @@ rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	if (info == NULL)
+		return -EINVAL;
 
 	dev = &rte_eth_devices[port_id];
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
index 554d11f..1a0382e 100644
--- a/lib/librte_ethdev/rte_ethdev.h
+++ b/lib/librte_ethdev/rte_ethdev.h
@@ -4429,6 +4429,7 @@ int rte_eth_dev_get_eeprom_length(uint16_t port_id);
  * @return
  *   - (0) if successful.
  *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-EINVAL) if bad parameter.
  *   - (-ENODEV) if *port_id* invalid.
  *   - (-EIO) if device is removed.
  *   - others depends on the specific operations implementation.
@@ -4447,6 +4448,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.
  */
-- 
2.7.4


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

* Re: [dpdk-dev] [PATCH 0/3] fix miss input validation
  2021-04-01 15:37 ` [dpdk-dev] [PATCH 0/3] fix miss input validation Ferruh Yigit
@ 2021-04-02  2:59   ` Min Hu (Connor)
  0 siblings, 0 replies; 15+ messages in thread
From: Min Hu (Connor) @ 2021-04-02  2:59 UTC (permalink / raw)
  To: Ferruh Yigit, dev; +Cc: thomas, andrew.rybchenko



在 2021/4/1 23:37, Ferruh Yigit 写道:
> On 3/27/2021 7:38 AM, Min Hu (Connor) wrote:
>> The validity verification of input parameters should be performed at
>> API layer, not in the PMD.
>>
>> This set of patches fix miss input validation.
>>
>> Chengchang Tang (3):
>>    ethdev: fix miss input validation in module EEPROM dump API
>>    ethdev: fix miss input validation when access reg info
>>    ethdev: fix miss input validation when access EEPROM info
>>
> 
> The function updated in ethdev header file, and the ethdev .c file seems 
> mixes within the patches [1], can you please send a new version to fix 
> it, you can keep the acks to this version.
> 
> [1]
> 1/3:
> * in .h: 'rte_eth_dev_get_module_info()', 'rte_eth_dev_set_eeprom()'
> * in .c: 'rte_eth_dev_get_module_info()', 'rte_eth_dev_get_module_eeprom()'
> 
> 3/3:
> * in .h: 'rte_eth_dev_get_eeprom()', 'rte_eth_dev_get_module_eeprom()'
> * in .c: 'rte_eth_dev_get_eeprom()', 'rte_eth_dev_set_eeprom()'
> .
Thanks Ferruh,
   Fixed done in v2.

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

* Re: [dpdk-dev] [PATCH v2 0/3] fix miss input validation
  2021-04-02  2:58 ` [dpdk-dev] [PATCH v2 " Min Hu (Connor)
                     ` (2 preceding siblings ...)
  2021-04-02  2:58   ` [dpdk-dev] [PATCH v2 3/3] ethdev: fix miss input validation when access EEPROM info Min Hu (Connor)
@ 2021-04-06  7:53   ` Ferruh Yigit
  2021-04-07 22:28     ` Ferruh Yigit
  3 siblings, 1 reply; 15+ messages in thread
From: Ferruh Yigit @ 2021-04-06  7:53 UTC (permalink / raw)
  To: Min Hu (Connor), dev; +Cc: Thomas Monjalon, Andrew Rybchenko

On 4/2/2021 3:58 AM, Min Hu (Connor) wrote:
> The validity verification of input parameters should be performed at
> API layer, not in the PMD.
> 
> This set of patches fix miss input validation.
> ---
> v2:
> * Fixed mixes in ethdev header file and ethdev .c file.
> 
> Chengchang Tang (3):
>    ethdev: fix miss input validation in module EEPROM dump API
>    ethdev: fix miss input validation when access reg info
>    ethdev: fix miss input validation when access EEPROM info
> 

For series,
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>

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

* Re: [dpdk-dev] [PATCH v2 0/3] fix miss input validation
  2021-04-06  7:53   ` [dpdk-dev] [PATCH v2 0/3] fix miss input validation Ferruh Yigit
@ 2021-04-07 22:28     ` Ferruh Yigit
  0 siblings, 0 replies; 15+ messages in thread
From: Ferruh Yigit @ 2021-04-07 22:28 UTC (permalink / raw)
  To: Min Hu (Connor), dev; +Cc: Thomas Monjalon, Andrew Rybchenko

On 4/6/2021 8:53 AM, Ferruh Yigit wrote:
> On 4/2/2021 3:58 AM, Min Hu (Connor) wrote:
>> The validity verification of input parameters should be performed at
>> API layer, not in the PMD.
>>
>> This set of patches fix miss input validation.
>> ---
>> v2:
>> * Fixed mixes in ethdev header file and ethdev .c file.
>>
>> Chengchang Tang (3):
>>    ethdev: fix miss input validation in module EEPROM dump API
>>    ethdev: fix miss input validation when access reg info
>>    ethdev: fix miss input validation when access EEPROM info
>>
> 
> For series,
> Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>

Series applied to dpdk-next-net/main, thanks.

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

end of thread, other threads:[~2021-04-07 22:28 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-27  7:38 [dpdk-dev] [PATCH 0/3] fix miss input validation Min Hu (Connor)
2021-03-27  7:38 ` [dpdk-dev] [PATCH 1/3] ethdev: fix miss input validation in module EEPROM dump API Min Hu (Connor)
2021-04-01 15:15   ` Ferruh Yigit
2021-03-27  7:38 ` [dpdk-dev] [PATCH 2/3] ethdev: fix miss input validation when access reg info Min Hu (Connor)
2021-04-01 15:15   ` Ferruh Yigit
2021-03-27  7:38 ` [dpdk-dev] [PATCH 3/3] ethdev: fix miss input validation when access EEPROM info Min Hu (Connor)
2021-04-01 15:27   ` Ferruh Yigit
2021-04-01 15:37 ` [dpdk-dev] [PATCH 0/3] fix miss input validation Ferruh Yigit
2021-04-02  2:59   ` Min Hu (Connor)
2021-04-02  2:58 ` [dpdk-dev] [PATCH v2 " Min Hu (Connor)
2021-04-02  2:58   ` [dpdk-dev] [PATCH v2 1/3] ethdev: fix miss input validation in module EEPROM dump API Min Hu (Connor)
2021-04-02  2:58   ` [dpdk-dev] [PATCH v2 2/3] ethdev: fix miss input validation when access reg info Min Hu (Connor)
2021-04-02  2:58   ` [dpdk-dev] [PATCH v2 3/3] ethdev: fix miss input validation when access EEPROM info Min Hu (Connor)
2021-04-06  7:53   ` [dpdk-dev] [PATCH v2 0/3] fix miss input validation Ferruh Yigit
2021-04-07 22:28     ` Ferruh Yigit

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