Netdev List
 help / color / mirror / Atom feed
* [PATCH] mlxsw: fix refcount leak in mlxsw_sp_vrs_lpm_tree_replace()
@ 2026-06-09  8:47 Wentao Liang
  2026-06-11  6:18 ` Ido Schimmel
  2026-06-11 23:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Wentao Liang @ 2026-06-09  8:47 UTC (permalink / raw)
  To: idosch, petrm, andrew+netdev, davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, Wentao Liang, stable

When mlxsw_sp_vrs_lpm_tree_replace() fails after replacing some VRs,
the error rollback loop does not correctly revert the preceding
replacements. The loop decrements the index but fails to update the
vr pointer, which still points to the VR that caused the failure. As
a result, the condition and the rollback call always operate on the
same VR, potentially calling mlxsw_sp_vr_lpm_tree_replace() multiple
times on it while never rolling back the earlier VRs. Those VRs
continue to hold a reference to new_tree acquired via
mlxsw_sp_lpm_tree_hold(), leaking the reference count of new_tree.

Fix by reinitializing vr inside the error loop with the updated index:

	vr = &mlxsw_sp->router->vrs[i];

so that the loop correctly iterates over all VRs that were actually
replaced.

Cc: stable@vger.kernel.org
Fixes: fc922bb0dd94 ("mlxsw: spectrum_router: Use one LPM tree for all virtual routers")
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
index 7bd87d0547d8..3d6fdbab05e0 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
@@ -1018,6 +1018,7 @@ static int mlxsw_sp_vrs_lpm_tree_replace(struct mlxsw_sp *mlxsw_sp,
 
 err_tree_replace:
 	for (i--; i >= 0; i--) {
+		vr = &mlxsw_sp->router->vrs[i];
 		if (!mlxsw_sp_vr_lpm_tree_should_replace(vr, proto, new_id))
 			continue;
 		mlxsw_sp_vr_lpm_tree_replace(mlxsw_sp,
-- 
2.34.1


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

* Re: [PATCH] mlxsw: fix refcount leak in mlxsw_sp_vrs_lpm_tree_replace()
  2026-06-09  8:47 [PATCH] mlxsw: fix refcount leak in mlxsw_sp_vrs_lpm_tree_replace() Wentao Liang
@ 2026-06-11  6:18 ` Ido Schimmel
  2026-06-11 23:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Ido Schimmel @ 2026-06-11  6:18 UTC (permalink / raw)
  To: Wentao Liang
  Cc: petrm, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
	linux-kernel, stable

Same comment as on the last patch regarding subject prefix

On Tue, Jun 09, 2026 at 08:47:30AM +0000, Wentao Liang wrote:
> When mlxsw_sp_vrs_lpm_tree_replace() fails after replacing some VRs,
> the error rollback loop does not correctly revert the preceding
> replacements. The loop decrements the index but fails to update the
> vr pointer, which still points to the VR that caused the failure. As
> a result, the condition and the rollback call always operate on the
> same VR, potentially calling mlxsw_sp_vr_lpm_tree_replace() multiple
> times on it while never rolling back the earlier VRs. Those VRs
> continue to hold a reference to new_tree acquired via
> mlxsw_sp_lpm_tree_hold(), leaking the reference count of new_tree.
> 
> Fix by reinitializing vr inside the error loop with the updated index:
> 
> 	vr = &mlxsw_sp->router->vrs[i];
> 
> so that the loop correctly iterates over all VRs that were actually
> replaced.
> 
> Cc: stable@vger.kernel.org
> Fixes: fc922bb0dd94 ("mlxsw: spectrum_router: Use one LPM tree for all virtual routers")
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>

Reviewed-by: Ido Schimmel <idosch@nvidia.com>

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

* Re: [PATCH] mlxsw: fix refcount leak in mlxsw_sp_vrs_lpm_tree_replace()
  2026-06-09  8:47 [PATCH] mlxsw: fix refcount leak in mlxsw_sp_vrs_lpm_tree_replace() Wentao Liang
  2026-06-11  6:18 ` Ido Schimmel
@ 2026-06-11 23:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-06-11 23:00 UTC (permalink / raw)
  To: WenTao Liang
  Cc: idosch, petrm, andrew+netdev, davem, edumazet, kuba, pabeni,
	netdev, linux-kernel, stable

Hello:

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

On Tue,  9 Jun 2026 08:47:30 +0000 you wrote:
> When mlxsw_sp_vrs_lpm_tree_replace() fails after replacing some VRs,
> the error rollback loop does not correctly revert the preceding
> replacements. The loop decrements the index but fails to update the
> vr pointer, which still points to the VR that caused the failure. As
> a result, the condition and the rollback call always operate on the
> same VR, potentially calling mlxsw_sp_vr_lpm_tree_replace() multiple
> times on it while never rolling back the earlier VRs. Those VRs
> continue to hold a reference to new_tree acquired via
> mlxsw_sp_lpm_tree_hold(), leaking the reference count of new_tree.
> 
> [...]

Here is the summary with links:
  - mlxsw: fix refcount leak in mlxsw_sp_vrs_lpm_tree_replace()
    https://git.kernel.org/netdev/net-next/c/21cf8dc478a4

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:[~2026-06-11 23:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-09  8:47 [PATCH] mlxsw: fix refcount leak in mlxsw_sp_vrs_lpm_tree_replace() Wentao Liang
2026-06-11  6:18 ` Ido Schimmel
2026-06-11 23:00 ` 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