diff mbox series

[net,v2] mlxsw: core_linecards: Fix double memory deallocation in case of invalid INI file

Message ID 20240703203251.8871-1-amishin@t-argos.ru (mailing list archive)
State Accepted
Commit 8ce34dccbe8fa7d2ef86f2d8e7db2a9b67cabfc3
Delegated to: Netdev Maintainers
Headers show
Series [net,v2] mlxsw: core_linecards: Fix double memory deallocation in case of invalid INI file | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 856 this patch: 856
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 860 this patch: 860
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 860 this patch: 860
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-07-04--00-00 (tests: 663)

Commit Message

Aleksandr Mishin July 3, 2024, 8:32 p.m. UTC
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(+)

Comments

Michal Kubiak July 4, 2024, 1:56 p.m. UTC | #1
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>
patchwork-bot+netdevbpf@kernel.org July 4, 2024, 2:40 p.m. UTC | #2
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!
diff mbox series

Patch

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;
 }