netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/1] net/mlx5: Fix null-ptr-deref in TTC table creation
@ 2025-04-11  2:29 Henry Martin
  2025-04-11  2:29 ` [PATCH v3 1/1] net/mlx5: Fix null-ptr-deref in mlx5_create_{inner_,}ttc_table() Henry Martin
  0 siblings, 1 reply; 4+ messages in thread
From: Henry Martin @ 2025-04-11  2:29 UTC (permalink / raw)
  To: saeedm, leon, tariqt, netdev
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, amirtz, ayal,
	linux-rdma, linux-kernel, Henry Martin

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(+)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3 1/1] net/mlx5: Fix null-ptr-deref in mlx5_create_{inner_,}ttc_table()
  2025-04-11  2:29 [PATCH v3 0/1] net/mlx5: Fix null-ptr-deref in TTC table creation Henry Martin
@ 2025-04-11  2:29 ` Henry Martin
  2025-04-11  5:34   ` Michal Swiatkowski
  0 siblings, 1 reply; 4+ messages in thread
From: Henry Martin @ 2025-04-11  2:29 UTC (permalink / raw)
  To: saeedm, leon, tariqt, netdev
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, amirtz, ayal,
	linux-rdma, linux-kernel, Henry Martin

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.

Fixes: 137f3d50ad2a ("net/mlx5: Support matching on l4_type for ttc_table")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
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(+)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c
index eb3bd9c7f66e..18cc6960a5c1 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c
@@ -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];
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 1/1] net/mlx5: Fix null-ptr-deref in mlx5_create_{inner_,}ttc_table()
  2025-04-11  2:29 ` [PATCH v3 1/1] net/mlx5: Fix null-ptr-deref in mlx5_create_{inner_,}ttc_table() Henry Martin
@ 2025-04-11  5:34   ` Michal Swiatkowski
  2025-04-14  9:55     ` henry martin
  0 siblings, 1 reply; 4+ messages in thread
From: Michal Swiatkowski @ 2025-04-11  5:34 UTC (permalink / raw)
  To: Henry Martin
  Cc: saeedm, leon, tariqt, netdev, andrew+netdev, davem, edumazet,
	kuba, pabeni, amirtz, ayal, linux-rdma, linux-kernel

On Fri, Apr 11, 2025 at 10:29:16AM +0800, Henry Martin wrote:
> 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.
> 
> Fixes: 137f3d50ad2a ("net/mlx5: Support matching on l4_type for ttc_table")
> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
> ---
> 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(+)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c
> index eb3bd9c7f66e..18cc6960a5c1 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c
> @@ -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.

> +
>  	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.

> +
>  	groups = use_l4_type ? &ttc_groups[TTC_GROUPS_USE_L4_TYPE] :
>  			       &ttc_groups[TTC_GROUPS_DEFAULT];
>  
> -- 
> 2.34.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 1/1] net/mlx5: Fix null-ptr-deref in mlx5_create_{inner_,}ttc_table()
  2025-04-11  5:34   ` Michal Swiatkowski
@ 2025-04-14  9:55     ` henry martin
  0 siblings, 0 replies; 4+ messages in thread
From: henry martin @ 2025-04-14  9:55 UTC (permalink / raw)
  To: Michal Swiatkowski
  Cc: saeedm, leon, tariqt, netdev, andrew+netdev, davem, edumazet,
	kuba, pabeni, amirtz, ayal, linux-rdma, linux-kernel

> 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.

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


Michal Swiatkowski <michal.swiatkowski@linux.intel.com> 于2025年4月11日周五 13:34写道:
>
> On Fri, Apr 11, 2025 at 10:29:16AM +0800, Henry Martin wrote:
> > 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.
> >
> > Fixes: 137f3d50ad2a ("net/mlx5: Support matching on l4_type for ttc_table")
> > Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
> > ---
> > 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(+)
> >
> > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c
> > index eb3bd9c7f66e..18cc6960a5c1 100644
> > --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c
> > +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c
> > @@ -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.
>
> > +
> >       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.
>
> > +
> >       groups = use_l4_type ? &ttc_groups[TTC_GROUPS_USE_L4_TYPE] :
> >                              &ttc_groups[TTC_GROUPS_DEFAULT];
> >
> > --
> > 2.34.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-04-14  9:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-11  2:29 [PATCH v3 0/1] net/mlx5: Fix null-ptr-deref in TTC table creation Henry Martin
2025-04-11  2:29 ` [PATCH v3 1/1] net/mlx5: Fix null-ptr-deref in mlx5_create_{inner_,}ttc_table() Henry Martin
2025-04-11  5:34   ` Michal Swiatkowski
2025-04-14  9:55     ` henry martin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).