* [PATCH net-next 0/6] bonding: refactor bond_enslave() to fix XDP ordering and error rollback
@ 2026-11-13 14:04 Hangbin Liu
2026-11-13 14:04 ` [PATCH net-next 1/6] bonding: check XDP support before enslaving changes state Hangbin Liu
` (6 more replies)
0 siblings, 7 replies; 13+ messages in thread
From: Hangbin Liu @ 2026-11-13 14:04 UTC (permalink / raw)
To: Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev
Cc: Hangbin Liu, netdev, linux-kernel, bpf, Hangbin Liu
`bond_enslave()` is over 500 lines long with complex logic and numerous
error rollback paths. It has XDP ordering isssue and missing some error
rollbacks for historical reasons (found by Sashiko when review bond
patches). The fixes are trivial, I plan to refactor the function to make
the logic clearer and resolved the issues. This patch set is the first
phase.
This series hardens bond_enslave() in two stages: first fix real
ordering and rollback bugs, then factor the function so the
infallible commit point and fail-fast validation stay obvious.
Problems fixed (patches 1-3):
1. XDP capability checks ran after the slave was opened, linked and
could already be visible to the datapath . A slave without
ndo_xdp_xmit could therefore be reached from bond_xdp_xmit().
Checks move to the top of bond_enslave(), before any mutation.
2. Fallible XDP setup (dev_xdp_propagate()) ran after publication.
On failure the undo ladder jumped to err_sysfs_del and leaked:
- promiscuity / allmulti / synced addresses
- ns maddrs added just before the failure
3. Error paths were incomplete versus release:
- bond_alb_init_slave() success + later failure skipped
bond_alb_deinit_slave() (TLB/RLB state, borrowed MAC)
- bond_3ad_bind_slave() + later failure skipped
bond_3ad_unbind_slave() (port left on its aggregator)
- automatic fail_over_mac = "active" was not restored on failure
Cleanup (patches 4-6), no intended behaviour change beyond patch 5's
extack string alignment:
4. bond_publish_slave() — explicit infallible commit point
5. bond_slave_xdp_check() — shared by bond_enslave() and bond_xdp_set()
6. bond_enslave_validate() — all read-only checks
Testing: build debug kernel and run all kernel selftests
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
Hangbin Liu (6):
bonding: check XDP support before enslaving changes state
bonding: finish XDP setup before publishing the slave
bonding: complete rollback of bond_enslave() error paths
bonding: factor out slave publication
bonding: factor out XDP slave check
bonding: factor out bond_enslave_validate
drivers/net/bonding/bond_main.c | 174 ++++++++++++++++++++++++++--------------
1 file changed, 116 insertions(+), 58 deletions(-)
---
base-commit: 573af801552999954caa8347e4490b04cf4763f0
change-id: 20261020-bond_enslave_restruct-30760e62def9
Best regards,
--
Hangbin Liu <liuhangbin@kylinos.cn>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH net-next 1/6] bonding: check XDP support before enslaving changes state
2026-11-13 14:04 [PATCH net-next 0/6] bonding: refactor bond_enslave() to fix XDP ordering and error rollback Hangbin Liu
@ 2026-11-13 14:04 ` Hangbin Liu
2026-11-17 14:40 ` netdev-bot+sashiko
2026-11-13 14:04 ` [PATCH net-next 2/6] bonding: finish XDP setup before publishing the slave Hangbin Liu
` (5 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Hangbin Liu @ 2026-11-13 14:04 UTC (permalink / raw)
To: Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev
Cc: Hangbin Liu, netdev, linux-kernel, bpf, Hangbin Liu
From: Hangbin Liu <liuhangbin@kylinos.cn>
The XDP capability checks (ndo_bpf/ndo_xdp_xmit) and the slave XDP
program count check in bond_enslave() run after the slave has already
been opened, attached and made visible to the datapath. In particular
the slave can become bond->curr_active_slave, or be published via
bond->slave_cnt, before we verify that slave_dev->netdev_ops->ndo_xdp_xmit
exists, so bond_xdp_xmit() may call a NULL ndo_xdp_xmit.
Move both checks to the validation section at the top of bond_enslave(),
before the first state change. On failure nothing has been mutated yet,
so the function can return directly. The dev_xdp_propagate() setup is
left in place for now and still uses the same error path.
Error messages and errno values are unchanged (-EOPNOTSUPP with the
same netlink extack strings), and the success path is unaffected
beyond running the read-only checks earlier.
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
drivers/net/bonding/bond_main.c | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 9249a79a168e..340af4c3fa20 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1948,6 +1948,23 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
return -EPERM;
}
+ /* Check XDP support before any state change, so a slave without
+ * XDP can never become visible to bond_xdp_xmit().
+ */
+ if (bond->xdp_prog) {
+ if (!slave_ops->ndo_bpf || !slave_ops->ndo_xdp_xmit) {
+ SLAVE_NL_ERR(bond_dev, slave_dev, extack,
+ "Slave does not support XDP");
+ return -EOPNOTSUPP;
+ }
+
+ if (dev_xdp_prog_count(slave_dev) > 0) {
+ SLAVE_NL_ERR(bond_dev, slave_dev, extack,
+ "Slave has XDP program loaded, please unload before enslaving");
+ return -EOPNOTSUPP;
+ }
+ }
+
/* set bonding device ether type by slave - bonding netdevices are
* created with ether_setup, so when the slave type is not ARPHRD_ETHER
* there is a need to override some of the type dependent attribs/funcs.
@@ -2311,15 +2328,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
unblock_netpoll_tx();
}
- if (!slave_dev->netdev_ops->ndo_bpf ||
- !slave_dev->netdev_ops->ndo_xdp_xmit) {
- if (bond->xdp_prog) {
- SLAVE_NL_ERR(bond_dev, slave_dev, extack,
- "Slave does not support XDP");
- res = -EOPNOTSUPP;
- goto err_dec_slave_cnt;
- }
- } else if (bond->xdp_prog) {
+ /* XDP capability and prog-count were already validated above */
+ if (bond->xdp_prog) {
struct netdev_bpf xdp = {
.command = XDP_SETUP_PROG,
.flags = 0,
@@ -2327,13 +2337,6 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
.extack = extack,
};
- if (dev_xdp_prog_count(slave_dev) > 0) {
- SLAVE_NL_ERR(bond_dev, slave_dev, extack,
- "Slave has XDP program loaded, please unload before enslaving");
- res = -EOPNOTSUPP;
- goto err_dec_slave_cnt;
- }
-
res = dev_xdp_propagate(slave_dev, &xdp);
if (res < 0) {
/* ndo_bpf() sets extack error message */
--
2.56.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH net-next 2/6] bonding: finish XDP setup before publishing the slave
2026-11-13 14:04 [PATCH net-next 0/6] bonding: refactor bond_enslave() to fix XDP ordering and error rollback Hangbin Liu
2026-11-13 14:04 ` [PATCH net-next 1/6] bonding: check XDP support before enslaving changes state Hangbin Liu
@ 2026-11-13 14:04 ` Hangbin Liu
2026-11-17 14:40 ` netdev-bot+sashiko
2026-11-13 14:04 ` [PATCH net-next 3/6] bonding: complete rollback of bond_enslave() error paths Hangbin Liu
` (4 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Hangbin Liu @ 2026-11-13 14:04 UTC (permalink / raw)
To: Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev
Cc: Hangbin Liu, netdev, linux-kernel, bpf, Hangbin Liu
From: Hangbin Liu <liuhangbin@kylinos.cn>
bond_enslave() currently runs the fallible XDP setup
(dev_xdp_propagate()) after the slave has already been published:
slave_cnt is incremented, ns maddrs are added and the active slave
may have been selected. If XDP setup then fails, the error path
jumps to err_sysfs_del and leaks:
- the promiscuity/allmulti increments and synced addresses applied
to the slave earlier in the function, which are only undone on
an immediate allmulti failure,
- the ns maddrs added just before the failure, which no enslave
error path ever removes.
Move dev_xdp_propagate() to the last fallible step, right after the
promiscuity/allmulti/address-sync block and before
WRITE_ONCE(bond->slave_cnt), so that no handled fallible call
follows the publication of the slave and a failure can no longer
leak slave_cnt or ns maddrs.
bond_xdp_set_features() is moved along with this reordering so XDP
features are updated before the slave is published. Route the XDP
failure through a new err_set_xdp label that undoes the promiscuity,
allmulti and address-sync state, mirroring what __bond_release_one()
does.
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
drivers/net/bonding/bond_main.c | 52 +++++++++++++++++++++++++----------------
1 file changed, 32 insertions(+), 20 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 340af4c3fa20..80b6c18ee9c2 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -2313,22 +2313,11 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
}
}
- WRITE_ONCE(bond->slave_cnt, bond->slave_cnt + 1);
- netdev_compute_master_upper_features(bond->dev, true);
- bond_set_carrier(bond);
-
- /* Needs to be called before bond_select_active_slave(), which will
- * remove the maddrs if the slave is selected as active slave.
+ /* XDP capability and prog-count were already validated above.
+ * Setup runs as the last fallible step before the slave is
+ * published, so no undo of this block can ever be needed and
+ * a failure here cannot leak slave_cnt or ns maddrs.
*/
- bond_slave_ns_maddrs_add(bond, new_slave);
-
- if (bond_uses_primary(bond)) {
- block_netpoll_tx();
- bond_select_active_slave(bond);
- unblock_netpoll_tx();
- }
-
- /* XDP capability and prog-count were already validated above */
if (bond->xdp_prog) {
struct netdev_bpf xdp = {
.command = XDP_SETUP_PROG,
@@ -2341,19 +2330,35 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
if (res < 0) {
/* ndo_bpf() sets extack error message */
slave_dbg(bond_dev, slave_dev, "Error %d calling ndo_bpf\n", res);
- goto err_dec_slave_cnt;
+ goto err_set_xdp;
}
if (bond->xdp_prog)
bpf_prog_inc(bond->xdp_prog);
}
+ bond_xdp_set_features(bond_dev);
+
+ /* Must called before bond_update_slave_arr() or bond_select_active_slave() */
+ WRITE_ONCE(bond->slave_cnt, bond->slave_cnt + 1);
+ netdev_compute_master_upper_features(bond->dev, true);
+ bond_set_carrier(bond);
+
+ /* Needs to be called before bond_select_active_slave(), which will
+ * remove the maddrs if the slave is selected as active slave.
+ */
+ bond_slave_ns_maddrs_add(bond, new_slave);
+
+ if (bond_uses_primary(bond)) {
+ block_netpoll_tx();
+ bond_select_active_slave(bond);
+ unblock_netpoll_tx();
+ }
+
/* broadcast mode uses the all_slaves to loop through slaves. */
if (bond_mode_can_use_xmit_hash(bond) ||
BOND_MODE(bond) == BOND_MODE_BROADCAST)
bond_update_slave_arr(bond, NULL);
- bond_xdp_set_features(bond_dev);
-
slave_info(bond_dev, slave_dev, "Enslaving as %s interface with %s link\n",
bond_is_active_slave(new_slave) ? "an active" : "a backup",
new_slave->link != BOND_LINK_DOWN ? "an up" : "a down");
@@ -2363,8 +2368,15 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
return 0;
/* Undo stages on error */
-err_dec_slave_cnt:
- WRITE_ONCE(bond->slave_cnt, bond->slave_cnt - 1);
+err_set_xdp:
+ if (!bond_uses_primary(bond)) {
+ if (bond_dev->flags & IFF_PROMISC)
+ dev_set_promiscuity(slave_dev, -1);
+ if (bond_dev->flags & IFF_ALLMULTI)
+ dev_set_allmulti(slave_dev, -1);
+ if (bond_dev->flags & IFF_UP)
+ bond_hw_addr_flush(bond_dev, slave_dev);
+ }
err_sysfs_del:
bond_sysfs_slave_del(new_slave);
--
2.56.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH net-next 3/6] bonding: complete rollback of bond_enslave() error paths
2026-11-13 14:04 [PATCH net-next 0/6] bonding: refactor bond_enslave() to fix XDP ordering and error rollback Hangbin Liu
2026-11-13 14:04 ` [PATCH net-next 1/6] bonding: check XDP support before enslaving changes state Hangbin Liu
2026-11-13 14:04 ` [PATCH net-next 2/6] bonding: finish XDP setup before publishing the slave Hangbin Liu
@ 2026-11-13 14:04 ` Hangbin Liu
2026-11-17 14:40 ` netdev-bot+sashiko
2026-11-13 14:04 ` [PATCH net-next 4/6] bonding: factor out slave publication Hangbin Liu
` (3 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Hangbin Liu @ 2026-11-13 14:04 UTC (permalink / raw)
To: Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev
Cc: Hangbin Liu, netdev, linux-kernel, bpf, Hangbin Liu
From: Hangbin Liu <liuhangbin@kylinos.cn>
The bond_enslave() undo labels are missing three cleanups that the
release path (__bond_release_one) already performs:
- If bond_alb_init_slave() succeeds but a later step fails, the
slave is never passed to bond_alb_deinit_slave(), leaving TLB/RLB
state and a possibly borrowed MAC address behind.
- If the slave is bound into 802.3ad (bond_3ad_bind_slave()) and a
later step fails, bond_3ad_unbind_slave() is never called, so the
port stays attached to its aggregator.
- When fail_over_mac is automatically set to "active" because the
first slave cannot change its MAC address, a subsequent failure
leaves the modified parameter on the bond.
Add undo steps for these 3 cleanups when error out.
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
drivers/net/bonding/bond_main.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 80b6c18ee9c2..f696a0d15034 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1890,7 +1890,9 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
{
struct bonding *bond = netdev_priv(bond_dev);
const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
+ int orig_fail_over_mac = bond->params.fail_over_mac;
struct slave *new_slave = NULL, *prev_slave;
+ bool alb_initialized = false;
struct sockaddr_storage ss;
int res = 0, i;
@@ -2120,6 +2122,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
res = bond_alb_init_slave(bond, new_slave);
if (res)
goto err_close;
+ alb_initialized = true;
}
res = vlan_vids_add_by_dev(slave_dev, bond_dev);
@@ -2388,6 +2391,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
netdev_rx_handler_unregister(slave_dev);
err_detach:
+ if (BOND_MODE(bond) == BOND_MODE_8023AD)
+ bond_3ad_unbind_slave(new_slave);
vlan_vids_del_by_dev(slave_dev, bond_dev);
if (rcu_access_pointer(bond->primary_slave) == new_slave)
RCU_INIT_POINTER(bond->primary_slave, NULL);
@@ -2402,6 +2407,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
slave_disable_netpoll(new_slave);
err_close:
+ if (alb_initialized)
+ bond_alb_deinit_slave(bond, new_slave);
if (!netif_is_bond_master(slave_dev))
slave_dev->priv_flags &= ~IFF_BONDING;
dev_close(slave_dev);
@@ -2427,6 +2434,11 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
kobject_put(&new_slave->kobj);
err_undo_flags:
+ /* Restore fail_over_mac in case the automatic "active" setting
+ * above was applied and a later step failed.
+ */
+ bond->params.fail_over_mac = orig_fail_over_mac;
+
/* Enslave of first slave has failed and we need to fix master's mac */
if (!bond_has_slaves(bond)) {
if (ether_addr_equal_64bits(bond_dev->dev_addr,
--
2.56.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH net-next 4/6] bonding: factor out slave publication
2026-11-13 14:04 [PATCH net-next 0/6] bonding: refactor bond_enslave() to fix XDP ordering and error rollback Hangbin Liu
` (2 preceding siblings ...)
2026-11-13 14:04 ` [PATCH net-next 3/6] bonding: complete rollback of bond_enslave() error paths Hangbin Liu
@ 2026-11-13 14:04 ` Hangbin Liu
2026-11-17 14:40 ` netdev-bot+sashiko
2026-11-13 14:04 ` [PATCH net-next 5/6] bonding: factor out XDP slave check Hangbin Liu
` (2 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Hangbin Liu @ 2026-11-13 14:04 UTC (permalink / raw)
To: Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev
Cc: Hangbin Liu, netdev, linux-kernel, bpf, Hangbin Liu
From: Hangbin Liu <liuhangbin@kylinos.cn>
Factor the publication step of bond_enslave() into bond_publish_slave()
so the infallible "commit point" of the function is explicit and cannot
be interleaved with new fallible code by accident.
No functional change.
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
drivers/net/bonding/bond_main.c | 49 ++++++++++++++++++++++++-----------------
1 file changed, 29 insertions(+), 20 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index f696a0d15034..bb3752683456 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1884,6 +1884,34 @@ void bond_xdp_set_features(struct net_device *bond_dev)
xdp_set_features_flag(bond_dev, val);
}
+/* Make the fully prepared slave visible to the rest of the bonding
+ * code. All fallible steps of bond_enslave() must have completed
+ * before this runs: error paths never undo the publication.
+ */
+static void bond_publish_slave(struct bonding *bond, struct slave *slave)
+{
+ /* Must called before bond_update_slave_arr() or bond_select_active_slave() */
+ WRITE_ONCE(bond->slave_cnt, bond->slave_cnt + 1);
+ netdev_compute_master_upper_features(bond->dev, true);
+ bond_set_carrier(bond);
+
+ /* Needs to be called before bond_select_active_slave(), which will
+ * remove the maddrs if the slave is selected as active slave.
+ */
+ bond_slave_ns_maddrs_add(bond, slave);
+
+ if (bond_uses_primary(bond)) {
+ block_netpoll_tx();
+ bond_select_active_slave(bond);
+ unblock_netpoll_tx();
+ }
+
+ /* broadcast mode uses the all_slaves to loop through slaves. */
+ if (bond_mode_can_use_xmit_hash(bond) ||
+ BOND_MODE(bond) == BOND_MODE_BROADCAST)
+ bond_update_slave_arr(bond, NULL);
+}
+
/* enslave device <slave> to bond device <master> */
int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
struct netlink_ext_ack *extack)
@@ -2341,26 +2369,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
bond_xdp_set_features(bond_dev);
- /* Must called before bond_update_slave_arr() or bond_select_active_slave() */
- WRITE_ONCE(bond->slave_cnt, bond->slave_cnt + 1);
- netdev_compute_master_upper_features(bond->dev, true);
- bond_set_carrier(bond);
-
- /* Needs to be called before bond_select_active_slave(), which will
- * remove the maddrs if the slave is selected as active slave.
- */
- bond_slave_ns_maddrs_add(bond, new_slave);
-
- if (bond_uses_primary(bond)) {
- block_netpoll_tx();
- bond_select_active_slave(bond);
- unblock_netpoll_tx();
- }
-
- /* broadcast mode uses the all_slaves to loop through slaves. */
- if (bond_mode_can_use_xmit_hash(bond) ||
- BOND_MODE(bond) == BOND_MODE_BROADCAST)
- bond_update_slave_arr(bond, NULL);
+ bond_publish_slave(bond, new_slave);
slave_info(bond_dev, slave_dev, "Enslaving as %s interface with %s link\n",
bond_is_active_slave(new_slave) ? "an active" : "a backup",
--
2.56.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH net-next 5/6] bonding: factor out XDP slave check
2026-11-13 14:04 [PATCH net-next 0/6] bonding: refactor bond_enslave() to fix XDP ordering and error rollback Hangbin Liu
` (3 preceding siblings ...)
2026-11-13 14:04 ` [PATCH net-next 4/6] bonding: factor out slave publication Hangbin Liu
@ 2026-11-13 14:04 ` Hangbin Liu
2026-11-13 14:04 ` [PATCH net-next 6/6] bonding: factor out bond_enslave_validate Hangbin Liu
2026-11-13 14:11 ` [PATCH net-next 0/6] bonding: refactor bond_enslave() to fix XDP ordering and error rollback netdev-bot+sinfo
6 siblings, 0 replies; 13+ messages in thread
From: Hangbin Liu @ 2026-11-13 14:04 UTC (permalink / raw)
To: Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev
Cc: Hangbin Liu, netdev, linux-kernel, bpf, Hangbin Liu
From: Hangbin Liu <liuhangbin@kylinos.cn>
bond_enslave() and bond_xdp_set() carry near-identical XDP slave
capability checks. Factor them into bond_slave_xdp_check() so the
two paths cannot drift apart.
The only behaviour difference is the netlink extack string in
bond_xdp_set(): "Slave device does not support XDP" becomes
"Slave does not support XDP" to match bond_enslave(). Logic and
return values are unchanged.
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
drivers/net/bonding/bond_main.c | 52 ++++++++++++++++++++++-------------------
1 file changed, 28 insertions(+), 24 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index bb3752683456..5e36612cfaec 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1884,6 +1884,29 @@ void bond_xdp_set_features(struct net_device *bond_dev)
xdp_set_features_flag(bond_dev, val);
}
+/* Verify that slave_dev can take part in the bond's XDP datapath.
+ * Returns 0 if the slave is usable, otherwise -EOPNOTSUPP.
+ */
+static int bond_slave_xdp_check(struct net_device *bond_dev,
+ struct net_device *slave_dev,
+ struct netlink_ext_ack *extack)
+{
+ if (!slave_dev->netdev_ops->ndo_bpf ||
+ !slave_dev->netdev_ops->ndo_xdp_xmit) {
+ SLAVE_NL_ERR(bond_dev, slave_dev, extack,
+ "Slave does not support XDP");
+ return -EOPNOTSUPP;
+ }
+
+ if (dev_xdp_prog_count(slave_dev) > 0) {
+ SLAVE_NL_ERR(bond_dev, slave_dev, extack,
+ "Slave has XDP program loaded, please unload before enslaving");
+ return -EOPNOTSUPP;
+ }
+
+ return 0;
+}
+
/* Make the fully prepared slave visible to the rest of the bonding
* code. All fallible steps of bond_enslave() must have completed
* before this runs: error paths never undo the publication.
@@ -1982,17 +2005,9 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
* XDP can never become visible to bond_xdp_xmit().
*/
if (bond->xdp_prog) {
- if (!slave_ops->ndo_bpf || !slave_ops->ndo_xdp_xmit) {
- SLAVE_NL_ERR(bond_dev, slave_dev, extack,
- "Slave does not support XDP");
- return -EOPNOTSUPP;
- }
-
- if (dev_xdp_prog_count(slave_dev) > 0) {
- SLAVE_NL_ERR(bond_dev, slave_dev, extack,
- "Slave has XDP program loaded, please unload before enslaving");
- return -EOPNOTSUPP;
- }
+ res = bond_slave_xdp_check(bond_dev, slave_dev, extack);
+ if (res)
+ return res;
}
/* set bonding device ether type by slave - bonding netdevices are
@@ -5764,20 +5779,9 @@ static int bond_xdp_set(struct net_device *dev, struct bpf_prog *prog,
bond_for_each_slave(bond, slave, iter) {
struct net_device *slave_dev = slave->dev;
- if (!slave_dev->netdev_ops->ndo_bpf ||
- !slave_dev->netdev_ops->ndo_xdp_xmit) {
- SLAVE_NL_ERR(dev, slave_dev, extack,
- "Slave device does not support XDP");
- err = -EOPNOTSUPP;
+ err = bond_slave_xdp_check(dev, slave_dev, extack);
+ if (err)
goto err;
- }
-
- if (dev_xdp_prog_count(slave_dev) > 0) {
- SLAVE_NL_ERR(dev, slave_dev, extack,
- "Slave has XDP program loaded, please unload before enslaving");
- err = -EOPNOTSUPP;
- goto err;
- }
err = dev_xdp_propagate(slave_dev, &xdp);
if (err < 0) {
--
2.56.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH net-next 6/6] bonding: factor out bond_enslave_validate
2026-11-13 14:04 [PATCH net-next 0/6] bonding: refactor bond_enslave() to fix XDP ordering and error rollback Hangbin Liu
` (4 preceding siblings ...)
2026-11-13 14:04 ` [PATCH net-next 5/6] bonding: factor out XDP slave check Hangbin Liu
@ 2026-11-13 14:04 ` Hangbin Liu
2026-11-17 14:40 ` netdev-bot+sashiko
2026-11-13 14:11 ` [PATCH net-next 0/6] bonding: refactor bond_enslave() to fix XDP ordering and error rollback netdev-bot+sinfo
6 siblings, 1 reply; 13+ messages in thread
From: Hangbin Liu @ 2026-11-13 14:04 UTC (permalink / raw)
To: Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev
Cc: Hangbin Liu, netdev, linux-kernel, bpf, Hangbin Liu
From: Hangbin Liu <liuhangbin@kylinos.cn>
bond_enslave() is a long linear function whose flow is hard to see
behind the inline blocks. Factor out bond_enslave_validate to do
all read-only checks.
Failures return directly, no undo needed at that point.
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
drivers/net/bonding/bond_main.c | 36 +++++++++++++++++++++++++++---------
1 file changed, 27 insertions(+), 9 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 5e36612cfaec..8f97b0e2c0b3 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1935,17 +1935,16 @@ static void bond_publish_slave(struct bonding *bond, struct slave *slave)
bond_update_slave_arr(bond, NULL);
}
-/* enslave device <slave> to bond device <master> */
-int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
- struct netlink_ext_ack *extack)
+/* Fail-fast validation of the slave and the bond. Everything here
+ * reads state only, so a failure needs no undo. Must stay ahead of
+ * the first mutation in bond_enslave().
+ */
+static int bond_enslave_validate(struct net_device *bond_dev,
+ struct net_device *slave_dev,
+ struct netlink_ext_ack *extack)
{
struct bonding *bond = netdev_priv(bond_dev);
- const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
- int orig_fail_over_mac = bond->params.fail_over_mac;
- struct slave *new_slave = NULL, *prev_slave;
- bool alb_initialized = false;
- struct sockaddr_storage ss;
- int res = 0, i;
+ int res;
if (slave_dev->type == ARPHRD_CAN) {
BOND_NL_ERR(bond_dev, extack,
@@ -2010,6 +2009,25 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
return res;
}
+ return 0;
+}
+
+/* enslave device <slave> to bond device <master> */
+int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
+ struct netlink_ext_ack *extack)
+{
+ struct bonding *bond = netdev_priv(bond_dev);
+ const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
+ int orig_fail_over_mac = bond->params.fail_over_mac;
+ struct slave *new_slave = NULL, *prev_slave;
+ bool alb_initialized = false;
+ struct sockaddr_storage ss;
+ int res = 0, i;
+
+ res = bond_enslave_validate(bond_dev, slave_dev, extack);
+ if (res)
+ return res;
+
/* set bonding device ether type by slave - bonding netdevices are
* created with ether_setup, so when the slave type is not ARPHRD_ETHER
* there is a need to override some of the type dependent attribs/funcs.
--
2.56.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH net-next 0/6] bonding: refactor bond_enslave() to fix XDP ordering and error rollback
2026-11-13 14:04 [PATCH net-next 0/6] bonding: refactor bond_enslave() to fix XDP ordering and error rollback Hangbin Liu
` (5 preceding siblings ...)
2026-11-13 14:04 ` [PATCH net-next 6/6] bonding: factor out bond_enslave_validate Hangbin Liu
@ 2026-11-13 14:11 ` netdev-bot+sinfo
6 siblings, 0 replies; 13+ messages in thread
From: netdev-bot+sinfo @ 2026-11-13 14:11 UTC (permalink / raw)
To: Hangbin Liu
Cc: Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
netdev, linux-kernel, bpf
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account. If the series needs another revision for
other reasons, please include the information in the commit messages
then.
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net-next 1/6] bonding: check XDP support before enslaving changes state
2026-11-13 14:04 ` [PATCH net-next 1/6] bonding: check XDP support before enslaving changes state Hangbin Liu
@ 2026-11-17 14:40 ` netdev-bot+sashiko
0 siblings, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 14:40 UTC (permalink / raw)
To: hangbin.liu
Cc: jv, andrew+netdev, davem, edumazet, kuba, pabeni, ast, daniel,
hawk, john.fastabend, sdf, netdev, linux-kernel, bpf
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The fix is incomplete: a slave without ndo_xdp_xmit can still be
reached by bond_xdp_xmit() whenever the bond has no XDP program.
- [Low] The commit message presents this as a crash fix ("bond_xdp_xmit()
may call a NULL ndo_xdp_xmit"), but the commit has no Fixes: tag (and…
- [Low] The commit author (From:) is "Hangbin Liu
<hangbin.liu@linux.dev>", but the only Signed-off-by line is "Hangbin…
--
bonding: check XDP support before enslaving changes state
This commit moves two XDP checks in bond_enslave() to the validation
section at the top of the function: the ndo_bpf/ndo_xdp_xmit capability
check and the slave XDP program count check. They now run before the slave
is opened, attached and made visible to the datapath. The
dev_xdp_propagate() setup stays where it was.
> In particular
> the slave can become bond->curr_active_slave, or be published via
> bond->slave_cnt, before we verify that slave_dev->netdev_ops->ndo_xdp_xmit
> exists, so bond_xdp_xmit() may call a NULL ndo_xdp_xmit.
[Severity: Low]
The commit message describes this as a fix for a NULL ndo_xdp_xmit call,
but there is no Fixes: tag and no Cc: stable. Should there be a Fixes:
tag?
git blame shows the late capability and prog-count checks came from commit
9e2ee5c7e7c3 ("net, bonding: Add XDP support to the bonding driver"), and
commit 6d5f1ef83868 later restructured them.
> Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
[Severity: Low]
The author is Hangbin Liu <hangbin.liu@linux.dev>, but the only
Signed-off-by line uses <liuhangbin@kylinos.cn>. checkpatch reports this
as a From:/Signed-off-by: email address mismatch. Could the two addresses
be made to match?
> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> index 9249a79a168e4..340af4c3fa201 100644
> --- a/drivers/net/bonding/bond_main.c
> +++ b/drivers/net/bonding/bond_main.c
> @@ -1948,6 +1948,23 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
> return -EPERM;
> }
>
> + /* Check XDP support before any state change, so a slave without
> + * XDP can never become visible to bond_xdp_xmit().
> + */
> + if (bond->xdp_prog) {
> + if (!slave_ops->ndo_bpf || !slave_ops->ndo_xdp_xmit) {
> + SLAVE_NL_ERR(bond_dev, slave_dev, extack,
> + "Slave does not support XDP");
> + return -EOPNOTSUPP;
> + }
[Severity: High]
Does the "can never become visible" claim still hold when bond->xdp_prog
is NULL?
bond_xdp_xmit() is the bond's ndo_xdp_xmit. Devmap and bpf_redirect reach
it after only this check:
kernel/bpf/devmap.c:__xdp_enqueue() {
...
if (!(dev->xdp_features & NETDEV_XDP_ACT_NDO_XMIT))
return -EOPNOTSUPP;
...
}
bond_xdp_set_features() builds that flag from bond_xdp_check() and the
slaves' xdp_features. It never looks at bond->xdp_prog:
if (!bond_xdp_check(bond, BOND_MODE(bond)) || !bond_has_slaves(bond)) {
xdp_clear_features_flag(bond_dev);
return;
}
bond_for_each_slave(bond, slave, iter)
val &= slave->dev->xdp_features;
Take a round-robin, active-backup, XOR or 802.3ad bond with no XDP
program, where all current slaves advertise NDO_XMIT and another device
redirects XDP frames into the bond. Enslaving a device with a NULL
ndo_xdp_xmit skips this check.
The new slave then becomes visible before bond_xdp_set_features() clears
NDO_XMIT on the bond:
- the default case of the mode switch in bond_enslave() does
rcu_assign_pointer(bond->curr_active_slave, new_slave)
- bond_master_upper_dev_link() puts the slave on the lower list that
bond_get_slave_by_id() walks
- slave_cnt++ and bond_update_slave_arr() also run before
bond_xdp_set_features()
A redirect on another CPU runs under RCU only, without RTNL. It could pick
the new slave, for example through the IGMP path of
bond_xdp_xmit_roundrobin_slave_get():
if (iph->protocol == IPPROTO_IGMP) {
slave = rcu_dereference(bond->curr_active_slave);
if (slave)
return slave;
bond_xdp_xmit() then makes the call without a NULL check:
err = slave_dev->netdev_ops->ndo_xdp_xmit(slave_dev, 1, frames1, flags);
Can this call a NULL ndo_xdp_xmit in softirq context?
There seems to be a second window as well. __xdp_enqueue() checks
xdp_features when a frame is queued, but the bulk queue is flushed later
without a recheck:
kernel/bpf/devmap.c:bq_xmit_all() {
...
sent = dev->netdev_ops->ndo_xdp_xmit(dev, to_send, bq->q, flags);
...
}
No RCU grace period follows xdp_set_features_flag() either.
The later patches in the series don't close this. At the end of the
series:
- the check is still gated on bond->xdp_prog, now in
bond_enslave_validate()
- bond_xdp_xmit() is unchanged
- bond_xdp_set_features() now runs before bond_publish_slave(), but
still after the curr_active_slave assignment and the lower-list link
One option is to guard the call in bond_xdp_xmit(), or to select only
slaves that advertise NDO_XMIT. Another is to clear the bond's NDO_XMIT
and wait for in-flight readers before any slave without XDP support
becomes visible, whether or not bond->xdp_prog is set. Would one of these
be a better fit?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-bond_enslave_restruct-v1-0-364c549e78db%40kylinos.cn
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net-next 2/6] bonding: finish XDP setup before publishing the slave
2026-11-13 14:04 ` [PATCH net-next 2/6] bonding: finish XDP setup before publishing the slave Hangbin Liu
@ 2026-11-17 14:40 ` netdev-bot+sashiko
0 siblings, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 14:40 UTC (permalink / raw)
To: hangbin.liu
Cc: jv, andrew+netdev, davem, edumazet, kuba, pabeni, ast, daniel,
hawk, john.fastabend, sdf, netdev, linux-kernel, bpf
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 1 · High: 0 · Medium: 0 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Critical] Heap out-of-bounds write in bond_update_slave_arr(),
introduced by moving the XDP setup ahead of the slave_cnt increment.
- [Low] The commit fixes real, user-visible leaks on the bond_enslave()
XDP-failure path but has no Fixes: tag.
- [Low] The commit message describes a stale version of the error path.
--
bonding: finish XDP setup before publishing the slave
This patch moves dev_xdp_propagate() in bond_enslave() ahead of the
slave_cnt increment, the ns maddr setup and active slave selection, so the
XDP setup becomes the last fallible step. It also moves
bond_xdp_set_features() earlier. It replaces err_dec_slave_cnt with a new
err_set_xdp label that undoes the promiscuity, allmulti and address sync.
> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> index 340af4c3fa201..80b6c18ee9c28 100644
> --- a/drivers/net/bonding/bond_main.c
> +++ b/drivers/net/bonding/bond_main.c
> @@ -2313,22 +2313,11 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
> }
> }
>
> - WRITE_ONCE(bond->slave_cnt, bond->slave_cnt + 1);
> - netdev_compute_master_upper_features(bond->dev, true);
> - bond_set_carrier(bond);
> -
[ ... ]
> - /* XDP capability and prog-count were already validated above */
> if (bond->xdp_prog) {
> struct netdev_bpf xdp = {
> .command = XDP_SETUP_PROG,
> @@ -2341,19 +2330,35 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
> if (res < 0) {
> /* ndo_bpf() sets extack error message */
> slave_dbg(bond_dev, slave_dev, "Error %d calling ndo_bpf\n", res);
> - goto err_dec_slave_cnt;
> + goto err_set_xdp;
> }
> if (bond->xdp_prog)
> bpf_prog_inc(bond->xdp_prog);
> }
>
> + bond_xdp_set_features(bond_dev);
> +
> + /* Must called before bond_update_slave_arr() or bond_select_active_slave() */
> + WRITE_ONCE(bond->slave_cnt, bond->slave_cnt + 1);
[Severity: Critical]
After this reordering, dev_xdp_propagate() runs the slave driver's ndo_bpf
when the new slave is already on the bond's lower list
(bond_master_upper_dev_link() ran earlier) but slave_cnt has not been
incremented yet. If a notifier fires from inside ndo_bpf, can it rebuild
the slave arrays using the old slave_cnt?
For example, dpaa2_eth_setup_xdp() closes and reopens a running device:
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c:dpaa2_eth_setup_xdp() {
...
up = netif_running(dev);
...
if (up)
dev_close(dev);
...
if (up) {
err = dev_open(dev, NULL);
...
}
Take balance-xor or 802.3ad mode (802.3ad once there is an active
aggregator) with an XDP program attached to the bond. The call chain
looks like this:
bond_enslave()
dev_xdp_propagate()
dpaa2_eth_xdp()
dpaa2_eth_setup_xdp()
dev_close() /* NETDEV_DOWN */
bond_netdev_event()
bond_slave_netdev_event()
bond_update_slave_arr(bond, NULL)
bond_update_slave_arr() sizes the arrays from slave_cnt (N). It then walks
all N+1 slaves on the list with no bound:
usable_slaves = kzalloc_flex(*usable_slaves, arr, bond->slave_cnt);
all_slaves = kzalloc_flex(*all_slaves, arr, bond->slave_cnt);
...
bond_for_each_slave(bond, slave, iter) {
...
all_slaves->arr[all_slaves->count++] = slave;
Does this write one struct slave pointer past the end of all_slaves->arr[]
and usable_slaves->arr[]? The arrays are then published with a count
larger than their allocation, so the xmit hash path could read past them
too. dev_open() then raises NETDEV_UP, which would do the same thing again.
For the second slave, struct_size() comes to 32 bytes, which fills a
kmalloc-32 object exactly. The write to arr[1] would then hit the
neighbouring object.
The same applies to any other slave driver whose ndo_bpf synchronously
raises NETDEV_UP, NETDEV_DOWN or NETDEV_CHANGE.
Before this patch, slave_cnt was incremented before dev_xdp_propagate(),
so these rebuilds saw the right count. The new comment above says slave_cnt
must be updated before bond_update_slave_arr(), but calls that come in
through notifiers from ndo_bpf now break that rule.
This still seems to be there at the end of the series.
bond_publish_slave(), added in "bonding: factor out slave publication",
still runs after the XDP setup.
> + netdev_compute_master_upper_features(bond->dev, true);
> + bond_set_carrier(bond);
[ ... ]
> @@ -2363,8 +2368,15 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
> return 0;
>
> /* Undo stages on error */
> -err_dec_slave_cnt:
> - WRITE_ONCE(bond->slave_cnt, bond->slave_cnt - 1);
[Severity: Low]
The commit message says:
If XDP setup then fails, the error path
jumps to err_sysfs_del and leaks:
and:
follows the publication of the slave and a failure can no longer
leak slave_cnt or ns maddrs.
Does this match the parent commit? There, a dev_xdp_propagate() failure
already does goto err_dec_slave_cnt, which decrements slave_cnt. That
label came from a978095699641d ("bonding: fix slave_cnt leak on XDP
enslave failure").
In this hunk the patch actually removes err_dec_slave_cnt, which the
reorder makes unnecessary. Could the commit message say so and reference
a978095699641d?
Separately, there's a typo in the new comment:
/* Must called before bond_update_slave_arr() or bond_select_active_slave() */
"Must called" should be "Must be called". The typo is carried into
bond_publish_slave() by "bonding: factor out slave publication".
> +err_set_xdp:
> + if (!bond_uses_primary(bond)) {
> + if (bond_dev->flags & IFF_PROMISC)
> + dev_set_promiscuity(slave_dev, -1);
> + if (bond_dev->flags & IFF_ALLMULTI)
> + dev_set_allmulti(slave_dev, -1);
> + if (bond_dev->flags & IFF_UP)
> + bond_hw_addr_flush(bond_dev, slave_dev);
> + }
[Severity: Low]
This block fixes leaks that users can actually hit, but the commit has no
Fixes: tag.
In non-primary modes, the parent code jumped from a dev_xdp_propagate()
failure to err_sysfs_del without undoing any of these:
- the promiscuity/allmulti increments
- the addresses added by dev_mc_sync_multiple()/dev_uc_sync_multiple()
and the LACPDU dev_mc_add()
- the ns target maddrs added by bond_slave_ns_maddrs_add()
The XDP setup placement comes from 9e2ee5c7e7c3 ("net, bonding: Add XDP
support to the bonding driver"). That is also the Fixes: target of
a978095699641d. Placing the ns maddrs before the XDP setup comes from
8eb36164d1a6 ("bonding: add ns target multicast address to slave
device").
This failure can really happen. For example, dpaa2_eth_setup_xdp() returns
-EINVAL when the MTU is not valid for XDP:
if (prog && !xdp_mtu_valid(priv, dev->mtu))
return -EINVAL;
Should this carry Fixes: 9e2ee5c7e7c3 and/or Fixes: 8eb36164d1a6?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-bond_enslave_restruct-v1-0-364c549e78db%40kylinos.cn
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net-next 3/6] bonding: complete rollback of bond_enslave() error paths
2026-11-13 14:04 ` [PATCH net-next 3/6] bonding: complete rollback of bond_enslave() error paths Hangbin Liu
@ 2026-11-17 14:40 ` netdev-bot+sashiko
0 siblings, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 14:40 UTC (permalink / raw)
To: hangbin.liu
Cc: jv, andrew+netdev, davem, edumazet, kuba, pabeni, ast, daniel,
hawk, john.fastabend, sdf, netdev, linux-kernel, bpf
Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.
Critical: 0 · High: 2 · Medium: 2 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The bond_enslave() unwind (err_set_xdp → err_sysfs_del →
err_upper_unlink → err_unregister → err_detach) clears…
- [High] The new bond_alb_deinit_slave() call sits at err_close (line
2411).
- [Medium] bond_3ad_unbind_slave() discards the 'slave array needs
update' result of ad_agg_selection_logic().
- [Medium] The commit message says all three added cleanups are ones
"that the release path (__bond_release_one) already performs".
- [Low] The commit describes its changes as cleanups that are "missing"
and state "left behind", and it has no Fixes: tag or stable Cc.
- [Low] The commit author address (Hangbin Liu <hangbin.liu@linux.dev>)
does not match the Signed-off-by address (Hangbin Liu…
--
bonding: complete rollback of bond_enslave() error paths
This patch adds three steps to the bond_enslave() error unwind:
bond_alb_deinit_slave() for TLB/ALB, bond_3ad_unbind_slave() for 802.3ad,
and restoring bond->params.fail_over_mac after it was automatically set to
"active". The goal is to match what __bond_release_one() does on release.
> The bond_enslave() undo labels are missing three cleanups that the
> release path (__bond_release_one) already performs:
>
> - If bond_alb_init_slave() succeeds but a later step fails, the
> slave is never passed to bond_alb_deinit_slave(), leaving TLB/RLB
> state and a possibly borrowed MAC address behind.
[ ... ]
> - When fail_over_mac is automatically set to "active" because the
> first slave cannot change its MAC address, a subsequent failure
> leaves the modified parameter on the bond.
[Severity: Medium]
Is it accurate that all three cleanups are ones the release path already
performs? __bond_release_one() never writes bond->params.fail_over_mac.
The only writers are the automatic setting in bond_enslave(), the restore
added here, and the module parameter init. So the restore looks like new
behaviour rather than parity with release.
The "possibly borrowed MAC address" part also looks off. In TLB/ALB mode
BOND_MODE() is not BOND_MODE_ACTIVEBACKUP, so err_restore_mac already puts
perm_hwaddr back on the slave:
err_restore_mac:
slave_dev->priv_flags &= ~IFF_NO_ADDRCONF;
if (!bond->params.fail_over_mac ||
BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
...
bond_hw_addr_copy(ss.__data, new_slave->perm_hwaddr,
new_slave->dev->addr_len);
ss.ss_family = slave_dev->type;
dev_set_mac_address(slave_dev, &ss, NULL);
}
The message does not mention what the new bond_alb_deinit_slave() call
does change. If the bond already has slaves, it calls
alb_change_hw_addr_on_detach():
drivers/net/bonding/bond_alb.c:alb_change_hw_addr_on_detach() {
...
if (perm_curr_diff && perm_bond_diff) {
found_slave = bond_slave_has_mac(bond, slave->perm_hwaddr);
if (found_slave) {
alb_swap_mac_addr(slave, found_slave);
alb_fasten_mac_swap(bond, slave, found_slave);
}
}
}
Can a failed enslave now change the MAC address of an existing slave that
is still enslaved, and send learning packets? Here is how that could
happen in TLB/ALB mode:
- The new slave's MAC matches an existing slave's current MAC, so
alb_handle_addr_collision_on_attach() gives it a free address.
- vlan_vids_add_by_dev() or bond_sysfs_slave_add() then fails.
Could the commit message be updated to describe what these changes
actually do?
> Add undo steps for these 3 cleanups when error out.
>
> Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
[Severity: Low]
Should this carry Fixes: tags? The message calls these missing cleanups
and leftover state. At least two of them are dangling pointers to a
struct slave that err_free has already freed through
kobject_put()->slave_kobj_release()->kfree().
In 802.3ad mode, bond_3ad_state_machine_handler() runs under RCU and
mode_lock without RTNL. After bond_master_upper_dev_link() it can link the
new port into an aggregator's lag_ports chain.
In TLB/ALB mode, tlb_get_least_loaded_slave() can cache the new slave in
tx_hashtbl[].tx_slave, and the RLB code can cache it in rx_hashtbl and
rx_slave.
Without Fixes: tags and a mention of the use-after-free, stable tooling
may never pick these fixes up.
[Severity: Low]
This isn't a bug, but the Signed-off-by address (liuhangbin@kylinos.cn)
does not match the author address (hangbin.liu@linux.dev). checkpatch
reports this as FROM_SIGN_OFF_MISMATCH. The other patches in the series
have the same mismatch.
> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> index 80b6c18ee9c28..f696a0d150346 100644
> --- a/drivers/net/bonding/bond_main.c
> +++ b/drivers/net/bonding/bond_main.c
[ ... ]
> @@ -2388,6 +2391,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
> netdev_rx_handler_unregister(slave_dev);
>
> err_detach:
> + if (BOND_MODE(bond) == BOND_MODE_8023AD)
> + bond_3ad_unbind_slave(new_slave);
[Severity: Medium]
Does this need a bond_update_slave_arr() call afterwards?
bond_3ad_unbind_slave() ignores the update result from
ad_agg_selection_logic() and leaves the array rebuild to its caller:
drivers/net/bonding/bond_3ad.c:bond_3ad_unbind_slave() {
...
bool dummy_slave_update; /* Ignore this value as caller updates array */
...
}
__bond_release_one() rebuilds the array right after the unbind:
if (BOND_MODE(bond) == BOND_MODE_8023AD)
bond_3ad_unbind_slave(slave);
bond_upper_dev_unlink(bond, slave);
if (bond_mode_can_use_xmit_hash(bond) ||
BOND_MODE(bond) == BOND_MODE_BROADCAST)
bond_update_slave_arr(bond, slave);
The bond_enslave() unwind never calls bond_update_slave_arr(). Suppose
unbinding the half-enslaved port makes ad_agg_selection_logic() choose a
new active aggregator. Could the usable_slaves and all_slaves arrays then
stay stale until some unrelated event rebuilds them?
bond_slave_arr_work_rearm() from the state machine may cover some of
these cases, but it is not clear that it covers all of them.
The ordering also differs from release. Here the unbind runs after
err_upper_unlink, so the bond_for_each_slave() loops inside
bond_3ad_unbind_slave() no longer see the departing slave's own
aggregator. Is that intended?
> vlan_vids_del_by_dev(slave_dev, bond_dev);
> if (rcu_access_pointer(bond->primary_slave) == new_slave)
> RCU_INIT_POINTER(bond->primary_slave, NULL);
[Severity: High]
Since this patch completes the rollback against __bond_release_one(),
should bond->current_arp_slave also be cleared here? The release path
clears it unconditionally:
RCU_INIT_POINTER(bond->current_arp_slave, NULL);
The unwind only clears primary_slave and curr_active_slave before
synchronize_rcu().
In active-backup mode with arp_interval set, bond_ab_arp_probe() runs from
arp_work with only rcu_read_lock() held. Once bond_master_upper_dev_link()
has linked new_slave, the probe can publish it while bond_enslave() still
holds RTNL:
bond_activebackup_arp_mon()
bond_ab_arp_probe()
curr_arp_slave = bond_first_slave_rcu(bond);
...
rcu_assign_pointer(bond->current_arp_slave, new_slave);
For the first slave there is no curr_active_slave yet, because
bond_select_active_slave() only runs from bond_publish_slave().
If dev_xdp_propagate() or bond_sysfs_slave_add() then fails, err_free
calls kobject_put(&new_slave->kobj) and the slave is freed. But
bond->current_arp_slave still points at it, and later users dereference
it:
bond_ab_arp_commit():
current_arp_slave = rtnl_dereference(bond->current_arp_slave);
...
bond_set_slave_inactive_flags(
current_arp_slave,
BOND_SLAVE_NOTIFY_NOW);
bond_arp_rcv():
else if (curr_arp_slave && (arp->ar_op == htons(ARPOP_REPLY)) &&
bond_time_in_interval(bond, slave_last_tx(curr_arp_slave), 1))
Can this cause a use-after-free of the freed struct slave? A received ARP
reply is enough to reach the bond_arp_rcv() read, and bond_na_rcv() and
the netdev_info() print of curr_arp_slave->dev->name in
bond_ab_arp_probe() follow the same pattern.
[ ... ]
> @@ -2402,6 +2407,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
> slave_disable_netpoll(new_slave);
>
> err_close:
> + if (alb_initialized)
> + bond_alb_deinit_slave(bond, new_slave);
[Severity: High]
Does this call come after the grace period it depends on? The only
synchronize_rcu() in the unwind is in err_detach, above this label. After
bond_alb_deinit_slave() clears tx_hashtbl and rx_hashtbl, nothing waits
for readers before err_free calls kobject_put(&new_slave->kobj) and frees
the slave.
In TLB/ALB mode the new slave can transmit once
bond_master_upper_dev_link() has linked it, so
tlb_get_least_loaded_slave() can cache it in tx_hashtbl[].tx_slave.
Suppose bond_sysfs_slave_add() fails. A transmit can start after
synchronize_rcu() returns but before tlb_clear_slave() takes mode_lock.
It picks up the cached pointer and keeps using it after dropping the
lock:
bond_tlb_xmit() / bond_alb_xmit()
bond_xmit_tlb_slave_get() / bond_xmit_alb_slave_get()
tlb_choose_channel()
spin_lock(&bond->mode_lock);
tx_slave = __tlb_choose_channel(bond, hash_index, skb_len);
spin_unlock(&bond->mode_lock);
bond_do_alb_xmit()
if (tx_slave && bond_slave_can_tx(tx_slave)) {
...
if (tx_slave && bond->params.tlb_dynamic_lb) {
spin_lock(&bond->mode_lock);
__tlb_clear_slave(bond, tx_slave, 0);
tlb_clear_slave() only takes mode_lock, so it cannot wait for a reader
that has already dropped the lock. dev_close(slave_dev) does not guarantee
a grace period either. dev_deactivate_many() only calls synchronize_net()
when sync_needed is set, and it is not set for noqueue slaves.
__bond_release_one() calls bond_alb_deinit_slave() before its
synchronize_rcu(). Should this call move into err_detach, ahead of the
synchronize_rcu() there, so new_slave cannot be used after it is freed?
> if (!netif_is_bond_master(slave_dev))
> slave_dev->priv_flags &= ~IFF_BONDING;
> dev_close(slave_dev);
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-bond_enslave_restruct-v1-0-364c549e78db%40kylinos.cn
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net-next 4/6] bonding: factor out slave publication
2026-11-13 14:04 ` [PATCH net-next 4/6] bonding: factor out slave publication Hangbin Liu
@ 2026-11-17 14:40 ` netdev-bot+sashiko
0 siblings, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 14:40 UTC (permalink / raw)
To: hangbin.liu
Cc: jv, andrew+netdev, davem, edumazet, kuba, pabeni, ast, daniel,
hawk, john.fastabend, sdf, netdev, linux-kernel, bpf
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The new comment on bond_publish_slave() in
drivers/net/bonding/bond_main.c says the helper will "Make the fully…
- [Low] The commit message calls bond_publish_slave() the "infallible
'commit point'", and the new comment says "All fallible steps of…
- [Low] The commit author is 'Hangbin Liu <hangbin.liu@linux.dev>', but
the only Signed-off-by is 'Hangbin Liu <liuhangbin@kylinos.cn>'.
--
bonding: factor out slave publication
This commit moves the final block of bond_enslave() into a new helper,
bond_publish_slave(). That block bumps slave_cnt, recomputes upper
features and carrier, adds NS maddrs, selects the active slave and
rebuilds the xmit slave arrays. The commit message calls this the
infallible commit point of the function and says there is no functional
change.
> Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
[Severity: Low]
This isn't a bug, but the Author address (hangbin.liu@linux.dev) does not
match the only Signed-off-by (liuhangbin@kylinos.cn). checkpatch reports
this as "From:/Signed-off-by: email address mismatch".
The same mismatch shows up on all six patches in the series, from
"bonding: check XDP support before enslaving changes state" through
"bonding: factor out bond_enslave_validate".
Could the addresses be made to match, or a From: line or Signed-off-by
be added for the author address?
> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> index f696a0d150346..bb37526834562 100644
> --- a/drivers/net/bonding/bond_main.c
> +++ b/drivers/net/bonding/bond_main.c
> @@ -1884,6 +1884,34 @@ void bond_xdp_set_features(struct net_device *bond_dev)
> xdp_set_features_flag(bond_dev, val);
> }
>
> +/* Make the fully prepared slave visible to the rest of the bonding
> + * code. All fallible steps of bond_enslave() must have completed
> + * before this runs: error paths never undo the publication.
> + */
[Severity: Low]
Is "visible to the rest of the bonding code" accurate here? By the time
bond_publish_slave() runs, bond_enslave() has already made the slave
reachable:
res = netdev_rx_handler_register(slave_dev, bond_handle_frame,
new_slave);
...
res = bond_master_upper_dev_link(bond, new_slave, extack);
...
res = bond_sysfs_slave_add(new_slave);
bond_for_each_slave() is netdev_for_each_lower_private(). So once
bond_master_upper_dev_link() returns, every bond_for_each_slave() walker
sees the new slave. bond_xdp_set_features(), called just before this
helper, already iterates over it.
In the default (trunk) mode, the switch in bond_enslave() also publishes
the slave as curr_active_slave. That happens before several steps that
can still fail (netpoll, rx_handler, upper link, sysfs, promisc/allmulti,
XDP):
if (!rcu_access_pointer(bond->curr_active_slave) &&
new_slave->link == BOND_LINK_UP)
rcu_assign_pointer(bond->curr_active_slave, new_slave);
The err_detach path then undoes that:
if (rcu_access_pointer(bond->curr_active_slave) == new_slave) {
block_netpoll_tx();
bond_change_active_slave(bond, NULL);
bond_select_active_slave(bond);
unblock_netpoll_tx();
}
So "error paths never undo the publication" does not seem to hold either.
The helper actually commits slave_cnt and rebuilds derived state: upper
features, carrier, NS maddrs, active slave selection and the xmit slave
arrays. Between bond_master_upper_dev_link() and bond_publish_slave(),
list walkers see N+1 slaves while slave_cnt is still N.
Could the comment say that instead? Otherwise a later change might assume
the slave cannot be reached before this point.
> +static void bond_publish_slave(struct bonding *bond, struct slave *slave)
> +{
[ ... ]
> + /* broadcast mode uses the all_slaves to loop through slaves. */
> + if (bond_mode_can_use_xmit_hash(bond) ||
> + BOND_MODE(bond) == BOND_MODE_BROADCAST)
> + bond_update_slave_arr(bond, NULL);
> +}
[Severity: Low]
The commit message calls this the infallible "commit point", and the
comment above says all fallible steps must be done before this runs. Can
bond_update_slave_arr() still fail here?
drivers/net/bonding/bond_main.c:bond_update_slave_arr() {
...
usable_slaves = kzalloc_flex(*usable_slaves, arr, bond->slave_cnt);
all_slaves = kzalloc_flex(*all_slaves, arr, bond->slave_cnt);
if (!usable_slaves || !all_slaves) {
ret = -ENOMEM;
goto out;
}
...
}
On that path bond_set_slave_arr() is never called. Since skipslave is
NULL, nothing else makes up for it.
bond_publish_slave() returns void, so the error is dropped and the
slave_arr work is not re-armed. bond_slave_arr_handler() does re-arm it
when the same call fails:
ret = bond_update_slave_arr(bond, NULL);
rtnl_unlock();
if (ret) {
pr_warn_ratelimited("Failed to update slave array from WT\n");
goto err;
}
return;
err:
bond_slave_arr_work_rearm(bond, 1);
If the allocation fails, bond_enslave() still returns 0 and slave_cnt
has already been incremented. all_slaves and usable_slaves still hold
the old slave set. bond_xmit_broadcast() skips the new slave, and
XOR/3ad/TLB hashing never picks it, until some unrelated event rebuilds
the arrays.
The unchecked call was already inline in bond_enslave() before this
patch. What is new is the void helper and the comment that call it
infallible.
Should the comment and commit message be corrected? Or should the helper
call bond_slave_arr_work_rearm(bond, 1) when bond_update_slave_arr()
fails?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-bond_enslave_restruct-v1-0-364c549e78db%40kylinos.cn
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net-next 6/6] bonding: factor out bond_enslave_validate
2026-11-13 14:04 ` [PATCH net-next 6/6] bonding: factor out bond_enslave_validate Hangbin Liu
@ 2026-11-17 14:40 ` netdev-bot+sashiko
0 siblings, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 14:40 UTC (permalink / raw)
To: hangbin.liu
Cc: jv, andrew+netdev, davem, edumazet, kuba, pabeni, ast, daniel,
hawk, john.fastabend, sdf, netdev, linux-kernel, bpf
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message says the new bond_enslave_validate() helper
(drivers/net/bonding/bond_main.c) does "all read-only checks".
--
bonding: factor out bond_enslave_validate
This commit moves the fail-fast checks at the top of bond_enslave() into
a new static helper, bond_enslave_validate(), in
drivers/net/bonding/bond_main.c. Behavior does not change. The moved
block runs from the ARPHRD_CAN check through the bond_slave_xdp_check()
call.
> bond_enslave() is a long linear function whose flow is hard to see
> behind the inline blocks. Factor out bond_enslave_validate to do
> all read-only checks.
[Severity: Low]
Is "all read-only checks" accurate here? The patch moves only the checks
that already ran before the first mutation. Several other checks that
only read state are still inline in bond_enslave().
Two of them run before any mutation:
drivers/net/bonding/bond_main.c:bond_enslave() {
...
if (!bond_has_slaves(bond)) {
if (bond_dev->type != slave_dev->type) {
if (slave_dev->type != ARPHRD_ETHER &&
BOND_MODE(bond) == BOND_MODE_8023AD) {
SLAVE_NL_ERR(bond_dev, slave_dev, extack,
"8023AD mode requires Ethernet devices");
return -EINVAL;
}
...
} else if (bond_dev->type != slave_dev->type) {
SLAVE_NL_ERR(bond_dev, slave_dev, extack,
"Device type is different from other slaves");
return -EINVAL;
}
...
}
The infiniband mode check only reads slave_dev->type and BOND_MODE(bond).
It runs after the first-slave type change block, though, and exits
through err_undo_flags:
if (slave_dev->type == ARPHRD_INFINIBAND &&
BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
SLAVE_NL_ERR(bond_dev, slave_dev, extack,
"Only active-backup mode is supported for infiniband slaves");
res = -EOPNOTSUPP;
goto err_undo_flags;
}
For a first slave, the bond has already gone through
NETDEV_PRE/POST_TYPE_CHANGE, dev_uc_flush()/dev_mc_flush() and
bond_setup_by_slave() at that point. err_undo_flags then calls
dev_close(bond_dev) and bond_ether_setup(bond_dev). This behaves the same
before and after the patch.
The fail_over_mac check after it also only reads state.
The helper's own code comment, and the "Failures return directly, no
undo needed at that point" sentence, are accurate for what the helper
contains.
Could the commit message say that the helper holds the checks that run
before the first mutation, rather than all read-only checks?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-bond_enslave_restruct-v1-0-364c549e78db%40kylinos.cn
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2026-11-17 14:40 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 14:04 [PATCH net-next 0/6] bonding: refactor bond_enslave() to fix XDP ordering and error rollback Hangbin Liu
2026-11-13 14:04 ` [PATCH net-next 1/6] bonding: check XDP support before enslaving changes state Hangbin Liu
2026-11-17 14:40 ` netdev-bot+sashiko
2026-11-13 14:04 ` [PATCH net-next 2/6] bonding: finish XDP setup before publishing the slave Hangbin Liu
2026-11-17 14:40 ` netdev-bot+sashiko
2026-11-13 14:04 ` [PATCH net-next 3/6] bonding: complete rollback of bond_enslave() error paths Hangbin Liu
2026-11-17 14:40 ` netdev-bot+sashiko
2026-11-13 14:04 ` [PATCH net-next 4/6] bonding: factor out slave publication Hangbin Liu
2026-11-17 14:40 ` netdev-bot+sashiko
2026-11-13 14:04 ` [PATCH net-next 5/6] bonding: factor out XDP slave check Hangbin Liu
2026-11-13 14:04 ` [PATCH net-next 6/6] bonding: factor out bond_enslave_validate Hangbin Liu
2026-11-17 14:40 ` netdev-bot+sashiko
2026-11-13 14:11 ` [PATCH net-next 0/6] bonding: refactor bond_enslave() to fix XDP ordering and error rollback netdev-bot+sinfo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox