mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next] bonding: undo enslave state when XDP setup fails
@ 2026-11-25 13:59 Hangbin Liu
  2026-11-25 14:03 ` netdev-bot+sinfo
  2026-11-29 13:01 ` netdev-bot+sashiko
  0 siblings, 2 replies; 3+ messages in thread
From: Hangbin Liu @ 2026-11-25 13:59 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>

If one of the XDP checks in bond_enslave() or dev_xdp_propagate()
fails, the error path jumps to err_dec_slave_cnt. By then the
function has already incremented the bond's promiscuity/allmulti on
the slave and synced the bond's addresses to it, and has added the
slave ns maddrs via bond_slave_ns_maddrs_add(). None of the existing
error paths undo those, so a failed enslave leaves the slave with
stale promisc/allmulti counts, synced addresses and ns maddrs.

Add the missing undo steps at err_dec_slave_cnt: remove the ns
maddrs, decrement slave_cnt, and - only for modes that do not use a
primary slave, mirroring the code that applied them - drop the
promiscuity/allmulti increments and flush the synced addresses from
the slave.

Remove the ns maddrs a second time at err_close. If the new slave
was selected active before the failure, err_detach demotes it via
bond_change_active_slave(NULL) and bond_hw_addr_swap() re-adds them
after the first removal, leaving the addresses on the slave as it
leaves the bond. This second call runs after that re-add; on every
other path it is a harmless no-op, since deleting an address that is
not on the mc list does nothing.

Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
For Sashiko: please ignore the possible ndo_xdp_xmit null pointer issue in
bond_xdp_xmit(). It will be fixed in another patch.
---
 drivers/net/bonding/bond_main.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 776afdb9df43..a3daf005b444 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -2364,7 +2364,16 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
 
 /* Undo stages on error */
 err_dec_slave_cnt:
+	bond_slave_ns_maddrs_del(bond, new_slave);
 	WRITE_ONCE(bond->slave_cnt, bond->slave_cnt - 1);
+	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);
@@ -2390,6 +2399,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
 	slave_disable_netpoll(new_slave);
 
 err_close:
+	bond_slave_ns_maddrs_del(bond, new_slave);
 	if (!netif_is_bond_master(slave_dev))
 		slave_dev->priv_flags &= ~IFF_BONDING;
 	dev_close(slave_dev);

---
base-commit: a4c450594f5d1dc0fc4daacfb95d40554d99dead
change-id: 20261124-bond_xdp_rollback-187c07d3125d

Best regards,
--  
Hangbin Liu <liuhangbin@kylinos.cn>


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

* Re: [PATCH net-next] bonding: undo enslave state when XDP setup fails
  2026-11-25 13:59 [PATCH net-next] bonding: undo enslave state when XDP setup fails Hangbin Liu
@ 2026-11-25 14:03 ` netdev-bot+sinfo
  2026-11-29 13:01 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-11-25 14:03 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:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - 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.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
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] 3+ messages in thread

* Re: [PATCH net-next] bonding: undo enslave state when XDP setup fails
  2026-11-25 13:59 [PATCH net-next] bonding: undo enslave state when XDP setup fails Hangbin Liu
  2026-11-25 14:03 ` netdev-bot+sinfo
