BPF List
 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-26 14:00 ` sashiko-bot
  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 related	[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-26 14:00 ` sashiko-bot
  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-26 14:00 ` sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-26 14:00 UTC (permalink / raw)
  To: Hangbin Liu; +Cc: bpf

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] bonding: unbalanced bond_slave_ns_maddrs_del() calls in
  bond_enslave()
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] bonding: missing cleanup and 3ad unbind on XDP error in
  bond_enslave() [1]
--

commit 92300beff3942cb3faeff269729a68f96aad2772
Author: Hangbin Liu <hangbin.liu@linux.dev>

bonding: undo enslave state when XDP setup fails

This commit cleans up promiscuity, allmulti, synced hardware addresses, and
NS target multicast addresses on the slave when XDP setup fails in
bond_enslave().

> 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);
> +	}
>  
>  err_sysfs_del:
>  	bond_sysfs_slave_del(new_slave);

[Severity: Critical]
This problem wasn't introduced by this patch, but in BOND_MODE_8023AD,
bond_enslave() has already called bond_3ad_bind_slave(new_slave) and linked
the slave into the lower device list before reaching these error labels
[1].  While new_slave is linked, bond_3ad_state_machine_handler() can
run concurrently and attach its port to an aggregator's lag_ports list.
Does unwinding without calling bond_3ad_unbind_slave() leave the freed port
linked in the aggregator after kobject_put(&new_slave->kobj), causing a
use-after-free on later 802.3ad state machine ticks or bond teardown?

> @@ -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: Medium]
Does calling bond_slave_ns_maddrs_del() at both err_dec_slave_cnt and
err_close cause an unbalanced extra dev_mc_del() on slave_dev in
active-backup mode?

slave_can_set_ns_maddr() gates NS multicast address addition and deletion on
!bond_is_active_slave(slave) (slave->backup == 1), which bond_enslave() sets
via bond_set_slave_inactive_flags() before registering the rx handler:

- If new_slave remained a backup slave when XDP setup fails, new_slave->backup
  is 1 at both err_dec_slave_cnt and err_close, so bond_slave_ns_maddrs_del()
  calls dev_mc_del() twice for one bond_slave_ns_maddrs_add().
- If new_slave became active in bond_select_active_slave(),
  bond_change_active_slave(bond, new_slave) already removed the NS multicast
  addresses in bond_hw_addr_swap() before clearing new_slave->backup.  When
  err_detach then calls bond_change_active_slave(bond, NULL),
  bond_hw_addr_swap(bond, NULL, new_slave) runs while new_slave->backup is
  still 0, before bond_set_slave_inactive_flags() sets new_slave->backup = 1:

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);
	...
}

  As a result, bond_hw_addr_swap() never re-adds the NS multicast addresses,
  and the call at err_close runs with new_slave->backup == 1 and invokes
  dev_mc_del() a second time.
- If bond_enslave() fails earlier (for example at netdev_rx_handler_register()
  or bond_master_upper_dev_link()) before bond_slave_ns_maddrs_add() is
  reached, new_slave->backup is already 1 and err_close calls dev_mc_del()
  without a matching add.

Because netdev multicast address entries are reference-counted, the extra
dev_mc_del() decrements and can remove pre-existing matching solicited-node
multicast MAC filters belonging to slave_dev itself.

If err_detach calls bond_set_slave_inactive_flags() before
bond_change_active_slave(bond, NULL) (matching __bond_release_one()), or if
bond_slave_ns_maddrs_del() is called only at err_dec_slave_cnt after
err_detach has already run, the add and delete calls stay balanced.

[1] https://sashiko.dev/#/bug/linux-3afd2f84-c338-4cc9-949c-4bc132bd2f79

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-bond_xdp_rollback-v1-1-35dddaa337ba@kylinos.cn?part=1

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

end of thread, other threads:[~2026-11-26 14:00 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-26 14:00 ` sashiko-bot

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