lib/librte_ethdev: Error checking for stats mapping

Message ID 1531236367-27067-1-git-send-email-kkokkilagadda@caviumnetworks.com (mailing list archive)
State Superseded, archived
Headers
Series lib/librte_ethdev: Error checking for stats mapping |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Kiran Kumar July 10, 2018, 3:26 p.m. UTC
  With current implementation, we are not checking for queue_id range
and stat_idx range in stats mapping function. This patch will add
check for queue_id and stat_idx range.

Fixes: 5de201df892 ("ethdev: add stats per queue")

Signed-off-by: Kiran Kumar <kkokkilagadda@caviumnetworks.com>
---
 lib/librte_ethdev/rte_ethdev.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
  

Comments

Andrew Rybchenko July 10, 2018, 3:54 p.m. UTC | #1
On 10.07.2018 18:26, Kiran Kumar wrote:
> With current implementation, we are not checking for queue_id range
> and stat_idx range in stats mapping function. This patch will add
> check for queue_id and stat_idx range.
>
> Fixes: 5de201df892 ("ethdev: add stats per queue")
>
> Signed-off-by: Kiran Kumar <kkokkilagadda@caviumnetworks.com>
> ---
>   lib/librte_ethdev/rte_ethdev.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
>
> diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
> index a9977df..0849016 100644
> --- a/lib/librte_ethdev/rte_ethdev.c
> +++ b/lib/librte_ethdev/rte_ethdev.c
> @@ -2457,6 +2457,16 @@ set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id, uint8_t stat_idx,
>   	dev = &rte_eth_devices[port_id];
>   
>   	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
> +
> +	if (is_rx && (queue_id >= dev->data->nb_rx_queues))
> +		return -EINVAL;
> +
> +	if (!is_rx && (queue_id >= dev->data->nb_tx_queues))
> +		return -EINVAL;
> +
> +	if (stat_idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
> +		return -EINVAL;
> +
>   	return (*dev->dev_ops->queue_stats_mapping_set)
>   			(dev, queue_id, stat_idx, is_rx);
>   }

Summary should be something like:
ethdev: check queue stats mapping input arguments

Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>
  

Patch

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index a9977df..0849016 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -2457,6 +2457,16 @@  set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id, uint8_t stat_idx,
 	dev = &rte_eth_devices[port_id];
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
+
+	if (is_rx && (queue_id >= dev->data->nb_rx_queues))
+		return -EINVAL;
+
+	if (!is_rx && (queue_id >= dev->data->nb_tx_queues))
+		return -EINVAL;
+
+	if (stat_idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
+		return -EINVAL;
+
 	return (*dev->dev_ops->queue_stats_mapping_set)
 			(dev, queue_id, stat_idx, is_rx);
 }