@ 2026-11-29 13:01 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-11-29 13:01 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 (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 second bond_slave_ns_maddrs_del() that the patch adds at
  err_close in bond_enslave() (drivers/net/bonding/bond_main.c:2402)…
- [Low] The patch fixes leaks visible to users after a failed
  bond_enslave(): stale promiscuity/allmulti counts and synced uc/mc…
- [Low] The commit author is 'Hangbin Liu <hangbin.liu@linux.dev>', but
  the only Signed-off-by is 'Hangbin Liu <liuhangbin@kylinos.cn>'.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the
  bond_enslave() error labels the patch extends still do not undo…

--

bonding: undo enslave state when XDP setup fails

This patch adds undo steps at err_dec_slave_cnt in bond_enslave() for
the ns maddrs, promiscuity, allmulti and synced addresses when one of
the XDP checks fails. It also adds a second bond_slave_ns_maddrs_del()
at err_close, meant for the case where the new slave was selected active
and is then demoted on the error path.

> Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>

[Severity: Low]
This isn't a bug, but the author address is hangbin.liu@linux.dev and
the only Signed-off-by uses liuhangbin@kylinos.cn. checkpatch reports a
From:/Signed-off-by: email address mismatch. Could the two addresses be
made to match?

[Severity: Low]
Should this have Fixes: tags?

The promisc/allmulti/address leak on the XDP failure paths appears to
come from 9e2ee5c7e7c3 ("net, bonding: Add XDP support to the bonding
driver"). The ns maddr leak appears to come from 8eb36164d1a6
("bonding: add ns target multicast address to slave device").

The earlier related fix a978095699641d ("bonding: fix slave_cnt leak on
XDP enslave failure") carries Fixes: 9e2ee5c7e7c3.

> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> index 776afdb9df43e..a3daf005b444d 100644
> --- a/drivers/net/bonding/bond_main.c
> +++ b/drivers/net/bonding/bond_main.c
> @@ -2364,7 +2364,16 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
>  
>  /* Undo stages on error */
>  err_dec_slave_cnt:
> +	bond_slave_ns_maddrs_del(bond, new_slave);
>  	WRITE_ONCE(bond->slave_cnt, bond->slave_cnt - 1);
> +	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: High]
This is a pre-existing issue and this patch did not introduce it. The
error labels being extended here still skip several steps that
__bond_release_one() performs.

In 802.3ad mode, bond_enslave() calls bond_3ad_bind_slave(new_slave).
No error label calls bond_3ad_unbind_slave(). Only __bond_release_one()
does:

drivers/net/bonding/bond_main.c:__bond_release_one() {
    ...
	if (BOND_MODE(bond) == BOND_MODE_8023AD)
		bond_3ad_unbind_slave(slave);
    ...
}

bond_3ad_state_machine_handler() runs from ad_work under mode_lock and
rcu_read_lock, not RTNL. That means it can run after the slave is linked
and before the XDP or sysfs failure.

The newly bound port is not AD_PORT_SELECTED, so ad_port_selection_logic()
picks it up. With no matching LAG it takes the first free aggregator,
which can belong to another existing slave:

drivers/net/bonding/bond_3ad.c:ad_port_selection_logic() {
    ...
			free_aggregator->lag_ports = port;
			free_aggregator->num_of_ports++;

			rcu_assign_pointer(port->aggregator, free_aggregator);
    ...
}

The error path then unlinks the slave, and bond_free_slave() calls
kfree(SLAVE_AD_INFO(slave)).

Can the other slave's aggregator->lag_ports then point to freed memory?
Later ticks would read it through __agg_active_ports() and
ad_agg_selection_logic(), and write through __set_agg_ports_ready().

__bond_xdp_check() allows 802.3ad with XDP, so the XDP failure labels
can reach this. The bond_sysfs_slave_add() failure path can reach it
too.

Separately, netdev_compute_master_upper_features() and bond_set_carrier()
ran with the failing slave counted:

	WRITE_ONCE(bond->slave_cnt, bond->slave_cnt + 1);
	netdev_compute_master_upper_features(bond->dev, true);
	bond_set_carrier(bond);

They do not run again after slave_cnt is decremented and the slave is
unlinked.

Could the bond keep carrier on, or keep stale features, with zero
slaves? One example is the first slave of a bond that already has an XDP
program and that fails the XDP checks.

Also, in TLB/ALB modes, the sysfs failure path never undoes
bond_alb_init_slave() with bond_alb_deinit_slave().

>  
>  err_sysfs_del:
>  	bond_sysfs_slave_del(new_slave);
> @@ -2390,6 +2399,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
>  	slave_disable_netpoll(new_slave);
>  
>  err_close:
> +	bond_slave_ns_maddrs_del(bond, new_slave);

[Severity: High]
Is there a matching add for this second bond_slave_ns_maddrs_del() on any
path?

The commit message says:

  If the new slave was selected active before the failure, err_detach
  demotes it via bond_change_active_slave(NULL) and bond_hw_addr_swap()
  re-adds them after the first removal

In bond_change_active_slave(), the swap runs before the old active slave
is flagged inactive:

drivers/net/bonding/bond_main.c:bond_change_active_slave() {
    ...
	if (bond_uses_primary(bond))
		bond_hw_addr_swap(bond, new_active, old_active);
    ...
	if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP) {
		if (old_active)
			bond_set_slave_inactive_flags(old_active,
						      BOND_SLAVE_NOTIFY_NOW);
    ...
}

So when bond_hw_addr_swap() calls bond_slave_ns_maddrs_add(bond,
old_active), the slave is still active and the gate rejects it:

drivers/net/bonding/bond_options.c:slave_can_set_ns_maddr() {
	return BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP &&
	       !bond_is_active_slave(slave) &&
	       slave->dev->flags & IFF_MULTICAST;
}

The re-add therefore does nothing. By the time err_close runs, though,
the slave is flagged backup. This del then passes the gate and calls
dev_mc_del() for every NS target MAC.

In active-backup mode with arp_validate and ns_ip6_target set, each of
these cases seems to end at net -1:

  - The new slave was selected active. The add in bond_enslave() is +1.
    The del of new_active in bond_hw_addr_swap() is -1. The
    err_dec_slave_cnt del is skipped (slave active). The err_detach
    re-add is skipped (still active). The err_close del is -1. This case
    was balanced before the patch.

  - The new slave stayed backup. The add is +1, the err_dec_slave_cnt
    del is -1 and the err_close del is -1.

  - Older failure paths reach err_close after
    bond_set_slave_inactive_flags() in the BOND_MODE_ACTIVEBACKUP case.
    These are the netpoll enable, netdev_rx_handler_register(),
    bond_master_upper_dev_link() and bond_sysfs_slave_add() failures.
    They now run a del even though bond_slave_ns_maddrs_add() never ran.

The commit message also says:

  on every other path it is a harmless no-op, since deleting an address
  that is not on the mc list does nothing.

dev_mc_del() ends up in __hw_addr_del_entry(), which decrements
ha->refcount without checking who owns the reference, and frees the
entry when it reaches zero.

Another owner may hold the solicited-node MAC 33:33:ff:xx:xx:xx on the
slave, for example a packet socket with PACKET_MR_MULTICAST, or a VLAN
or macvlan upper. Can this del drop that owner's reference and remove
the hardware filter? That owner's later delete would then fail with
-ENOENT.

The err_dec_slave_cnt del already undoes the add on the XDP failure
paths. Could the err_close call be dropped?

Related, and not introduced by this patch: because of the same ordering
in bond_change_active_slave(), a slave demoted on an ordinary failover
also becomes a backup without NS maddrs.

>  	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/20261125-bond_xdp_rollback-v1-1-35dddaa337ba%40kylinos.cn

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

end of thread, other threads:[~2026-11-29 13:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 13:59 [PATCH net-next] bonding: undo enslave state when XDP setup fails Hangbin Liu
2026-11-25 14:03 ` netdev-bot+sinfo
2026-11-29 13:01 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®