Skip to content

Commit

Permalink
ethdev: validate input in module EEPROM dump
Browse files Browse the repository at this point in the history
[ upstream commit e2bd08d ]

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

Fixes: 3a18c44 ("ethdev: add access to EEPROM")
Fixes: 40ff8b3 ("net/e1000: add module EEPROM callbacks for e1000")
Fixes: f2088e7 ("net/i40e: fix dereference before check when getting EEPROM")
Fixes: b74d0cd ("net/ixgbe: add module EEPROM callbacks for ixgbe")
Fixes: 8a6a09f ("net/mlx5: support reading module EEPROM data")
Fixes: 58f6f93 ("net/octeontx2: add module EEPROM dump")

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>
  • Loading branch information
Chengchang Tang authored and cpaelzer committed May 17, 2021
1 parent 31b17ff commit d50e609
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 13 deletions.
3 changes: 0 additions & 3 deletions drivers/net/e1000/igb_ethdev.c
Expand Up @@ -5518,9 +5518,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;

Expand Down
3 changes: 0 additions & 3 deletions drivers/net/i40e/i40e_ethdev.c
Expand Up @@ -12129,9 +12129,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;

Expand Down
3 changes: 0 additions & 3 deletions drivers/net/ixgbe/ixgbe_ethdev.c
Expand Up @@ -7628,9 +7628,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);
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/mlx5/mlx5_ethdev.c
Expand Up @@ -1883,7 +1883,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;
Expand Down Expand Up @@ -1917,7 +1917,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;
Expand Down
3 changes: 1 addition & 2 deletions drivers/net/octeontx2/otx2_ethdev_ops.c
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions lib/librte_ethdev/rte_ethdev.c
Expand Up @@ -4922,6 +4922,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);
Expand All @@ -4935,6 +4937,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);
Expand Down
2 changes: 2 additions & 0 deletions lib/librte_ethdev/rte_ethdev.h
Expand Up @@ -3920,6 +3920,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.
*/
Expand All @@ -3942,6 +3943,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.
Expand Down

0 comments on commit d50e609

Please sign in to comment.