From: sashiko-bot@kernel.org
To: "Hangbin Liu" <hangbin.liu@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net-next] bonding: undo enslave state when XDP setup fails
Date: Thu, 26 Nov 2026 14:00:05 +0000 [thread overview]
Message-ID: <sashiko-outbox-235667@kernel.org> (raw)
In-Reply-To: <20261125-bond_xdp_rollback-v1-1-35dddaa337ba@kylinos.cn>
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
next prev parent reply other threads:[~2026-11-26 14:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
2026-11-27 6:54 ` Hangbin Liu
2026-11-29 13:01 ` netdev-bot+sashiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-235667@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=hangbin.liu@linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.