* [PATCH net 0/2] fix two memory leak issues for mlx5en driver
@ 2023-06-29 2:46 Zhengchao Shao
2023-06-29 2:46 ` [PATCH net 1/2] net/mlx5e: fix memory leak in mlx5e_fs_tt_redirect_any_create Zhengchao Shao
2023-06-29 2:46 ` [PATCH net 2/2] net/mlx5e: fix memory leak in mlx5e_ptp_open Zhengchao Shao
0 siblings, 2 replies; 8+ messages in thread
From: Zhengchao Shao @ 2023-06-29 2:46 UTC (permalink / raw)
To: netdev, linux-rdma, davem, edumazet, kuba, pabeni, richardcochran
Cc: saeedm, leon, lkayal, tariqt, gal, rrameshbabu, vadfed, ayal,
eranbe, weiyongjun1, yuehaibing, shaozhengchao
Fix two memory leak issues for mlx5en driver:
1. fix memory leak in mlx5e_fs_tt_redirect_any_create
2. fix memory leak in mlx5e_ptp_open
Zhengchao Shao (2):
net/mlx5e: fix memory leak in mlx5e_fs_tt_redirect_any_create
net/mlx5e: fix memory leak in mlx5e_ptp_open
drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c | 4 ++--
drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c | 6 ++++--
2 files changed, 6 insertions(+), 4 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH net 1/2] net/mlx5e: fix memory leak in mlx5e_fs_tt_redirect_any_create
2023-06-29 2:46 [PATCH net 0/2] fix two memory leak issues for mlx5en driver Zhengchao Shao
@ 2023-06-29 2:46 ` Zhengchao Shao
2023-06-29 12:05 ` Simon Horman
2023-06-29 18:18 ` Rahul Rameshbabu
2023-06-29 2:46 ` [PATCH net 2/2] net/mlx5e: fix memory leak in mlx5e_ptp_open Zhengchao Shao
1 sibling, 2 replies; 8+ messages in thread
From: Zhengchao Shao @ 2023-06-29 2:46 UTC (permalink / raw)
To: netdev, linux-rdma, davem, edumazet, kuba, pabeni, richardcochran
Cc: saeedm, leon, lkayal, tariqt, gal, rrameshbabu, vadfed, ayal,
eranbe, weiyongjun1, yuehaibing, shaozhengchao
The memory pointed to by the fs->any pointer is not freed in the error
path of mlx5e_fs_tt_redirect_any_create, which can lead to a memory leak.
Fix by freeing the memory in the error path, thereby making the error path
identical to mlx5e_fs_tt_redirect_any_destroy().
Fixes: 0f575c20bf06 ("net/mlx5e: Introduce Flow Steering ANY API")
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
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 03cb79adf912..9cf4ec931b8b 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
@@ -594,7 +594,7 @@ int mlx5e_fs_tt_redirect_any_create(struct mlx5e_flow_steering *fs)
err = fs_any_create_table(fs);
if (err)
- return err;
+ goto err_free_any;
err = fs_any_enable(fs);
if (err)
@@ -606,7 +606,7 @@ int mlx5e_fs_tt_redirect_any_create(struct mlx5e_flow_steering *fs)
err_destroy_table:
fs_any_destroy_table(fs_any);
-
+err_free_any:
kfree(fs_any);
mlx5e_fs_set_any(fs, NULL);
return err;
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net 2/2] net/mlx5e: fix memory leak in mlx5e_ptp_open
2023-06-29 2:46 [PATCH net 0/2] fix two memory leak issues for mlx5en driver Zhengchao Shao
2023-06-29 2:46 ` [PATCH net 1/2] net/mlx5e: fix memory leak in mlx5e_fs_tt_redirect_any_create Zhengchao Shao
@ 2023-06-29 2:46 ` Zhengchao Shao
2023-06-29 6:08 ` Gal Pressman
2023-06-29 6:23 ` Rahul Rameshbabu
1 sibling, 2 replies; 8+ messages in thread
From: Zhengchao Shao @ 2023-06-29 2:46 UTC (permalink / raw)
To: netdev, linux-rdma, davem, edumazet, kuba, pabeni, richardcochran
Cc: saeedm, leon, lkayal, tariqt, gal, rrameshbabu, vadfed, ayal,
eranbe, weiyongjun1, yuehaibing, shaozhengchao
When kvzalloc_node or kvzalloc failed in mlx5e_ptp_open, the memory
pointed by "c" or "cparams" is not freed, which can lead to a memory
leak. Fix by freeing the array in the error path.
Fixes: 145e5637d941 ("net/mlx5e: Add TX PTP port object support")
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c b/drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c
index 3cbebfba582b..b0b429a0321e 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c
@@ -729,8 +729,10 @@ int mlx5e_ptp_open(struct mlx5e_priv *priv, struct mlx5e_params *params,
c = kvzalloc_node(sizeof(*c), GFP_KERNEL, dev_to_node(mlx5_core_dma_dev(mdev)));
cparams = kvzalloc(sizeof(*cparams), GFP_KERNEL);
- if (!c || !cparams)
- return -ENOMEM;
+ if (!c || !cparams) {
+ err = -ENOMEM;
+ goto err_free;
+ }
c->priv = priv;
c->mdev = priv->mdev;
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net 2/2] net/mlx5e: fix memory leak in mlx5e_ptp_open
2023-06-29 2:46 ` [PATCH net 2/2] net/mlx5e: fix memory leak in mlx5e_ptp_open Zhengchao Shao
@ 2023-06-29 6:08 ` Gal Pressman
2023-06-29 6:23 ` Rahul Rameshbabu
1 sibling, 0 replies; 8+ messages in thread
From: Gal Pressman @ 2023-06-29 6:08 UTC (permalink / raw)
To: Zhengchao Shao, netdev, linux-rdma, davem, edumazet, kuba, pabeni,
richardcochran
Cc: saeedm, leon, lkayal, tariqt, rrameshbabu, vadfed, ayal, eranbe,
weiyongjun1, yuehaibing
On 29/06/2023 5:46, Zhengchao Shao wrote:
> When kvzalloc_node or kvzalloc failed in mlx5e_ptp_open, the memory
> pointed by "c" or "cparams" is not freed, which can lead to a memory
> leak. Fix by freeing the array in the error path.
>
> Fixes: 145e5637d941 ("net/mlx5e: Add TX PTP port object support")
> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
Thanks Zhengchao!
Reviewed-by: Gal Pressman <gal@nvidia.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net 2/2] net/mlx5e: fix memory leak in mlx5e_ptp_open
2023-06-29 2:46 ` [PATCH net 2/2] net/mlx5e: fix memory leak in mlx5e_ptp_open Zhengchao Shao
2023-06-29 6:08 ` Gal Pressman
@ 2023-06-29 6:23 ` Rahul Rameshbabu
1 sibling, 0 replies; 8+ messages in thread
From: Rahul Rameshbabu @ 2023-06-29 6:23 UTC (permalink / raw)
To: Zhengchao Shao
Cc: netdev, linux-rdma, davem, edumazet, kuba, pabeni, richardcochran,
saeedm, leon, lkayal, tariqt, gal, vadfed, ayal, eranbe,
weiyongjun1, yuehaibing
On Thu, 29 Jun, 2023 10:46:42 +0800 Zhengchao Shao <shaozhengchao@huawei.com> wrote:
> When kvzalloc_node or kvzalloc failed in mlx5e_ptp_open, the memory
> pointed by "c" or "cparams" is not freed, which can lead to a memory
> leak. Fix by freeing the array in the error path.
Reviewed-by: Rahul Rameshbabu <rrameshbabu@nvidia.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net 1/2] net/mlx5e: fix memory leak in mlx5e_fs_tt_redirect_any_create
2023-06-29 2:46 ` [PATCH net 1/2] net/mlx5e: fix memory leak in mlx5e_fs_tt_redirect_any_create Zhengchao Shao
@ 2023-06-29 12:05 ` Simon Horman
2023-06-29 18:18 ` Rahul Rameshbabu
1 sibling, 0 replies; 8+ messages in thread
From: Simon Horman @ 2023-06-29 12:05 UTC (permalink / raw)
To: Zhengchao Shao
Cc: netdev, linux-rdma, davem, edumazet, kuba, pabeni, richardcochran,
saeedm, leon, lkayal, tariqt, gal, rrameshbabu, vadfed, ayal,
eranbe, weiyongjun1, yuehaibing
On Thu, Jun 29, 2023 at 10:46:41AM +0800, Zhengchao Shao wrote:
> The memory pointed to by the fs->any pointer is not freed in the error
> path of mlx5e_fs_tt_redirect_any_create, which can lead to a memory leak.
> Fix by freeing the memory in the error path, thereby making the error path
> identical to mlx5e_fs_tt_redirect_any_destroy().
>
> Fixes: 0f575c20bf06 ("net/mlx5e: Introduce Flow Steering ANY API")
> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net 1/2] net/mlx5e: fix memory leak in mlx5e_fs_tt_redirect_any_create
2023-06-29 2:46 ` [PATCH net 1/2] net/mlx5e: fix memory leak in mlx5e_fs_tt_redirect_any_create Zhengchao Shao
2023-06-29 12:05 ` Simon Horman
@ 2023-06-29 18:18 ` Rahul Rameshbabu
2023-06-30 1:27 ` shaozhengchao
1 sibling, 1 reply; 8+ messages in thread
From: Rahul Rameshbabu @ 2023-06-29 18:18 UTC (permalink / raw)
To: Zhengchao Shao
Cc: netdev, linux-rdma, davem, edumazet, kuba, pabeni, richardcochran,
saeedm, leon, lkayal, tariqt, gal, vadfed, ayal, eranbe,
weiyongjun1, yuehaibing
On Thu, 29 Jun, 2023 10:46:41 +0800 Zhengchao Shao <shaozhengchao@huawei.com> wrote:
> The memory pointed to by the fs->any pointer is not freed in the error
> path of mlx5e_fs_tt_redirect_any_create, which can lead to a memory leak.
> Fix by freeing the memory in the error path, thereby making the error path
> identical to mlx5e_fs_tt_redirect_any_destroy().
>
> Fixes: 0f575c20bf06 ("net/mlx5e: Introduce Flow Steering ANY API")
> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
> ---
> drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> 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 03cb79adf912..9cf4ec931b8b 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
> @@ -594,7 +594,7 @@ int mlx5e_fs_tt_redirect_any_create(struct mlx5e_flow_steering *fs)
>
> err = fs_any_create_table(fs);
> if (err)
> - return err;
> + goto err_free_any;
>
> err = fs_any_enable(fs);
> if (err)
> @@ -606,7 +606,7 @@ int mlx5e_fs_tt_redirect_any_create(struct mlx5e_flow_steering *fs)
>
> err_destroy_table:
> fs_any_destroy_table(fs_any);
> -
> +err_free_any:
> kfree(fs_any);
> mlx5e_fs_set_any(fs, NULL);
We probably should update the 'any' member reference in fs to NULL
*before* free-ing fs_any. Otherwise, there is a period in time where fs
is referring to a dirty pointer value in its any member field. It's not
critical, but it makes logical sense in my opinion. Lets swap these two
lines in this patch.
> return err;
Thanks for the patch,
-- Rahul Rameshbabu
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net 1/2] net/mlx5e: fix memory leak in mlx5e_fs_tt_redirect_any_create
2023-06-29 18:18 ` Rahul Rameshbabu
@ 2023-06-30 1:27 ` shaozhengchao
0 siblings, 0 replies; 8+ messages in thread
From: shaozhengchao @ 2023-06-30 1:27 UTC (permalink / raw)
To: Rahul Rameshbabu
Cc: netdev, linux-rdma, davem, edumazet, kuba, pabeni, richardcochran,
saeedm, leon, lkayal, tariqt, gal, vadfed, ayal, eranbe,
weiyongjun1, yuehaibing
On 2023/6/30 2:18, Rahul Rameshbabu wrote:
> On Thu, 29 Jun, 2023 10:46:41 +0800 Zhengchao Shao <shaozhengchao@huawei.com> wrote:
>> The memory pointed to by the fs->any pointer is not freed in the error
>> path of mlx5e_fs_tt_redirect_any_create, which can lead to a memory leak.
>> Fix by freeing the memory in the error path, thereby making the error path
>> identical to mlx5e_fs_tt_redirect_any_destroy().
>>
>> Fixes: 0f575c20bf06 ("net/mlx5e: Introduce Flow Steering ANY API")
>> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
>> ---
>> drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> 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 03cb79adf912..9cf4ec931b8b 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
>> @@ -594,7 +594,7 @@ int mlx5e_fs_tt_redirect_any_create(struct mlx5e_flow_steering *fs)
>>
>> err = fs_any_create_table(fs);
>> if (err)
>> - return err;
>> + goto err_free_any;
>>
>> err = fs_any_enable(fs);
>> if (err)
>> @@ -606,7 +606,7 @@ int mlx5e_fs_tt_redirect_any_create(struct mlx5e_flow_steering *fs)
>>
>> err_destroy_table:
>> fs_any_destroy_table(fs_any);
>> -
>> +err_free_any:
>> kfree(fs_any);
>> mlx5e_fs_set_any(fs, NULL);
>
Hi Rahul:
> We probably should update the 'any' member reference in fs to NULL
> *before* free-ing fs_any. Otherwise, there is a period in time where fs
> is referring to a dirty pointer value in its any member field. It's not
> critical, but it makes logical sense in my opinion. Lets swap these two
> lines in this patch.
>
It looks good. I will send V2. Thank you.
Zhengchao Shao
>> return err;
>
> Thanks for the patch,
>
> -- Rahul Rameshbabu
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-06-30 1:28 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-29 2:46 [PATCH net 0/2] fix two memory leak issues for mlx5en driver Zhengchao Shao
2023-06-29 2:46 ` [PATCH net 1/2] net/mlx5e: fix memory leak in mlx5e_fs_tt_redirect_any_create Zhengchao Shao
2023-06-29 12:05 ` Simon Horman
2023-06-29 18:18 ` Rahul Rameshbabu
2023-06-30 1:27 ` shaozhengchao
2023-06-29 2:46 ` [PATCH net 2/2] net/mlx5e: fix memory leak in mlx5e_ptp_open Zhengchao Shao
2023-06-29 6:08 ` Gal Pressman
2023-06-29 6:23 ` Rahul Rameshbabu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox