gre_item was dereferenced w/o checking it's value.
added a check to verify if null before using the pointer.

Fixes: 80c676259a04 ("net/mlx5: validate HWS template items")
Cc: sta...@dpdk.org

Signed-off-by: Maayan Kashani <mkash...@nvidia.com>
Acked-by: Bing Zhao <bi...@nvidia.com>
---
 drivers/net/mlx5/mlx5_flow.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index e2f4bd8cef1..93ee6f75626 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -3333,10 +3333,10 @@ mlx5_flow_validate_item_gre_key(const struct 
rte_eth_dev *dev,
                return rte_flow_error_set(error, ENOTSUP,
                                          RTE_FLOW_ERROR_TYPE_ITEM, item,
                                          "GRE key following a wrong item");
-       gre_mask = gre_item->mask;
+       gre_mask = gre_item ? gre_item->mask : NULL;
        if (!gre_mask)
                gre_mask = &rte_flow_item_gre_mask;
-       gre_spec = gre_item->spec;
+       gre_spec = gre_item ? gre_item->spec : NULL;
        if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
                         !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
                return rte_flow_error_set(error, EINVAL,
@@ -3379,8 +3379,8 @@ mlx5_flow_validate_item_gre_option(struct rte_eth_dev 
*dev,
                                   const struct rte_flow_item *gre_item,
                                   struct rte_flow_error *error)
 {
-       const struct rte_flow_item_gre *gre_spec = gre_item->spec;
-       const struct rte_flow_item_gre *gre_mask = gre_item->mask;
+       const struct rte_flow_item_gre *gre_spec = gre_item ? gre_item->spec : 
NULL;
+       const struct rte_flow_item_gre *gre_mask = gre_item ? gre_item->mask : 
NULL;
        const struct rte_flow_item_gre_opt *spec = item->spec;
        const struct rte_flow_item_gre_opt *mask = item->mask;
        struct mlx5_priv *priv = dev->data->dev_private;
-- 
2.21.0

Reply via email to