netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [v2] net/mlx5e: fix a potential double-free in fs_udp_create_groups
@ 2023-11-28  9:40 Dinghao Liu
  2023-11-28  9:55 ` Tariq Toukan
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dinghao Liu @ 2023-11-28  9:40 UTC (permalink / raw)
  To: dinghao.liu
  Cc: Saeed Mahameed, Leon Romanovsky, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Zhengchao Shao, Simon Horman,
	Rahul Rameshbabu, Aya Levin, Tariq Toukan, netdev, linux-rdma,
	linux-kernel

When kcalloc() for ft->g succeeds but kvzalloc() for in fails,
fs_udp_create_groups() will free ft->g. However, its caller
fs_udp_create_table() will free ft->g again through calling
mlx5e_destroy_flow_table(), which will lead to a double-free.
Fix this by setting ft->g to NULL in fs_udp_create_groups().

Fixes: 1c80bd684388 ("net/mlx5e: Introduce Flow Steering UDP API")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---

Changelog:

v2: Setting ft->g to NULL instead of removing the kfree().
---
 drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c | 1 +
 1 file changed, 1 insertion(+)

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..e1283531e0b8 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
@@ -154,6 +154,7 @@ static int fs_udp_create_groups(struct mlx5e_flow_table *ft, enum fs_udp_type ty
 	in = kvzalloc(inlen, GFP_KERNEL);
 	if  (!in || !ft->g) {
 		kfree(ft->g);
+		ft->g = NULL;
 		kvfree(in);
 		return -ENOMEM;
 	}
-- 
2.17.1


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

* Re: [PATCH] [v2] net/mlx5e: fix a potential double-free in fs_udp_create_groups
  2023-11-28  9:40 [PATCH] [v2] net/mlx5e: fix a potential double-free in fs_udp_create_groups Dinghao Liu
@ 2023-11-28  9:55 ` Tariq Toukan
  2023-11-30 17:45 ` Simon Horman
  2023-12-06 21:53 ` Saeed Mahameed
  2 siblings, 0 replies; 4+ messages in thread
From: Tariq Toukan @ 2023-11-28  9:55 UTC (permalink / raw)
  To: Dinghao Liu
  Cc: Saeed Mahameed, Leon Romanovsky, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Zhengchao Shao, Simon Horman,
	Rahul Rameshbabu, Aya Levin, Tariq Toukan, netdev, linux-rdma,
	linux-kernel, Tariq Toukan



On 28/11/2023 11:40, Dinghao Liu wrote:
> When kcalloc() for ft->g succeeds but kvzalloc() for in fails,
> fs_udp_create_groups() will free ft->g. However, its caller
> fs_udp_create_table() will free ft->g again through calling
> mlx5e_destroy_flow_table(), which will lead to a double-free.
> Fix this by setting ft->g to NULL in fs_udp_create_groups().
> 
> Fixes: 1c80bd684388 ("net/mlx5e: Introduce Flow Steering UDP API")
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
> 
> Changelog:
> 
> v2: Setting ft->g to NULL instead of removing the kfree().
> ---
>   drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> 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..e1283531e0b8 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
> @@ -154,6 +154,7 @@ static int fs_udp_create_groups(struct mlx5e_flow_table *ft, enum fs_udp_type ty
>   	in = kvzalloc(inlen, GFP_KERNEL);
>   	if  (!in || !ft->g) {
>   		kfree(ft->g);
> +		ft->g = NULL;
>   		kvfree(in);
>   		return -ENOMEM;
>   	}


Thanks for your patch.
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>

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

* Re: [PATCH] [v2] net/mlx5e: fix a potential double-free in fs_udp_create_groups
  2023-11-28  9:40 [PATCH] [v2] net/mlx5e: fix a potential double-free in fs_udp_create_groups Dinghao Liu
  2023-11-28  9:55 ` Tariq Toukan
@ 2023-11-30 17:45 ` Simon Horman
  2023-12-06 21:53 ` Saeed Mahameed
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2023-11-30 17:45 UTC (permalink / raw)
  To: Dinghao Liu
  Cc: Saeed Mahameed, Leon Romanovsky, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Zhengchao Shao, Rahul Rameshbabu,
	Aya Levin, Tariq Toukan, netdev, linux-rdma, linux-kernel

On Tue, Nov 28, 2023 at 05:40:53PM +0800, Dinghao Liu wrote:
> When kcalloc() for ft->g succeeds but kvzalloc() for in fails,
> fs_udp_create_groups() will free ft->g. However, its caller
> fs_udp_create_table() will free ft->g again through calling
> mlx5e_destroy_flow_table(), which will lead to a double-free.
> Fix this by setting ft->g to NULL in fs_udp_create_groups().
> 
> Fixes: 1c80bd684388 ("net/mlx5e: Introduce Flow Steering UDP API")
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
> 
> Changelog:
> 
> v2: Setting ft->g to NULL instead of removing the kfree().

Reviewed-by: Simon Horman <horms@kernel.org>


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

* Re: [PATCH] [v2] net/mlx5e: fix a potential double-free in fs_udp_create_groups
  2023-11-28  9:40 [PATCH] [v2] net/mlx5e: fix a potential double-free in fs_udp_create_groups Dinghao Liu
  2023-11-28  9:55 ` Tariq Toukan
  2023-11-30 17:45 ` Simon Horman
@ 2023-12-06 21:53 ` Saeed Mahameed
  2 siblings, 0 replies; 4+ messages in thread
From: Saeed Mahameed @ 2023-12-06 21:53 UTC (permalink / raw)
  To: Dinghao Liu
  Cc: Saeed Mahameed, Leon Romanovsky, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Zhengchao Shao, Simon Horman,
	Rahul Rameshbabu, Aya Levin, Tariq Toukan, netdev, linux-rdma,
	linux-kernel

On 28 Nov 17:40, Dinghao Liu wrote:
>When kcalloc() for ft->g succeeds but kvzalloc() for in fails,
>fs_udp_create_groups() will free ft->g. However, its caller
>fs_udp_create_table() will free ft->g again through calling
>mlx5e_destroy_flow_table(), which will lead to a double-free.
>Fix this by setting ft->g to NULL in fs_udp_create_groups().
>
>Fixes: 1c80bd684388 ("net/mlx5e: Introduce Flow Steering UDP API")
>Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
>---
>
>Changelog:
>
>v2: Setting ft->g to NULL instead of removing the kfree().
>---

Applied to net-mlx5.

- Saeed

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

end of thread, other threads:[~2023-12-06 21:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-28  9:40 [PATCH] [v2] net/mlx5e: fix a potential double-free in fs_udp_create_groups Dinghao Liu
2023-11-28  9:55 ` Tariq Toukan
2023-11-30 17:45 ` Simon Horman
2023-12-06 21:53 ` Saeed Mahameed

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