Skip to contentSkip to conversation

mlxsw: spectrum_router: fix a use after free

PATCH In review Dan Carpenter 2 participants 2 messages Jul 7, 2016

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

PATCH 1/1 mlxsw: spectrum_router: fix a use after free

mlxsw_sp_fib_entry_destroy() frees "fib_entry" but we dereference it on the next line.

Fixes 61c503f976b5 ('mlxsw: spectrum_router: Implement fib4 add/del switchdev obj ops')
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +1 -1
index e084ea5..adb481a 100644
@@ -1652,8 +1652,8 @@ static void mlxsw_sp_router_fib4_add_info_destroy(void const *data)
 	struct mlxsw_sp_fib_entry *fib_entry = info->fib_entry;
 	struct mlxsw_sp *mlxsw_sp = info->mlxsw_sp;
 
-	mlxsw_sp_fib_entry_destroy(fib_entry);
 	mlxsw_sp_vr_put(mlxsw_sp, fib_entry->vr);
+	mlxsw_sp_fib_entry_destroy(fib_entry);
 	kfree(info);
 }
 
#1 lore raw

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c static void mlxsw_sp_router_fib4_add_info_destroy(void const *data) · line 1653

Quoted 13 lines · Thu, Jul 07, 2016 at 10:20:28AM CEST, [email protected] wrote:

mlxsw_sp_fib_entry_destroy() frees "fib_entry" but we dereference it on the next line.

Fixes 61c503f976b5 ('mlxsw: spectrum_router: Implement fib4 add/del switchdev obj ops')
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +0 -0
index e084ea5..adb481a 100644
@@ -1652,8 +1652,8 @@ static void mlxsw_sp_router_fib4_add_info_destroy(void const *data)
 	struct mlxsw_sp_fib_entry *fib_entry = info->fib_entry;
 	struct mlxsw_sp *mlxsw_sp = info->mlxsw_sp;

To be consistent with the rest of the flows, I would rather do:

	struct mlxsw_sp_vr *vr = fib_entry->vr;

	mlxsw_sp_fib_entry_destroy(fib_entry);

mlxsw_sp_vr_put(mlxsw_sp, vr);

I can send the fix or I can leave it up to you. Thanks.