* [PATCH net-next] bonding: check XDP support before enslaving changes state
@ 2026-11-24 13:41 Hangbin Liu
2026-11-24 13:48 ` netdev-bot+sinfo
2026-11-25 14:12 ` netdev-bot+sashiko
0 siblings, 2 replies; 3+ messages in thread
From: Hangbin Liu @ 2026-11-24 13:41 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 in bond_enslave() - ndo_bpf/ndo_xdp_xmit
presence and the slave XDP program count - run only after the slave
has been opened, linked and published to the datapath. On failure the
slave may already be bond->curr_active_slave or reachable through
bond->slave_cnt and the upper device list, so a lot of state has to be
undone, and bond_xdp_xmit() can observe the slave before its
capability was ever verified.
Move both checks to the validation section at the top of
bond_enslave(), before the first state change, so a rejected slave
returns directly with nothing mutated. The dev_xdp_propagate() setup
stays in place and still uses the err_dec_slave_cnt error path.
Moving the checks alone is not enough. Without a bond xdp_prog they
are skipped, and a slave without ndo_xdp_xmit can be enslaved while
the bond still advertises NETDEV_XDP_ACT_NDO_XMIT built from the
other slaves. __xdp_enqueue() then accepts frames and the bulk-queue
flush hands them to bond_xdp_xmit(), which may pick the new slave and
call a NULL ndo_xdp_xmit in softirq context.
Check the selected slave in bond_xdp_xmit() and fail the frame with
-ENXIO instead. The check happens at xmit time, so it also covers
frames enqueued before bond_xdp_set_features() clears the flag, and
the bulk-queue flush path that never rechecks xdp_features.
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
Target this patch to net-next as it depends on f564749b3b26 ("net: record
XDP programs propagated to lower devices"). Please tell me if anyone
think it should be post to net.
For Sashiko: please ignore the bond's promiscuity/allmulti/ns maddrs
leak issue when xdp setup failed. It will be addressed in another patch.
---
drivers/net/bonding/bond_main.c | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 776afdb9df43..0149bd7764e7 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1951,6 +1951,20 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
return -EPERM;
}
+ 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_has_own_prog(slave_dev)) {
+ 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.
@@ -2314,15 +2328,7 @@ 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) {
+ if (bond->xdp_prog) {
struct netdev_bpf xdp = {
.command = XDP_SETUP_PROG,
.flags = 0,
@@ -2330,13 +2336,6 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
.extack = extack,
};
- if (dev_xdp_has_own_prog(slave_dev)) {
- 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 */
@@ -5681,7 +5680,7 @@ static int bond_xdp_xmit(struct net_device *bond_dev,
xdp_convert_frame_to_buff(frame, &xdp);
slave_dev = bond_xdp_get_xmit_slave(bond_dev, &xdp);
- if (!slave_dev) {
+ if (!slave_dev || unlikely(!slave_dev->netdev_ops->ndo_xdp_xmit)) {
err = -ENXIO;
break;
}
---
base-commit: a4c450594f5d1dc0fc4daacfb95d40554d99dead
change-id: 20261124-bond_xdp_fix-3f5eb6533f50
Best regards,
--
Hangbin Liu <liuhangbin@kylinos.cn>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net-next] bonding: check XDP support before enslaving changes state
2026-11-24 13:41 [PATCH net-next] bonding: check XDP support before enslaving changes state Hangbin Liu
@ 2026-11-24 13:48 ` netdev-bot+sinfo
2026-11-25 14:12 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-11-24 13:48 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: check XDP support before enslaving changes state
2026-11-24 13:41 [PATCH net-next] bonding: check XDP support before enslaving changes state Hangbin Liu
2026-11-24 13:48 ` netdev-bot+sinfo
@ 2026-11-25 14:12 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 14:12 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 2 potential
issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 1 · Low: 0
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] bonding: bond_xdp_xmit() checks ndo_xdp_xmit instead of
xdp_features
- [Medium] This patch fixes a kernel oops that is self-contained and goes
back years, but it has no Fixes: tag and it is mixed in with changes…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the XDP
propagate failure it keeps on the late path can leave freed memory…
--
bonding: check XDP support before enslaving changes state
This patch moves the ndo_bpf/ndo_xdp_xmit and dev_xdp_has_own_prog() checks
in bond_enslave() to the validation section, before any state is changed.
It also checks the selected slave's ndo_xdp_xmit in bond_xdp_xmit(). Frames
then fail with -ENXIO instead of calling a NULL pointer.
> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> index 776afdb9df43e..0149bd7764e7c 100644
> --- a/drivers/net/bonding/bond_main.c
> +++ b/drivers/net/bonding/bond_main.c
[ ... ]
> @@ -2330,13 +2336,6 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
> .extack = extack,
> };
>
> - if (dev_xdp_has_own_prog(slave_dev)) {
> - 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 */
[Severity: High]
This isn't a bug introduced by this patch, but the dev_xdp_propagate()
failure path that stays here looks like it can leave freed memory linked
into live 802.3ad state.
In BOND_MODE_8023AD, bond_enslave() calls bond_3ad_bind_slave(new_slave) and
then publishes the slave through bond_master_upper_dev_link(). If
dev_xdp_propagate() fails, the unwind runs through err_dec_slave_cnt,
err_sysfs_del, err_upper_unlink, err_unregister, err_detach and err_free.
None of those labels call bond_3ad_unbind_slave(). Its only caller is
__bond_release_one().
bond_3ad_state_machine_handler() runs from ad_work under mode_lock and RCU,
not RTNL, and walks bond_for_each_slave_rcu(). That means it can run while
the new slave is published. In that window ad_port_selection_logic() can
attach the new port to another slave's aggregator:
drivers/net/bonding/bond_3ad.c:ad_port_selection_logic() {
...
port->next_port_in_aggregator = aggregator->lag_ports;
aggregator->num_of_ports++;
aggregator->lag_ports = port;
...
free_aggregator->lag_ports = port;
...
}
The unwind then reaches slave_kobj_release() through kobject_put():
if (BOND_MODE(bond) == BOND_MODE_8023AD)
kfree(SLAVE_AD_INFO(slave));
However, the other slave's aggregator->lag_ports still points at the freed
port. On a later tick, ad_agg_selection_logic()->__agg_active_ports() walks
that list:
for (port = agg->lag_ports; port;
port = port->next_port_in_aggregator) {
if (READ_ONCE(port->is_enabled))
Can this read a freed struct port? When ports join or leave,
ad_port_selection_logic() can also write through
last_port->next_port_in_aggregator.
dev_xdp_propagate() can fail here when ndo_bpf refuses the program, for
example veth with a large MTU, or when it returns -EBUSY.
The note under the commit message only covers the promiscuity, allmulti and
ns maddrs leaks, so this one seems to be a separate issue.
Does the unwind need a bond_3ad_unbind_slave() call in 802.3ad mode?
[ ... ]
> @@ -5681,7 +5680,7 @@ static int bond_xdp_xmit(struct net_device *bond_dev,
> xdp_convert_frame_to_buff(frame, &xdp);
>
> slave_dev = bond_xdp_get_xmit_slave(bond_dev, &xdp);
> - if (!slave_dev) {
> + if (!slave_dev || unlikely(!slave_dev->netdev_ops->ndo_xdp_xmit)) {
> err = -ENXIO;
> break;
> }
[Severity: High]
Is checking the ndo_xdp_xmit pointer enough here? Most XDP capable
drivers fill in .ndo_xdp_xmit unconditionally in their static
net_device_ops. They only advertise NETDEV_XDP_ACT_NDO_XMIT in
dev->xdp_features once their XDP TX queues have been set up. For those
slaves the pointer is never NULL, so the new check doesn't stop the
call the commit message is worried about.
When bond->xdp_prog is NULL, bond_enslave() makes the new slave
selectable through bond->curr_active_slave, bond->slave_cnt and
bond_update_slave_arr(). All of that happens before
bond_xdp_set_features() recomputes bond_dev->xdp_features.
__xdp_enqueue() in kernel/bpf/devmap.c only checks the bond's flags,
and only at enqueue time:
if (!(dev->xdp_features & NETDEV_XDP_ACT_NDO_XMIT))
return -EOPNOTSUPP;
bq_xmit_all() then hands the queued frames to bond_xdp_xmit()
without rechecking anything. A slave whose XDP TX path isn't ready
can be picked by bond_xdp_get_xmit_slave() and have its
ndo_xdp_xmit called.
In gve, gve_xdp_xmit_dqo() takes smp_processor_id() modulo
priv->tx_cfg.num_xdp_queues, which is 0 when XDP isn't enabled on the
device. That is a divide by zero in softirq context.
In mvpp2, mvpp2_xdp_xmit() derives txq_id from port->ntxqs / 2. The
driver only advertises NETDEV_XDP_ACT_NDO_XMIT when port->ntxqs >=
num_possible_cpus() * 2, so port->txqs[txq_id] looks like it can be
indexed out of bounds otherwise.
Multi-buffer frames have the same problem. Suppose the existing
slaves support NETDEV_XDP_ACT_NDO_XMIT_SG and the new slave only does
linear XDP. Frames with xdp_frame_has_frags() that were enqueued
before bond_xdp_set_features() drops the SG bit can still be handed
to the new slave.
The commit message says the xmit time check covers frames enqueued
before the flag is cleared, and the bulk-queue flush path. That only
holds for slaves with a NULL ndo_xdp_xmit.
Would it be better to test READ_ONCE(slave_dev->xdp_features) for
NETDEV_XDP_ACT_NDO_XMIT here? It could also test
NETDEV_XDP_ACT_NDO_XMIT_SG when xdp_frame_has_frags(frame) is true,
the same way __xdp_enqueue() does for the bond itself.
[Severity: Medium]
This check seems to fix a NULL ndo_xdp_xmit call in softirq context. The
unguarded call goes back to commit 9e2ee5c7e7c3 ("net, bonding: Add XDP
support to the bonding driver"). Should this have a Fixes: tag?
On the net vs net-next question in the notes: as far as I can tell, this
one-line check doesn't depend on f564749b3b26 ("net: record XDP programs
propagated to lower devices"). Only the dev_xdp_has_own_prog() check that
moved to the top of bond_enslave() needs that commit.
When bond->xdp_prog is NULL, bond_enslave() publishes the new slave before
bond_xdp_set_features() recomputes the bond's flags:
bond_enslave()
bond_master_upper_dev_link()
WRITE_ONCE(bond->slave_cnt, bond->slave_cnt + 1);
...
bond_update_slave_arr()
bond_xdp_set_features()
During that window the bond can still advertise NETDEV_XDP_ACT_NDO_XMIT, so
__xdp_enqueue() in kernel/bpf/devmap.c accepts frames. The roundrobin,
active-backup or XOR selectors in bond_xdp_get_xmit_slave() can then pick
the new slave. Frames already sitting in a devmap bulk queue never recheck
xdp_features.
Could this hunk be split out into its own patch with a Fixes: tag for net,
so it can reach stable? The enslave check reordering could stay in
net-next.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-bond_xdp_fix-v1-1-e67983924324%40kylinos.cn
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-25 14:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 13:41 [PATCH net-next] bonding: check XDP support before enslaving changes state Hangbin Liu
2026-11-24 13:48 ` netdev-bot+sinfo
2026-11-25 14:12 ` 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®