[v2] ethdev: check queue stats mapping input arguments

Message ID 1531298519-8033-1-git-send-email-kkokkilagadda@caviumnetworks.com (mailing list archive)
State Accepted, archived
Headers
Series [v2] ethdev: check queue stats mapping input arguments |

Checks

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

Commit Message

Kiran Kumar July 11, 2018, 8:41 a.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>
Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>
---
 v2 changes:
 - changed summery

 lib/librte_ethdev/rte_ethdev.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

--
2.7.4
  

Comments

Thomas Monjalon July 13, 2018, 10:10 p.m. UTC | #1
11/07/2018 10:41, Kiran Kumar:
> 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>
> Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>

Applied, thanks
  

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);
 }