net/mlx5: Fix null-ptr-deref in mlx5_create_inner_ttc_table()
Subsystems (4)
PATCH 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() to prevent NULL pointer dereference.
--- drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +2 -0
@@ -655,6 +655,8 @@ 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 ];
Signature · 1 line
2.34.1
Quoted 2 lines
Add NULL check for
mlx5_get_flow_namespace()returns inmlx5_create_inner_ttc_table()to prevent NULL pointer dereference.
* You would like to adjust the error handling in some function implementations from a common subdirectory.
How do you think about to offer such changes in a corresponding patch series?
* Can any other summary phrase variant become more desirable accordingly?
* Would any blank lines become also desirable after added statements?
Regards,
Markus
Paolo Abeni
maintainerQuoted 14 lines · Henry Martin
Add NULL check for
mlx5_get_flow_namespace()returns inmlx5_create_inner_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]>--- drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c | 2 ++ 1 file changed, 2 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,8 @@ 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 );
I suspect the ns_type the caller always sets a valid 'ns_type', so the NULL ptr is not really possible here.
At very least an empty line after the return statement will make the code more readable and the commit message should be rewritten to better describe the issue.
Similar considerations apply to the other mlx5 fixes.
Thanks,
Paolo
…
Quoted 10 lines
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 7 lines
+++
b/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.cdrivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +2
-0@@ -655,6 +655,8 @@ 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 );I suspect the
ns_typethe caller always sets a valid 'ns_type', so the NULL ptr is not really possible here.
Is there a need to mark such a check result as “unlikely”?
Regards,
Markus
Mark Bloch
maintainerQuoted 5 lines · Markus Elfring
…
Quoted 4 lines
Quoted 4 lines
+++
b/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c(quoted diff) +0
-0@@ -655,6 +655,8 @@ struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev, }
Quoted 9 lines
Quoted 6 lines
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 3 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +2
-0ns =mlx5_get_flow_namespace (dev, params->ns_type); +if (!ns) +return ERR_PTR (-EOPNOTSUPP );I suspect the
ns_typethe caller always sets a valid 'ns_type', so the NULL ptr is not really possible here.Is there a need to mark such a check result as “unlikely”?
Please don't. I'm fine with simply adding the check, as Paolo suggested. When TTC was originally introduced, its functionality was more limited, and reaching this point in the driver meant we could be certain the namespace existed. Now that TTC has become more advanced, adding this check makes sense and I'm okay with it.
Mark
Quoted 3 lines
Regards,
Markus
Thank you for the review. This check will be kept, and I'll follow Paolo's suggestion about adding a blank line before the return statements in the v2.
Quoted 32 lines · Mark Bloch <[email protected]> 于2025年4月8日周二 23:01写道:
Quoted 5 lines · Markus Elfring
…
Quoted 4 lines
Quoted 4 lines
+++
b/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c(quoted diff) +0
-0@@ -655,6 +655,8 @@ struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev, }Quoted 9 lines
Quoted 6 lines
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 3 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +2
-0ns =mlx5_get_flow_namespace (dev, params->ns_type); +if (!ns) +return ERR_PTR (-EOPNOTSUPP );I suspect the
ns_typethe caller always sets a valid 'ns_type', so the NULL ptr is not really possible here.Is there a need to mark such a check result as “unlikely”?
Please don't. I'm fine with simply adding the check, as Paolo suggested. When TTC was originally introduced, its functionality was more limited, and reaching this point in the driver meant we could be certain the namespace existed. Now that TTC has become more advanced, adding this check makes sense and I'm okay with it.
Mark
Quoted 3 lines
Regards,
Markus
Quoted 2 lines
Thank you for the review. This check will be kept, and I'll follow Paolo's suggestion about adding a blank line before the return statements in the v2.
after?
Regards,
Markus