Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH] net/mlx5e: fix a potential double-free in fs_any_create_groups
@ 2023-11-28  8:28 Dinghao Liu
  2023-11-28  8:58 ` Tariq Toukan
  0 siblings, 1 reply; 3+ messages in thread
From: Dinghao Liu @ 2023-11-28  8:28 UTC (permalink / raw)
  To: dinghao.liu
  Cc: Saeed Mahameed, Leon Romanovsky, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Zhengchao Shao, Rahul Rameshbabu,
	Simon Horman, Tariq Toukan, Aya Levin, netdev, linux-rdma,
	linux-kernel

When kcalloc() for ft->g succeeds but kvzalloc() for in fails,
fs_any_create_groups() will free ft->g. However, its caller
fs_any_create_table() will free ft->g again through calling
mlx5e_destroy_flow_table(), which will lead to a double-free.
Fix this by removing the kfree(ft->g) in fs_any_create_groups().

Fixes: 0f575c20bf06 ("net/mlx5e: Introduce Flow Steering ANY API")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c b/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c
index be83ad9db82a..b222d23bfb9a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c
@@ -434,7 +434,6 @@ static int fs_any_create_groups(struct mlx5e_flow_table *ft)
 	ft->g = kcalloc(MLX5E_FS_UDP_NUM_GROUPS, sizeof(*ft->g), GFP_KERNEL);
 	in = kvzalloc(inlen, GFP_KERNEL);
 	if  (!in || !ft->g) {
-		kfree(ft->g);
 		kvfree(in);
 		return -ENOMEM;
 	}
-- 
2.17.1


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

* Re: [PATCH] net/mlx5e: fix a potential double-free in fs_any_create_groups
  2023-11-28  8:28 [PATCH] net/mlx5e: fix a potential double-free in fs_any_create_groups Dinghao Liu
@ 2023-11-28  8:58 ` Tariq Toukan
  2023-11-28  9:15   ` dinghao.liu
  0 siblings, 1 reply; 3+ messages in thread
From: Tariq Toukan @ 2023-11-28  8:58 UTC (permalink / raw)
  To: Dinghao Liu
  Cc: Saeed Mahameed, Leon Romanovsky, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Zhengchao Shao, Rahul Rameshbabu,
	Simon Horman, Tariq Toukan, Aya Levin, netdev, linux-rdma,
	linux-kernel, Tariq Toukan



On 28/11/2023 10:28, Dinghao Liu wrote:
> When kcalloc() for ft->g succeeds but kvzalloc() for in fails,
> fs_any_create_groups() will free ft->g. However, its caller
> fs_any_create_table() will free ft->g again through calling
> mlx5e_destroy_flow_table(), which will lead to a double-free.
> Fix this by removing the kfree(ft->g) in fs_any_create_groups().
> 
> Fixes: 0f575c20bf06 ("net/mlx5e: Introduce Flow Steering ANY API")
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>   drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c | 1 -
>   1 file changed, 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c b/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c
> index be83ad9db82a..b222d23bfb9a 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c
> @@ -434,7 +434,6 @@ static int fs_any_create_groups(struct mlx5e_flow_table *ft)
>   	ft->g = kcalloc(MLX5E_FS_UDP_NUM_GROUPS, sizeof(*ft->g), GFP_KERNEL);
>   	in = kvzalloc(inlen, GFP_KERNEL);
>   	if  (!in || !ft->g) {
> -		kfree(ft->g);
>   		kvfree(in);
>   		return -ENOMEM;
>   	}

Function fs_any_create_groups should not return failure without cleaning 
itself up. This is not the right fix.
Freeing ft->g and setting it to NULL will do it, and will avoid the 
double free.

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

* Re: [PATCH] net/mlx5e: fix a potential double-free in fs_any_create_groups
  2023-11-28  8:58 ` Tariq Toukan
@ 2023-11-28  9:15   ` dinghao.liu
  0 siblings, 0 replies; 3+ messages in thread
From: dinghao.liu @ 2023-11-28  9:15 UTC (permalink / raw)
  To: Tariq Toukan
  Cc: Saeed Mahameed, Leon Romanovsky, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Zhengchao Shao, Rahul Rameshbabu,
	Simon Horman, Tariq Toukan, Aya Levin, netdev, linux-rdma,
	linux-kernel

> 
> On 28/11/2023 10:28, Dinghao Liu wrote:
> > When kcalloc() for ft->g succeeds but kvzalloc() for in fails,
> > fs_any_create_groups() will free ft->g. However, its caller
> > fs_any_create_table() will free ft->g again through calling
> > mlx5e_destroy_flow_table(), which will lead to a double-free.
> > Fix this by removing the kfree(ft->g) in fs_any_create_groups().
> > 
> > Fixes: 0f575c20bf06 ("net/mlx5e: Introduce Flow Steering ANY API")
> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > ---
> >   drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c | 1 -
> >   1 file changed, 1 deletion(-)
> > 
> > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c b/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c
> > index be83ad9db82a..b222d23bfb9a 100644
> > --- a/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c
> > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c
> > @@ -434,7 +434,6 @@ static int fs_any_create_groups(struct mlx5e_flow_table *ft)
> >   	ft->g = kcalloc(MLX5E_FS_UDP_NUM_GROUPS, sizeof(*ft->g), GFP_KERNEL);
> >   	in = kvzalloc(inlen, GFP_KERNEL);
> >   	if  (!in || !ft->g) {
> > -		kfree(ft->g);
> >   		kvfree(in);
> >   		return -ENOMEM;
> >   	}
> 
> Function fs_any_create_groups should not return failure without cleaning 
> itself up. This is not the right fix.
> Freeing ft->g and setting it to NULL will do it, and will avoid the 
> double free.

Thanks for your advice! I will resend a new patch soon.

Regards,
Dinghao

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

end of thread, other threads:[~2023-11-28  9:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-28  8:28 [PATCH] net/mlx5e: fix a potential double-free in fs_any_create_groups Dinghao Liu
2023-11-28  8:58 ` Tariq Toukan
2023-11-28  9:15   ` dinghao.liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox