net/mlx5: Fix null-ptr-deref in TTC table creation
Subsystems (4)
v3 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 | 6 ++++++ 1 file changed, 6 insertions(+)
Signature · 1 line
2.34.1
PATCH v3 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.
---
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 | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +6 -0
@@ -655,6 +655,9 @@ struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev, } ns =mlx5_get_flow_namespace (dev, params->ns_type); +if (!ns) +return ERR_PTR (-EOPNOTSUPP ); + groups = use_l4_type ? &inner_ttc_groups[TTC_GROUPS_USE_L4_TYPE ] : &inner_ttc_groups[TTC_GROUPS_DEFAULT ];
@@ -728,6 +731,9 @@ struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev, } ns =mlx5_get_flow_namespace (dev, params->ns_type); +if (!ns) +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
Re: [PATCH v3 1/1] net/mlx5: Fix null-ptr-deref in mlx5_create_{inner_,}ttc_table()
Quoted 18 lines · Henry Martin
Add NULL check for
mlx5_get_flow_namespace()returns inmlx5_create_inner_ttc_table()andmlx5_create_ttc_table()to prevent NULL pointer dereference.Fixes 137f3d50ad2a ("net/mlx5: Support matching on l4_type for ttc_table")Signed-off-by Henry Martin <[email protected]>---
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 | 6 ++++++ 1 file changed, 6 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +0
-0
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 659
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +2
-0@@ -655,6 +655,9 @@ struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev, } ns =mlx5_get_flow_namespace (dev, params->ns_type); +if (!ns) +return ERR_PTR (-EOPNOTSUPP );
There is ttc = kvzalloc() before. I think you should call kvfree(ttc) before returning. It looks like the same leak is already when params->ns_type is unknown.
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev, · line 735
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +3
-0+ groups = use_l4_type ? &inner_ttc_groups[TTC_GROUPS_USE_L4_TYPE ] : &inner_ttc_groups[TTC_GROUPS_DEFAULT ];@@ -728,6 +731,9 @@ struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev, } ns =mlx5_get_flow_namespace (dev, params->ns_type); +if (!ns) +return ERR_PTR (-EOPNOTSUPP );
The same here.
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +1
-0+ groups = use_l4_type ? &ttc_groups[TTC_GROUPS_USE_L4_TYPE ] : &ttc_groups[TTC_GROUPS_DEFAULT ];Signature · 1 line
2.34.1
Re: [PATCH v3 1/1] net/mlx5: Fix null-ptr-deref in mlx5_create_{inner_,}ttc_table()
Quoted 3 lines
There is ttc =
kvzalloc()before. I think you should call kvfree(ttc) before returning. It looks like the same leak is already whenparams->ns_typeis unknown.
Thanks for the review and the helpful suggestions!
I've addressed the kvfree(ttc) memory leak issue and updated the logic accordingly in both code paths. The updated patch has been sent out as v4.
Regards,
Henry
Quoted 49 lines · Michal Swiatkowski <[email protected]> 于2025年4月11日周五 13:34写道:
Quoted 18 lines · Henry Martin
Add NULL check for
mlx5_get_flow_namespace()returns inmlx5_create_inner_ttc_table()andmlx5_create_ttc_table()to prevent NULL pointer dereference.Fixes 137f3d50ad2a ("net/mlx5: Support matching on l4_type for ttc_table")Signed-off-by Henry Martin <[email protected]>---
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 | 6 ++++++ 1 file changed, 6 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +0
-0drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev, · line 659
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +2
-0@@ -655,6 +655,9 @@ struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev, } ns =mlx5_get_flow_namespace (dev, params->ns_type); +if (!ns) +return ERR_PTR (-EOPNOTSUPP );There is ttc =
kvzalloc()before. I think you should call kvfree(ttc) before returning. It looks like the same leak is already whenparams->ns_typeis unknown.drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev, · line 735
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +3
-0+ groups = use_l4_type ? &inner_ttc_groups[TTC_GROUPS_USE_L4_TYPE ] : &inner_ttc_groups[TTC_GROUPS_DEFAULT ];@@ -728,6 +731,9 @@ struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev, } ns =mlx5_get_flow_namespace (dev, params->ns_type); +if (!ns) +return ERR_PTR (-EOPNOTSUPP );The same here.
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +1
-1+ groups = use_l4_type ? &ttc_groups[TTC_GROUPS_USE_L4_TYPE ] : &ttc_groups[TTC_GROUPS_DEFAULT ]; --2.34.1