Skip to contentSkip to conversation

net/mlx5e: TC, Fix parse_attr leak on branch attr alloc failure

PATCH Applied Tariq Toukan 3 participants 3 messages Nov 26 – Dec 2

Subsystems (5)
lore
Share & tools
lore

Tariq Toukan

author maintainer
#0 lore raw

PATCH 1/1 net/mlx5e: TC, Fix parse_attr leak on branch attr alloc failure

alloc_branch_attr() gets the branch attribute from mlx5e_clone_flow_attr_for_post_act(), which also allocates its parse_attr. When the branch action cannot be offloaded, the error path frees the attribute but not its parse_attr, leaking it.

This happens, for example, when a police action's conform and exceed actions are both jumps: the exceed action fails with "Cannot offload flows with nested jumps".

Free the parse_attr too.

Found by LLM-assisted code inspection, while reviewing a fix for a double free on the same error path.

Reproduced on ConnectX-6 Dx in switchdev mode, with kmemleak, by failing 50 times to offload such a filter on the uplink representor:

  tc filter add dev $UPLINK ingress protocol ip flower skip_sw \
          dst_ip 192.0.2.2 action police rate 1mbit burst 20k \
          conform-exceed jump 1 / jump 1 action pass action drop

Without this patch, kmemleak reported 29 unreferenced 4096-byte objects, all allocated by mlx5e_clone_flow_attr_for_post_act() from alloc_branch_attr(). With it, kmemleak reported none.

Fixes f86488cb4685 ("net/mlx5e: TC, initialize branch flow attributes")
---
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +2 -1
index 011741553f5b..142cccba907e 100644
@@ -3915,7 +3915,8 @@ alloc_branch_attr(struct mlx5e_tc_flow *flow,
 
 	return err;
 out_err:
-	kfree(*cond_attr);
+	kvfree(attr->parse_attr);
+	kfree(attr);
 	*cond_attr = NULL;
 	return err;
 }

base-commit: cc7fe6e741730fef549e484379281736d32746f0

Signature · 1 line
2.44.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 21 lines

alloc_branch_attr() gets the branch attribute from mlx5e_clone_flow_attr_for_post_act(), which also allocates its parse_attr. When the branch action cannot be offloaded, the error path frees the attribute but not its parse_attr, leaking it.

This happens, for example, when a police action's conform and exceed actions are both jumps: the exceed action fails with "Cannot offload flows with nested jumps".

Free the parse_attr too.

Found by LLM-assisted code inspection, while reviewing a fix for a double free on the same error path.

Reproduced on ConnectX-6 Dx in switchdev mode, with kmemleak, by failing 50 times to offload such a filter on the uplink representor:

  tc filter add dev $UPLINK ingress protocol ip flower skip_sw \
          dst_ip 192.0.2.2 action police rate 1mbit burst 20k \
          conform-exceed jump 1 / jump 1 action pass action drop
Quoted 6 lines

Without this patch, kmemleak reported 29 unreferenced 4096-byte objects, all allocated by mlx5e_clone_flow_attr_for_post_act() from alloc_branch_attr(). With it, kmemleak reported none.

Fixes f86488cb4685 ("net/mlx5e: TC, initialize branch flow attributes")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Tariq Toukan
This patch was applied to netdev/net.git (main) by Willem de Bruijn <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Willem de Bruijn <[email protected]>:

Quoted 10 lines · On Thu, 26 Nov 2026 14:23:16 +0200 you wrote:

alloc_branch_attr() gets the branch attribute from mlx5e_clone_flow_attr_for_post_act(), which also allocates its parse_attr. When the branch action cannot be offloaded, the error path frees the attribute but not its parse_attr, leaking it.

This happens, for example, when a police action's conform and exceed actions are both jumps: the exceed action fails with "Cannot offload flows with nested jumps".

[...]

Here is the summary with links:
- [net] net/mlx5e: TC, Fix parse_attr leak on branch attr alloc failure

    https://git.kernel.org/netdev/net/c/ce0791c3406e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html