netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/mlx5e: Fix two double free cases
@ 2020-12-21  8:50 Dinghao Liu
  2020-12-27  8:40 ` Leon Romanovsky
  0 siblings, 1 reply; 3+ messages in thread
From: Dinghao Liu @ 2020-12-21  8:50 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Saeed Mahameed, Leon Romanovsky, David S. Miller, Jakub Kicinski,
	netdev, linux-rdma, linux-kernel

mlx5e_create_ttc_table_groups() frees ft->g on failure of
kvzalloc(), but such failure will be caught by its caller
in mlx5e_create_ttc_table() and ft->g will be freed again
in mlx5e_destroy_flow_table(). The same issue also occurs
in mlx5e_create_ttc_table_groups().

Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/net/ethernet/mellanox/mlx5/core/en_fs.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_fs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_fs.c
index fa8149f6eb08..63323c5b6a50 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_fs.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_fs.c
@@ -940,10 +940,8 @@ static int mlx5e_create_ttc_table_groups(struct mlx5e_ttc_table *ttc,
 	if (!ft->g)
 		return -ENOMEM;
 	in = kvzalloc(inlen, GFP_KERNEL);
-	if (!in) {
-		kfree(ft->g);
+	if (!in)
 		return -ENOMEM;
-	}
 
 	/* L4 Group */
 	mc = MLX5_ADDR_OF(create_flow_group_in, in, match_criteria);
@@ -1085,10 +1083,8 @@ static int mlx5e_create_inner_ttc_table_groups(struct mlx5e_ttc_table *ttc)
 	if (!ft->g)
 		return -ENOMEM;
 	in = kvzalloc(inlen, GFP_KERNEL);
-	if (!in) {
-		kfree(ft->g);
+	if (!in)
 		return -ENOMEM;
-	}
 
 	/* L4 Group */
 	mc = MLX5_ADDR_OF(create_flow_group_in, in, match_criteria);
-- 
2.17.1


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

* Re: [PATCH] net/mlx5e: Fix two double free cases
  2020-12-21  8:50 [PATCH] net/mlx5e: Fix two double free cases Dinghao Liu
@ 2020-12-27  8:40 ` Leon Romanovsky
  2020-12-28  3:14   ` dinghao.liu
  0 siblings, 1 reply; 3+ messages in thread
From: Leon Romanovsky @ 2020-12-27  8:40 UTC (permalink / raw)
  To: Dinghao Liu
  Cc: kjlu, Saeed Mahameed, David S. Miller, Jakub Kicinski, netdev,
	linux-rdma, linux-kernel

On Mon, Dec 21, 2020 at 04:50:31PM +0800, Dinghao Liu wrote:
> mlx5e_create_ttc_table_groups() frees ft->g on failure of
> kvzalloc(), but such failure will be caught by its caller
> in mlx5e_create_ttc_table() and ft->g will be freed again
> in mlx5e_destroy_flow_table(). The same issue also occurs
> in mlx5e_create_ttc_table_groups().
>
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>  drivers/net/ethernet/mellanox/mlx5/core/en_fs.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)

I'm not thrilled to see release in the error flow that will be done in
the different function. The missing piece is "ft->g = NULL" after kfree().

And also fixes lines are missing in all your patches.

Thanks

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

* Re: Re: [PATCH] net/mlx5e: Fix two double free cases
  2020-12-27  8:40 ` Leon Romanovsky
@ 2020-12-28  3:14   ` dinghao.liu
  0 siblings, 0 replies; 3+ messages in thread
From: dinghao.liu @ 2020-12-28  3:14 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: kjlu, Saeed Mahameed, David S. Miller, Jakub Kicinski, netdev,
	linux-rdma, linux-kernel

> On Mon, Dec 21, 2020 at 04:50:31PM +0800, Dinghao Liu wrote:
> > mlx5e_create_ttc_table_groups() frees ft->g on failure of
> > kvzalloc(), but such failure will be caught by its caller
> > in mlx5e_create_ttc_table() and ft->g will be freed again
> > in mlx5e_destroy_flow_table(). The same issue also occurs
> > in mlx5e_create_ttc_table_groups().
> >
> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > ---
> >  drivers/net/ethernet/mellanox/mlx5/core/en_fs.c | 8 ++------
> >  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> I'm not thrilled to see release in the error flow that will be done in
> the different function. The missing piece is "ft->g = NULL" after kfree().
> 
> And also fixes lines are missing in all your patches.
> 

Thank you 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:[~2020-12-28  3:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-21  8:50 [PATCH] net/mlx5e: Fix two double free cases Dinghao Liu
2020-12-27  8:40 ` Leon Romanovsky
2020-12-28  3:14   ` dinghao.liu

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