Skip to content

Commit

Permalink
ethdev: fix crash on owner delete
Browse files Browse the repository at this point in the history
[ upstream commit b7ade5d ]

'eth_dev->data' can be null before ethdev allocated. The API walks
through all eth devices, at least for some data can be null.

Adding 'eth_dev->data' null check before accessing it.

Fixes: 33c73aa ("ethdev: allow ownership operations on unused port")

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Chenbo Xia <chenbo.xia@intel.com>
Acked-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
  • Loading branch information
Ferruh Yigit authored and cpaelzer committed Nov 30, 2021
1 parent d2b406a commit d3ccaea
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/librte_ethdev/rte_ethdev.c
Expand Up @@ -702,10 +702,13 @@ rte_eth_dev_owner_delete(const uint64_t owner_id)
rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);

if (rte_eth_is_valid_owner_id(owner_id)) {
for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++)
if (rte_eth_devices[port_id].data->owner.id == owner_id)
memset(&rte_eth_devices[port_id].data->owner, 0,
for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++) {
struct rte_eth_dev_data *data =
rte_eth_devices[port_id].data;
if (data != NULL && data->owner.id == owner_id)
memset(&data->owner, 0,
sizeof(struct rte_eth_dev_owner));
}
RTE_ETHDEV_LOG(NOTICE,
"All port owners owned by %016"PRIx64" identifier have removed\n",
owner_id);
Expand Down

0 comments on commit d3ccaea

Please sign in to comment.