Skip to contentSkip to conversation

net/mlx5: Fix null-ptr-deref in TTC table creation

PATCH Superseded Henry Martin 4 participants 6 messages Apr 11, 2025 – Apr 15, 2025

Subsystems (4)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover net/mlx5: Fix null-ptr-deref in TTC table creation

This patch fixes a NULL pointer dereference in mlx5_create_{inner_,}ttc_table() by adding NULL checks for mlx5_get_flow_namespace() return values.

Henry Martin (1):
net/mlx5: Fix null-ptr-deref in mlx5_create_{inner_,}ttc_table()

 drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/1 net/mlx5: Fix null-ptr-deref in mlx5_create_{inner_,}ttc_table()

Add NULL check for mlx5_get_flow_namespace() returns in mlx5_create_inner_ttc_table() and mlx5_create_ttc_table() to prevent NULL pointer dereference.

Fixes 137f3d50ad2a ("net/mlx5: Support matching on l4_type for ttc_table")

---
V3 -> V4: Fix potential memory leak.
V2 -> V3: No functional changes, just gathering the patches in a series. V1 -> V2: Add a empty line after the return statement.

 drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +12 -0
index eb3bd9c7f66e..077fe908bf86 100644
@@ -651,10 +651,16 @@ struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev,
 			MLX5_CAP_NIC_RX_FT_FIELD_SUPPORT_2(dev, inner_l4_type);
 		break;
 	default:
+		kvfree(ttc);
 		return ERR_PTR(-EINVAL);
 	}
 
 	ns = mlx5_get_flow_namespace(dev, params->ns_type);
+	if (!ns) {
+		kvfree(ttc);
+		return ERR_PTR(-EOPNOTSUPP);
+	}
+
 	groups = use_l4_type ? &inner_ttc_groups[TTC_GROUPS_USE_L4_TYPE] :
 			       &inner_ttc_groups[TTC_GROUPS_DEFAULT];
 
@@ -724,10 +730,16 @@ struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev,
 			MLX5_CAP_NIC_RX_FT_FIELD_SUPPORT_2(dev, outer_l4_type);
 		break;
 	default:
+		kvfree(ttc);
 		return ERR_PTR(-EINVAL);
 	}
 
 	ns = mlx5_get_flow_namespace(dev, params->ns_type);
+	if (!ns){
+		kvfree(ttc);
+		return ERR_PTR(-EOPNOTSUPP);
+	}
+
 	groups = use_l4_type ? &ttc_groups[TTC_GROUPS_USE_L4_TYPE] :
 			       &ttc_groups[TTC_GROUPS_DEFAULT];
 
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v4] net/mlx5: Fix null-ptr-deref in mlx5_create_{inner_,}ttc_table()

Quoted 3 lines

Add NULL check for mlx5_get_flow_namespace() returns in mlx5_create_inner_ttc_table() and mlx5_create_ttc_table() to prevent NULL pointer dereference.

Can any other summary phrase variants become more desirable accordingly?

…

Quoted 2 lines

---
V3 -> V4: Fix potential memory leak.

* Do you propose to complete the error handling for more function implementations?

* Please avoid duplicate source code.

* Can an other enumeration style become nicer for version numbers?

Quoted 1 line

V2 -> V3: No functional changes, just gathering the patches in a series.

Would you usually expect more than one update step then?

Regards,
Markus

Reviewed-by on v4 1/1
#3 lore raw

Re: [PATCH v4 1/1] net/mlx5: Fix null-ptr-deref in mlx5_create_{inner_,}ttc_table()

In reply to Henry Martin
Quoted 41 lines · Henry Martin

Add NULL check for mlx5_get_flow_namespace() returns in mlx5_create_inner_ttc_table() and mlx5_create_ttc_table() to prevent NULL pointer dereference.

Fixes 137f3d50ad2a ("net/mlx5: Support matching on l4_type for ttc_table")

---
V3 -> V4: Fix potential memory leak.
V2 -> V3: No functional changes, just gathering the patches in a series. V1 -> V2: Add a empty line after the return statement.

 drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +7 -0
