[PATCH] net/mlx5: Add NULL check in mlx5e_tc_nic_create_miss_table

Charles Han posted 1 patch 8 months, 3 weeks ago
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 4 ++++
1 file changed, 4 insertions(+)
[PATCH] net/mlx5: Add NULL check in mlx5e_tc_nic_create_miss_table
Posted by Charles Han 8 months, 3 weeks ago
The mlx5e_tc_nic_create_miss_table() function did not check the
return value of mlx5_get_flow_namespace(). This could lead to
subsequent code using an invalid flow namespace pointer,
potentially causing crashes or undefined behavior.

Fixes: 794131c40850 ("net/mlx5: E-Switch, Return EBUSY if can't get mode lock")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index f1d908f61134..81f0db29a2bb 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -5213,6 +5213,10 @@ static int mlx5e_tc_nic_create_miss_table(struct mlx5e_priv *priv)
 	ft_attr.level = MLX5E_TC_MISS_LEVEL;
 	ft_attr.prio = 0;
 	ns = mlx5_get_flow_namespace(priv->mdev, MLX5_FLOW_NAMESPACE_KERNEL);
+	if (!ns) {
+		mlx5_core_err(priv->mdev, "Failed to get flow namespace\n");
+		return -EOPNOTSUPP;
+	}
 
 	*ft = mlx5_create_auto_grouped_flow_table(ns, &ft_attr);
 	if (IS_ERR(*ft)) {
-- 
2.43.0
Re: [PATCH] net/mlx5: Add NULL check in mlx5e_tc_nic_create_miss_table
Posted by Tariq Toukan 8 months, 3 weeks ago
For EN driver changes, please use net/mlx5e prefix.

On 19/05/2025 14:27, Charles Han wrote:
> The mlx5e_tc_nic_create_miss_table() function did not check the
> return value of mlx5_get_flow_namespace(). This could lead to
> subsequent code using an invalid flow namespace pointer,
> potentially causing crashes or undefined behavior.
> 
> Fixes: 794131c40850 ("net/mlx5: E-Switch, Return EBUSY if can't get mode lock")

Tagged commit doesn't seem related.

> Signed-off-by: Charles Han <hanchunchao@inspur.com>
> ---

Explicitly mention target branch, and add the netdev mailing list.

>   drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> index f1d908f61134..81f0db29a2bb 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> @@ -5213,6 +5213,10 @@ static int mlx5e_tc_nic_create_miss_table(struct mlx5e_priv *priv)
>   	ft_attr.level = MLX5E_TC_MISS_LEVEL;
>   	ft_attr.prio = 0;
>   	ns = mlx5_get_flow_namespace(priv->mdev, MLX5_FLOW_NAMESPACE_KERNEL);
> +	if (!ns) {
> +		mlx5_core_err(priv->mdev, "Failed to get flow namespace\n");
> +		return -EOPNOTSUPP;
> +	}
>   
>   	*ft = mlx5_create_auto_grouped_flow_table(ns, &ft_attr);
>   	if (IS_ERR(*ft)) {