public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v2] mlxsw: core_linecards: Fix double memory deallocation in case of invalid INI file
@ 2024-07-03 20:32 Aleksandr Mishin
  2024-07-04 13:56 ` Michal Kubiak
  2024-07-04 14:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Aleksandr Mishin @ 2024-07-03 20:32 UTC (permalink / raw)
  To: Jiri Pirko
  Cc: Aleksandr Mishin, Ido Schimmel, Petr Machata, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	lvc-project, Przemek Kitszel

In case of invalid INI file mlxsw_linecard_types_init() deallocates memory
but doesn't reset pointer to NULL and returns 0. In case of any error
occurred after mlxsw_linecard_types_init() call, mlxsw_linecards_init()
calls mlxsw_linecard_types_fini() which performs memory deallocation again.

Add pointer reset to NULL.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: b217127e5e4e ("mlxsw: core_linecards: Add line card objects and implement provisioning")
Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
---
v2:
  - fix few typos in comment as suggested by Przemek and Ido
  - add Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
    (https://lore.kernel.org/all/c631fc5e-1cc6-467a-963a-69ef03c20f40@intel.com/)
  - add Reviewed-by: Ido Schimmel <idosch@nvidia.com>
    (https://lore.kernel.org/all/ZoWJzqaRJKjtTlNO@shredder.mtl.com/)
v1: https://lore.kernel.org/all/20240702103352.15315-1-amishin@t-argos.ru/

 drivers/net/ethernet/mellanox/mlxsw/core_linecards.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c b/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c
index 025e0db983fe..b032d5a4b3b8 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c
@@ -1484,6 +1484,7 @@ static int mlxsw_linecard_types_init(struct mlxsw_core *mlxsw_core,
 	vfree(types_info->data);
 err_data_alloc:
 	kfree(types_info);
+	linecards->types_info = NULL;
 	return err;
 }
 
-- 
2.30.2


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

* Re: [PATCH net v2] mlxsw: core_linecards: Fix double memory deallocation in case of invalid INI file
  2024-07-03 20:32 [PATCH net v2] mlxsw: core_linecards: Fix double memory deallocation in case of invalid INI file Aleksandr Mishin
@ 2024-07-04 13:56 ` Michal Kubiak
  2024-07-04 14:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Michal Kubiak @ 2024-07-04 13:56 UTC (permalink / raw)
  To: Aleksandr Mishin
  Cc: Jiri Pirko, Ido Schimmel, Petr Machata, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	lvc-project, Przemek Kitszel

On Wed, Jul 03, 2024 at 11:32:51PM +0300, Aleksandr Mishin wrote:
> In case of invalid INI file mlxsw_linecard_types_init() deallocates memory
> but doesn't reset pointer to NULL and returns 0. In case of any error
> occurred after mlxsw_linecard_types_init() call, mlxsw_linecards_init()
> calls mlxsw_linecard_types_fini() which performs memory deallocation again.
> 
> Add pointer reset to NULL.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: b217127e5e4e ("mlxsw: core_linecards: Add line card objects and implement provisioning")
> Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
> Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
> Reviewed-by: Ido Schimmel <idosch@nvidia.com>
> ---
> v2:
>   - fix few typos in comment as suggested by Przemek and Ido
>   - add Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
>     (https://lore.kernel.org/all/c631fc5e-1cc6-467a-963a-69ef03c20f40@intel.com/)
>   - add Reviewed-by: Ido Schimmel <idosch@nvidia.com>
>     (https://lore.kernel.org/all/ZoWJzqaRJKjtTlNO@shredder.mtl.com/)
> v1: https://lore.kernel.org/all/20240702103352.15315-1-amishin@t-argos.ru/
> 
>  drivers/net/ethernet/mellanox/mlxsw/core_linecards.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c b/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c
> index 025e0db983fe..b032d5a4b3b8 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c
> +++ b/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c
> @@ -1484,6 +1484,7 @@ static int mlxsw_linecard_types_init(struct mlxsw_core *mlxsw_core,
>  	vfree(types_info->data);
>  err_data_alloc:
>  	kfree(types_info);
> +	linecards->types_info = NULL;
>  	return err;
>  }
>  
> -- 
> 2.30.2
> 

It looks like all the typos pointed out in v1 have been fixed.
Thanks,

Reviewed-by: Michal Kubiak <michal.kubiak@intel.com>

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

* Re: [PATCH net v2] mlxsw: core_linecards: Fix double memory deallocation in case of invalid INI file
  2024-07-03 20:32 [PATCH net v2] mlxsw: core_linecards: Fix double memory deallocation in case of invalid INI file Aleksandr Mishin
  2024-07-04 13:56 ` Michal Kubiak
@ 2024-07-04 14:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-07-04 14:40 UTC (permalink / raw)
  To: Aleksandr Mishin
  Cc: jiri, idosch, petrm, davem, edumazet, kuba, pabeni, netdev,
	linux-kernel, lvc-project, przemyslaw.kitszel

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 3 Jul 2024 23:32:51 +0300 you wrote:
> In case of invalid INI file mlxsw_linecard_types_init() deallocates memory
> but doesn't reset pointer to NULL and returns 0. In case of any error
> occurred after mlxsw_linecard_types_init() call, mlxsw_linecards_init()
> calls mlxsw_linecard_types_fini() which performs memory deallocation again.
> 
> Add pointer reset to NULL.
> 
> [...]

Here is the summary with links:
  - [net,v2] mlxsw: core_linecards: Fix double memory deallocation in case of invalid INI file
    https://git.kernel.org/netdev/net/c/8ce34dccbe8f

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2024-07-04 14:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-03 20:32 [PATCH net v2] mlxsw: core_linecards: Fix double memory deallocation in case of invalid INI file Aleksandr Mishin
2024-07-04 13:56 ` Michal Kubiak
2024-07-04 14:40 ` patchwork-bot+netdevbpf

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