mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [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
  0 siblings, 1 reply; 2+ 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] 2+ 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
  0 siblings, 0 replies; 2+ 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] 2+ messages in thread

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

Thread overview: 2+ 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

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®