index eb3bd9c7f66e..077fe908bf86 100644
@@ -651,10 +651,16 @@ struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev,
 			MLX5_CAP_NIC_RX_FT_FIELD_SUPPORT_2(dev, inner_l4_type);
 		break;
 	default:
+		kvfree(ttc);
 		return ERR_PTR(-EINVAL);
 	}
 
 	ns = mlx5_get_flow_namespace(dev, params->ns_type);
+	if (!ns) {
+		kvfree(ttc);
+		return ERR_PTR(-EOPNOTSUPP);
+	}
+
 	groups = use_l4_type ? &inner_ttc_groups[TTC_GROUPS_USE_L4_TYPE] :
 			       &inner_ttc_groups[TTC_GROUPS_DEFAULT];
 
@@ -724,10 +730,16 @@ struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev,
 			MLX5_CAP_NIC_RX_FT_FIELD_SUPPORT_2(dev, outer_l4_type);
 		break;
 	default:
+		kvfree(ttc);
 		return ERR_PTR(-EINVAL);

drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev, · line 744

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +5 -0
 	}
 
 	ns = mlx5_get_flow_namespace(dev, params->ns_type);
+	if (!ns){
+		kvfree(ttc);
+		return ERR_PTR(-EOPNOTSUPP);
+	}
+
 	groups = use_l4_type ? &ttc_groups[TTC_GROUPS_USE_L4_TYPE] :
 			       &ttc_groups[TTC_GROUPS_DEFAULT];

Thanks for addressing leak

Quoted 3 lines
Signature · 2 lines
-- 
2.34.1
#4 lore raw

Re: [PATCH v4 1/1] net/mlx5: Fix null-ptr-deref in mlx5_create_{inner_,}ttc_table()

In reply to Henry Martin
Quoted 19 lines · Henry Martin

Add NULL check for mlx5_get_flow_namespace() returns in mlx5_create_inner_ttc_table() and mlx5_create_ttc_table() to prevent NULL pointer dereference.

Fixes 137f3d50ad2a ("net/mlx5: Support matching on l4_type for ttc_table")

---
V3 -> V4: Fix potential memory leak.
V2 -> V3: No functional changes, just gathering the patches in a series. V1 -> V2: Add a empty line after the return statement.

  drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c | 12 ++++++++++++
  1 file changed, 12 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +0 -0
index eb3bd9c7f66e..077fe908bf86 100644

drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev, · line 654

Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +1 -0
@@ -651,10 +651,16 @@ struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev,
  			MLX5_CAP_NIC_RX_FT_FIELD_SUPPORT_2(dev, inner_l4_type);
  		break;
  	default:
+		kvfree(ttc);

Unrelated change.
Not described in patch subject or commit message.
Please introduce in a separate patch.

Quoted 13 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +5 -0
  		return ERR_PTR(-EINVAL);
  	}
 
  	ns = mlx5_get_flow_namespace(dev, params->ns_type);
+	if (!ns) {
+		kvfree(ttc);
+		return ERR_PTR(-EOPNOTSUPP);
+	}
+
  	groups = use_l4_type ? &inner_ttc_groups[TTC_GROUPS_USE_L4_TYPE] :
  			       &inner_ttc_groups[TTC_GROUPS_DEFAULT];
 

drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev, · line 733

Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +1 -0
@@ -724,10 +730,16 @@ struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev,
  			MLX5_CAP_NIC_RX_FT_FIELD_SUPPORT_2(dev, outer_l4_type);
  		break;
  	default:
+		kvfree(ttc);

Same.

Quoted 12 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +5 -0
  		return ERR_PTR(-EINVAL);
  	}
 
  	ns = mlx5_get_flow_namespace(dev, params->ns_type);
+	if (!ns){
+		kvfree(ttc);
+		return ERR_PTR(-EOPNOTSUPP);
+	}
+
  	groups = use_l4_type ? &ttc_groups[TTC_GROUPS_USE_L4_TYPE] :
  			       &ttc_groups[TTC_GROUPS_DEFAULT];