net/mlx5: Check dr mask size against mlx5_match_param size
authorMuhammad Sammar <muhammads@nvidia.com>
Fri, 20 Nov 2020 23:03:26 +0000 (15:03 -0800)
committerSaeed Mahameed <saeedm@nvidia.com>
Fri, 27 Nov 2020 02:43:47 +0000 (18:43 -0800)
This is to allow passing misc4 match param from userspace when
function like ib_flow_matcher_create is called.

Signed-off-by: Muhammad Sammar <muhammads@nvidia.com>
Reviewed-by: Alex Vesker <valex@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/steering/dr_matcher.c
drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c
drivers/net/ethernet/mellanox/mlx5/core/steering/dr_types.h

index 7df883686d46bb32e26ea79b4675b7293a1a7363..1b3b2acd45c548fd6886dbd98d1a078078b5f98f 100644 (file)
@@ -630,7 +630,7 @@ static int dr_matcher_init(struct mlx5dr_matcher *matcher,
        }
 
        if (mask) {
-               if (mask->match_sz > sizeof(struct mlx5dr_match_param)) {
+               if (mask->match_sz > DR_SZ_MATCH_PARAM) {
                        mlx5dr_err(dmn, "Invalid match size attribute\n");
                        return -EINVAL;
                }
index b3c9dc032026ca056609e5aac796ddbbb7f9a66d..6d73719db1f4eae7b6adf45f36dd1091de7b54fe 100644 (file)
@@ -874,8 +874,7 @@ static bool dr_rule_verify(struct mlx5dr_matcher *matcher,
        u32 s_idx, e_idx;
 
        if (!value_size ||
-           (value_size > sizeof(struct mlx5dr_match_param) ||
-            (value_size % sizeof(u32)))) {
+           (value_size > DR_SZ_MATCH_PARAM || (value_size % sizeof(u32)))) {
                mlx5dr_err(matcher->tbl->dmn, "Rule parameters length is incorrect\n");
                return false;
        }
index f50f3b107aa3172edb9c9078f3bcad12038bd14f..937f469ec678e37f4aef54c57be915239ade83c9 100644 (file)
@@ -17,6 +17,7 @@
 #define WIRE_PORT 0xFFFF
 #define DR_STE_SVLAN 0x1
 #define DR_STE_CVLAN 0x2
+#define DR_SZ_MATCH_PARAM (MLX5_ST_SZ_DW_MATCH_PARAM * 4)
 
 #define mlx5dr_err(dmn, arg...) mlx5_core_err((dmn)->mdev, ##arg)
 #define mlx5dr_info(dmn, arg...) mlx5_core_info((dmn)->mdev, ##arg)