net/mlx5e: Add null check for flow namespace in mlx5e_tc_nic_create_miss_table
Subsystems (5)
PATCH 1/3 net/mlx5e: Add null check for flow namespace in mlx5e_tc_nic_create_miss_table
mlx5_get_flow_namespace() can return NULL if the namespace is not available. Add a null check to prevent potential null pointer dereference when accessing ns->node.
--- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +4 -0
@@ -5216,6 +5216,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) { +netdev_err (priv->netdev,"failed to get flow namespace\n" ); +return -EOPNOTSUPP ; + } *ft =mlx5_create_auto_grouped_flow_table (ns, &ft_attr);if (IS_ERR (*ft)) {
Signature · 1 line
2.43.0
PATCH 2/3 net/mlx5: Add null check for flow namespace in esw_set_slave_root_fdb
mlx5_get_flow_namespace() can return NULL if the namespace is not available. Add null checks to prevent potential null pointer dereference when accessing ns->node in both master and slave branches.
--- drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +4 -0
@@ -2821,6 +2821,8 @@ static int esw_set_slave_root_fdb(struct mlx5_core_dev *master,if (master) { ns =mlx5_get_flow_namespace (master,MLX5_FLOW_NAMESPACE_FDB ); +if (!ns) +return -EOPNOTSUPP ; root =find_root (&ns->node);mutex_lock (&root->chain_lock); MLX5_SET(set_flow_table_root_in, in,
@@ -2833,6 +2835,8 @@ static int esw_set_slave_root_fdb(struct mlx5_core_dev *master, }else { ns =mlx5_get_flow_namespace (slave,MLX5_FLOW_NAMESPACE_FDB ); +if (!ns) +return -EOPNOTSUPP ; root =find_root (&ns->node);mutex_lock (&root->chain_lock); MLX5_SET(set_flow_table_root_in, in, table_id,
Signature · 1 line
2.43.0
PATCH 3/3 net/mlx5: Add null check for flow namespace in mlx5_cmd_set_slave_root_fdb
In reply to Oskar Ray-Frayssinetmlx5_get_flow_namespace() can return NULL if the namespace is not available. Add a null check to prevent potential null pointer dereference when accessing ns->node.
--- drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c +2 -0
@@ -186,6 +186,8 @@ static int mlx5_cmd_set_slave_root_fdb(struct mlx5_core_dev *master, }else { ns =mlx5_get_flow_namespace (slave,MLX5_FLOW_NAMESPACE_FDB ); +if (!ns) +return -EOPNOTSUPP ; root =find_root (&ns->node);MLX5_SET (set_flow_table_root_in, in, table_id, root->root_ft->id);
Signature · 1 line
2.43.0
Quoted 3 lines · Oskar Ray-Frayssinet
mlx5_get_flow_namespace()can return NULL if the namespace is not available. Add a null check to prevent potential null pointer dereference when accessingns->node.
MLX5_FLOW_NAMESPACE_KERNEL and MLX5_FLOW_NAMESPACE_FDB flow namespaces are always available. The driver and device cannot operate without them.
Thanks
Quoted 24 lines
Signed-off-by Oskar Ray-Frayssinet <[email protected]>--- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +4
-0@@ -5216,6 +5216,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) { +netdev_err (priv->netdev,"failed to get flow namespace\n" ); +return -EOPNOTSUPP ; + } *ft =mlx5_create_auto_grouped_flow_table (ns, &ft_attr);if (IS_ERR (*ft)) {Signature · 1 line
2.43.0