Skip to contentSkip to conversation

mlxsw: spectrum_router: Fix a double free on error

PATCH In review Dan Carpenter 2 participants 2 messages Nov 18, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mlxsw: spectrum_router: Fix a double free on error

There is a double free here because mlxsw_sp_nexthop6_group_create() and mlxsw_sp_nexthop6_group_info_init() free "nh_grp". It should only be freed in the create function.

Fixes 7f7a417e6a11 ("mlxsw: spectrum_router: Split nexthop group configuration to a different struct")
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 1 -
 1 file changed, 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +0 -1
index a2e81ad5790f..fde8667a2f60 100644
@@ -5423,7 +5423,6 @@ mlxsw_sp_nexthop6_group_info_init(struct mlxsw_sp *mlxsw_sp,
 		nh = &nhgi->nexthops[i];
 		mlxsw_sp_nexthop6_fini(mlxsw_sp, nh);
 	}
-	kfree(nh_grp);
 	return err;
 }
 
Signature · 1 line
2.29.2
#1 lore raw
Quoted 15 lines · Dan Carpenter

There is a double free here because mlxsw_sp_nexthop6_group_create() and mlxsw_sp_nexthop6_group_info_init() free "nh_grp". It should only be freed in the create function.

Fixes 7f7a417e6a11 ("mlxsw: spectrum_router: Split nexthop group configuration to a different struct")
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 1 -
 1 file changed, 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +0 -0
index a2e81ad5790f..fde8667a2f60 100644

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c mlxsw_sp_nexthop6_group_info_init(struct mlxsw_sp *mlxsw_sp, · line 5426

Quoted 4 lines
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +0 -1
@@ -5423,7 +5423,6 @@ mlxsw_sp_nexthop6_group_info_init(struct mlxsw_sp *mlxsw_sp,
 		nh = &nhgi->nexthops[i];
 		mlxsw_sp_nexthop6_fini(mlxsw_sp, nh);
 	}
-	kfree(nh_grp);

Thanks for the patch, Dan.

I already sent a patch yesterday:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

Note that it is different than yours. It frees 'nhgi' instead of 'nh_grp'. It was a typo.

Quoted 6 lines
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +0 -0
 	return err;
 }
 
Signature · 1 line
2.29.2