Skip to contentSkip to conversation

bonding: fix the program leak when XDP is replaced

PATCH Applied Jakub Kicinski 4 participants 4 messages Oct 1 – Oct 2

Subsystems (3)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 bonding: fix the program leak when XDP is replaced

We need to release the reference on the old BPF prog, whether we are going to no-prog, or replacing the prog with another.

Spotted by AI while running tests for the propagation series (leaked programs were accumulating). Selftest will come in the net-next series to avoid conflicts.

Fixes 9e2ee5c7e7c3 ("net, bonding: Add XDP support to the bonding driver")
Fixes 6d5f1ef83868 ("bonding: Fix negative jump label count on nested bonding")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 drivers/net/bonding/bond_main.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/bonding/bond_main.c +4 -4
index de2489c3d9bf..09aa45d71fab 100644
@@ -5732,12 +5732,12 @@ static int bond_xdp_set(struct net_device *dev, struct bpf_prog *prog,
 			bpf_prog_inc(prog);
 	}
 
-	if (prog) {
+	if (prog && !old_prog)
 		static_branch_inc(&bpf_master_redirect_enabled_key);
-	} else if (old_prog) {
-		bpf_prog_put(old_prog);
+	else if (!prog && old_prog)
 		static_branch_dec(&bpf_master_redirect_enabled_key);
-	}
+	if (old_prog)
+		bpf_prog_put(old_prog);
 
 	return 0;
 
Signature · 1 line
2.55.0
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Jakub Kicinski

We need to release the reference on the old BPF prog, whether we are going to no-prog, or replacing the prog with another.

Spotted by AI while running tests for the propagation series (leaked programs were accumulating). Selftest will come in the net-next series to avoid conflicts.

Fixes 9e2ee5c7e7c3 ("net, bonding: Add XDP support to the bonding driver")
Fixes 6d5f1ef83868 ("bonding: Fix negative jump label count on nested bonding")
Reviewed-by on v1 1/1
#2 lore raw
In reply to Jakub Kicinski
Quoted 10 lines · Jakub Kicinski

We need to release the reference on the old BPF prog, whether we are going to no-prog, or replacing the prog with another.

Spotted by AI while running tests for the propagation series (leaked programs were accumulating). Selftest will come in the net-next series to avoid conflicts.

Fixes 9e2ee5c7e7c3 ("net, bonding: Add XDP support to the bonding driver")
Fixes 6d5f1ef83868 ("bonding: Fix negative jump label count on nested bonding")
Quoted 29 lines

---
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
  drivers/net/bonding/bond_main.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/bonding/bond_main.c +4 -4
index de2489c3d9bf..09aa45d71fab 100644
@@ -5732,12 +5732,12 @@ static int bond_xdp_set(struct net_device *dev, struct bpf_prog *prog,
  			bpf_prog_inc(prog);
  	}
 
-	if (prog) {
+	if (prog && !old_prog)
  		static_branch_inc(&bpf_master_redirect_enabled_key);
-	} else if (old_prog) {
-		bpf_prog_put(old_prog);
+	else if (!prog && old_prog)
  		static_branch_dec(&bpf_master_redirect_enabled_key);
-	}
+	if (old_prog)
+		bpf_prog_put(old_prog);
 
  	return 0;
 
#3 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 8 lines · On Wed, 30 Sep 2026 18:26:39 -0700 you wrote:

We need to release the reference on the old BPF prog, whether we are going to no-prog, or replacing the prog with another.

Spotted by AI while running tests for the propagation series (leaked programs were accumulating). Selftest will come in the net-next series to avoid conflicts.

[...]

Here is the summary with links:
- [net] bonding: fix the program leak when XDP is replaced

    https://git.kernel.org/netdev/net/c/184b5ddf82d4

You are awesome, thank you!

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