net/mlx5: restrict Rx queue array access to boundary
authorMichael Baum <michaelba@nvidia.com>
Sun, 10 Apr 2022 09:25:27 +0000 (12:25 +0300)
committerRaslan Darawsheh <rasland@nvidia.com>
Thu, 21 Apr 2022 10:47:41 +0000 (12:47 +0200)
The mlx5_rxq_get() function gets RxQ index and return RxQ priv
accordingly.

When it gets an invalid index, it accesses out of array bounds which
might cause undefined behavior.

This patch adds a check for invalid indexes before accessing to array.

Fixes: 0cedf34da78f ("net/mlx5: move Rx queue reference count")
Cc: stable@dpdk.org
Signed-off-by: Michael Baum <michaelba@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
drivers/net/mlx5/mlx5_rxq.c

index 925544a..38fde93 100644 (file)
@@ -2049,6 +2049,8 @@ mlx5_rxq_get(struct rte_eth_dev *dev, uint16_t idx)
 {
        struct mlx5_priv *priv = dev->data->dev_private;
 
+       if (idx >= priv->rxqs_n)
+               return NULL;
        MLX5_ASSERT(priv->rxq_privs != NULL);
        return (*priv->rxq_privs)[idx];
 }