net/mlx5: Fix NULL dereference and memory leak in ttc_table creation
Subsystems (4)
v7 cover net/mlx5: Fix NULL dereference and memory leak in ttc_table creation
This patch series addresses two issues in the mlx5_create_inner_ttc_table() and mlx5_create_ttc_table() functions:
1. A potential NULL pointer dereference if mlx5_get_flow_namespace() returns NULL.
2. A memory leak in the error path when ttc_type is invalid (default:
switch case).
Henry Martin (2):
net/mlx5: Fix null-ptr-deref in mlx5_create_{inner_,}ttc_table() net/mlx5: Move ttc allocation after switch case to prevent leaks
.../ethernet/mellanox/mlx5/core/lib/fs_ttc.c | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-)
Signature · 1 line
2.34.1
PATCH v7 1/2 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.
--- drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +10 -0
@@ -655,6 +655,11 @@ 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) { +kvfree (ttc); +return ERR_PTR (-EOPNOTSUPP ); + } + groups = use_l4_type ? &inner_ttc_groups[TTC_GROUPS_USE_L4_TYPE ] : &inner_ttc_groups[TTC_GROUPS_DEFAULT ];
@@ -728,6 +733,11 @@ struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev, } 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
Re: [PATCH v7 1/2] net/mlx5: Fix null-ptr-deref in mlx5_create_{inner_,}ttc_table()
Quoted 3 lines
Add NULL check for
mlx5_get_flow_namespace()returns inmlx5_create_inner_ttc_table()andmlx5_create_ttc_table()to prevent NULL pointer dereference.
* Can an other summary phrase variant become more desirable accordingly?
* Please avoid duplicate source code.
Regards,
Markus
PATCH v7 2/2 net/mlx5: Move ttc allocation after switch case to prevent leaks
In reply to Henry MartinRelocate the memory allocation for ttc table after the switch statement that validates params->ns_type in both mlx5_create_inner_ttc_table() and mlx5_create_ttc_table(). This ensures memory is only allocated after confirming valid input, eliminating potential memory leaks when invalid ns_type cases occur.
--- .../net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +8 -8
@@ -637,10 +637,6 @@ struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev,bool use_l4_type;int err; - ttc =kvzalloc (sizeof (*ttc),GFP_KERNEL ); -if (!ttc) -return ERR_PTR (-ENOMEM ); -switch (params->ns_type) {case MLX5_FLOW_NAMESPACE_PORT_SEL : use_l4_type = MLX5_CAP_GEN_2(dev, pcc_ifa2) &&
@@ -654,6 +650,10 @@ struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev,return ERR_PTR (-EINVAL ); } + ttc =kvzalloc (sizeof (*ttc),GFP_KERNEL ); +if (!ttc) +return ERR_PTR (-ENOMEM ); + ns =mlx5_get_flow_namespace (dev, params->ns_type);if (!ns) {kvfree (ttc);
@@ -715,10 +715,6 @@ struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev,bool use_l4_type;int err; - ttc =kvzalloc (sizeof (*ttc),GFP_KERNEL ); -if (!ttc) -return ERR_PTR (-ENOMEM ); -switch (params->ns_type) {case MLX5_FLOW_NAMESPACE_PORT_SEL : use_l4_type = MLX5_CAP_GEN_2(dev, pcc_ifa2) &&
@@ -732,6 +728,10 @@ struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev,return ERR_PTR (-EINVAL ); } + ttc =kvzalloc (sizeof (*ttc),GFP_KERNEL ); +if (!ttc) +return ERR_PTR (-ENOMEM ); + ns =mlx5_get_flow_namespace (dev, params->ns_type);if (!ns) {kvfree (ttc);
Signature · 1 line
2.34.1
Quoted 1 line
This patch series addresses two issues in …
Did you overlook the addition of patch version descriptions once more?
https://lore.kernel.org/all/?q=%22This+looks+like+a+new+version+of+a+previously+submitted+patch%22
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.15-rc3#n310
Regards,
Markus
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Fri, 18 Apr 2025 10:38:12 +0800 you wrote:
This patch series addresses two issues in the
mlx5_create_inner_ttc_table()andmlx5_create_ttc_table()functions:1. A potential NULL pointer dereference if
mlx5_get_flow_namespace()returns NULL.2. A memory leak in the error path when
ttc_typeis invalid (default:
switch case).[...]
Here is the summary with links:
- [v7,1/2] net/mlx5: Fix null-ptr-deref in mlx5_create_{inner_,}ttc_table()
https://git.kernel.org/netdev/net/c/91037037ee3d - [v7,2/2] net/mlx5: Move ttc allocation after switch case to prevent leaks https://git.kernel.org/netdev/net/c/fa8fd315127c
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html