Thread View: linux.kernel.netdev
1 messages
1 total messages
Started by Hangbin Liu
Fri, 06 Nov 2026 01:34
[PATCH net RESEND v5] bonding: fix slave_cnt leak on XDP error paths
Author: Hangbin Liu
Date: Fri, 06 Nov 2026 01:34
Date: Fri, 06 Nov 2026 01:34
112 lines
12619 bytes
12619 bytes
From: Hangbin Liu <liuhangbin@kylinos.cn>
When bond_enslave() succeeds up to the XDP setup stage, slave_cnt is
already incremented. If XDP setup subsequently fails, the error paths
jump directly to err_sysfs_del, bypassing the slave_cnt decrement.
This causes slave_cnt to drift upward on each failed enslaving attempt,
which would lead to unbalanced traffic distribution with round-robin
mode.
Add an error out to make sure slave_cnt gets decreased correctly.
Fixes: 9e2ee5c7e7c3 ("net, bonding: Add XDP support to the bonding driver")
Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
This issue is found during code review. The reproducer is from
Eric's patch
ip link add bond0 type bond mode balance-rr
ip link set bond0 xdpdrv obj xdp_dummy.bpf.o sec xdp
for i in 0 1 2; do
ip link add d$i type dummy
ip link set d$i master bond0 # fails: Slave does not support XDP
done
num_slaves read via SIOCBONDINFOQUERY is 3 before this patch, 0 after.
For Sashiko:
This patch only focuses on fixing the bond_slave_cnt leak issue.
1. `bond_xdp_xmit()` may call the slave's `ndo_xdp_xmit` before checking
whether `slave->netdev_ops->ndo_xdp_xmit` exists. This is a separate issue
and I will address it in another patch.
2. `bond_slave_ns_maddrs_add()` and device promiscuous/allmulti error
handling are also separate issues, which I will fix separately.
PS: I'm working on a restruct of bond_enslave to fix all these issues.
---
Changes in v5:
- Re-post, no code change.
- Link to v4: https://lore.kernel.org/r/20260914-bond_slave_cnt-v4-1-d14864a39e60@kylinos.cn
Changes in v4:
- Revert to v1 version as the bond_select_active_slave() just under
slave_cnt increase also calls bond_update_slave_arr() (sashiko)
- re-run all bonding selftests with debug kernel, all passed.
- Link to v3: https://lore.kernel.org/r/20260907-bond_slave_cnt-v3-1-57df3b3cf2cb@kylinos.cn
Changes in v3:
- move the slave_cnt increasement before bond_update_slave_arr() (selftest)
- run all bonding selftests on debug kernel to make sure no regression (Jakub)
- Link to v2: https://lore.kernel.org/r/20260903-bond_slave_cnt-v2-1-02e27304ca36@kylinos.cn
Changes in v2:
- move the slave_cnt increasement after XDP setup (Nikolay Aleksandrov)
- balance-xor mode is not affected, not mention it (Nikolay Aleksandrov)
- Link to v1: https://lore.kernel.org/r/20260902-bond_slave_cnt-v1-1-36e95bf4a6ff@kylinos.cn
---
drivers/net/bonding/bond_main.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index a1c156c145b2..34f1b8083fbb 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -2305,7 +2305,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
SLAVE_NL_ERR(bond_dev, slave_dev, extack,
"Slave does not support XDP");
res = -EOPNOTSUPP;
- goto err_sysfs_del;
+ goto err_slave_cnt;
}
} else if (bond->xdp_prog) {
struct netdev_bpf xdp = {
@@ -2319,14 +2319,14 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
SLAVE_NL_ERR(bond_dev, slave_dev, extack,
"Slave has XDP program loaded, please unload before enslaving");
res = -EOPNOTSUPP;
- goto err_sysfs_del;
+ goto err_slave_cnt;
}
res = dev_xdp_propagate(slave_dev, &xdp);
if (res < 0) {
/* ndo_bpf() sets extack error message */
slave_dbg(bond_dev, slave_dev, "Error %d calling ndo_bpf\n", res);
- goto err_sysfs_del;
+ goto err_slave_cnt;
}
if (bond->xdp_prog)
bpf_prog_inc(bond->xdp_prog);
@@ -2348,6 +2348,9 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
return 0;
/* Undo stages on error */
+err_slave_cnt:
+ WRITE_ONCE(bond->slave_cnt, bond->slave_cnt - 1);
+
err_sysfs_del:
bond_sysfs_slave_del(new_slave);
---
base-commit: fafbc4051123d5459ea6950899cec08ed946e278
change-id: 20260807-bond_slave_cnt-88e78c5f0ab9
Best regards,
--
Hangbin Liu <liuhangbin@kylinos.cn>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads