From: Wei Hu (Xavier) Date: Tue, 13 Oct 2020 11:50:54 +0000 (+0800) Subject: ethdev: check if queue setup in queue-related APIs X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=83e813ec2a719d8e4c00199acc3f13cb2ad3d838;p=dpdk.git ethdev: check if queue setup in queue-related APIs This patch adds checking whether the related Tx or Rx queue has been setup in the queue-related API functions to avoid illegal address access. Signed-off-by: Chengchang Tang Signed-off-by: Wei Hu (Xavier) Signed-off-by: Chengwen Feng Acked-by: Stephen Hemminger Reviewed-by: Kalesh AP Reviewed-by: Ferruh Yigit --- diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 0fdbd526bf..11d6d993f5 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -892,6 +892,14 @@ eth_dev_validate_rx_queue(const struct rte_eth_dev *dev, uint16_t rx_queue_id) return -EINVAL; } + if (dev->data->rx_queues[rx_queue_id] == NULL) { + port_id = dev->data->port_id; + RTE_ETHDEV_LOG(ERR, + "Queue %u of device with port_id=%u has not been setup\n", + rx_queue_id, port_id); + return -EINVAL; + } + return 0; } @@ -908,6 +916,14 @@ eth_dev_validate_tx_queue(const struct rte_eth_dev *dev, uint16_t tx_queue_id) return -EINVAL; } + if (dev->data->tx_queues[tx_queue_id] == NULL) { + port_id = dev->data->port_id; + RTE_ETHDEV_LOG(ERR, + "Queue %u of device with port_id=%u has not been setup\n", + tx_queue_id, port_id); + return -EINVAL; + } + return 0; } diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h index 4f4196ba89..f07dbc4d26 100644 --- a/lib/librte_ethdev/rte_ethdev.h +++ b/lib/librte_ethdev/rte_ethdev.h @@ -4723,7 +4723,8 @@ rte_eth_rx_queue_count(uint16_t port_id, uint16_t queue_id) RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); dev = &rte_eth_devices[port_id]; RTE_FUNC_PTR_OR_ERR_RET(*dev->rx_queue_count, -ENOTSUP); - if (queue_id >= dev->data->nb_rx_queues) + if (queue_id >= dev->data->nb_rx_queues || + dev->data->rx_queues[queue_id] == NULL) return -EINVAL; return (int)(*dev->rx_queue_count)(dev, queue_id);