* [PATCH net] bonding: check slave xdp_features in bond_xdp_xmit
@ 2026-11-27 3:08 Hangbin Liu
2026-12-04 11:31 ` Paolo Abeni
2026-12-04 11:40 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Hangbin Liu @ 2026-11-27 3:08 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,
Jussi Maki
Cc: Hangbin Liu, netdev, bpf, stable, Hangbin Liu
From: Hangbin Liu <liuhangbin@kylinos.cn>
bond_xdp_xmit() may select a slave that bond_enslave() made visible
before bond_xdp_set_features() republished the bond's xdp_features.
Frames enqueued in that window pass __xdp_enqueue()'s bond-level
checks, and the bulk-queue flush later calls bond_xdp_xmit() without
rechecking anything. The selected slave may be unable to transmit
XDP frames:
- NETDEV_XDP_ACT_NDO_XMIT appears only once the driver's XDP TX
queues are up.
- a linear-only slave receives multi-buffer frames enqueued while
the bond still advertised NETDEV_XDP_ACT_NDO_XMIT_SG.
- with no bond->xdp_prog, bond_enslave() skips the capability
check: a slave without XDP joins while the bond still
advertises NETDEV_XDP_ACT_NDO_XMIT (built from the other
slaves; __xdp_enqueue() never looks at dev->xdp_prog) and
bond_xdp_set_features() drops the flag only afterwards.
Apply the __xdp_enqueue() contract to the selected slave at xmit
time: require NETDEV_XDP_ACT_NDO_XMIT and, for fragmented frames,
NETDEV_XDP_ACT_NDO_XMIT_SG, failing with -ENXIO otherwise (the
caller frees the frames).
Fixes: 9e2ee5c7e7c3 ("net, bonding: Add XDP support to the bonding driver")
Cc: stable@vger.kernel.org # b9d460c92455 ("bpf: devmap: check XDP features in __xdp_enqueue routine")
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
The issue was identified when sashiko review other patches.
The issue is theoretical and only happen in a race window, I didn't
reproduce it.
For Sashiko,
Please ignore the error out issues during bond_enslave. They will
be addressed in other patches.
---
drivers/net/bonding/bond_main.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 042d7c75548f..6ceefb0bfc20 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -5664,6 +5664,7 @@ static int bond_xdp_xmit(struct net_device *bond_dev,
struct xdp_frame *frame = frames[nxmit];
struct xdp_frame *frames1[] = {frame};
struct net_device *slave_dev;
+ xdp_features_t feats;
struct xdp_buff xdp;
xdp_convert_frame_to_buff(frame, &xdp);
@@ -5674,6 +5675,18 @@ static int bond_xdp_xmit(struct net_device *bond_dev,
break;
}
+ /* The slave can be selected before bond_xdp_set_features()
+ * republishes the bond's xdp_features, so apply the
+ * __xdp_enqueue() contract to the slave itself.
+ */
+ feats = READ_ONCE(slave_dev->xdp_features);
+ if (unlikely(!(feats & NETDEV_XDP_ACT_NDO_XMIT) ||
+ (!(feats & NETDEV_XDP_ACT_NDO_XMIT_SG) &&
+ xdp_frame_has_frags(frame)))) {
+ err = -ENXIO;
+ break;
+ }
+
err = slave_dev->netdev_ops->ndo_xdp_xmit(slave_dev, 1, frames1, flags);
if (err < 1)
break;
---
base-commit: e1055cbfd6eb578417f3ce983cf44462e8465267
change-id: 20261127-bond_xdp_xmit-5dfe5b99d10c
Best regards,
--
Hangbin Liu <liuhangbin@kylinos.cn>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] bonding: check slave xdp_features in bond_xdp_xmit
2026-11-27 3:08 [PATCH net] bonding: check slave xdp_features in bond_xdp_xmit Hangbin Liu
@ 2026-12-04 11:31 ` Paolo Abeni
2026-12-04 11:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Paolo Abeni @ 2026-12-04 11:31 UTC (permalink / raw)
To: Hangbin Liu, Jay Vosburgh, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
Jussi Maki
Cc: netdev, bpf, stable
On 11/27/26 04:08, Hangbin Liu wrote:
> From: Hangbin Liu <liuhangbin@kylinos.cn>
>
> bond_xdp_xmit() may select a slave that bond_enslave() made visible
> before bond_xdp_set_features() republished the bond's xdp_features.
> Frames enqueued in that window pass __xdp_enqueue()'s bond-level
> checks, and the bulk-queue flush later calls bond_xdp_xmit() without
> rechecking anything. The selected slave may be unable to transmit
> XDP frames:
>
> - NETDEV_XDP_ACT_NDO_XMIT appears only once the driver's XDP TX
> queues are up.
> - a linear-only slave receives multi-buffer frames enqueued while
> the bond still advertised NETDEV_XDP_ACT_NDO_XMIT_SG.
> - with no bond->xdp_prog, bond_enslave() skips the capability
> check: a slave without XDP joins while the bond still
> advertises NETDEV_XDP_ACT_NDO_XMIT (built from the other
> slaves; __xdp_enqueue() never looks at dev->xdp_prog) and
> bond_xdp_set_features() drops the flag only afterwards.
>
> Apply the __xdp_enqueue() contract to the selected slave at xmit
> time: require NETDEV_XDP_ACT_NDO_XMIT and, for fragmented frames,
> NETDEV_XDP_ACT_NDO_XMIT_SG, failing with -ENXIO otherwise (the
> caller frees the frames).
>
> Fixes: 9e2ee5c7e7c3 ("net, bonding: Add XDP support to the bonding driver")
> Cc: stable@vger.kernel.org # b9d460c92455 ("bpf: devmap: check XDP features in __xdp_enqueue routine")
> Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
Given the 'broken from day-1' status, and the mostly theoretical
nature of the issue, I think this is net-next material.
/P
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] bonding: check slave xdp_features in bond_xdp_xmit
2026-11-27 3:08 [PATCH net] bonding: check slave xdp_features in bond_xdp_xmit Hangbin Liu
2026-12-04 11:31 ` Paolo Abeni
@ 2026-12-04 11:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-12-04 11:40 UTC (permalink / raw)
To: Hangbin Liu
Cc: jv, andrew+netdev, davem, edumazet, kuba, pabeni, ast, daniel,
hawk, john.fastabend, sdf, joamaki, netdev, bpf, stable
Hello:
This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Fri, 27 Nov 2026 11:08:54 +0800 you wrote:
> From: Hangbin Liu <liuhangbin@kylinos.cn>
>
> bond_xdp_xmit() may select a slave that bond_enslave() made visible
> before bond_xdp_set_features() republished the bond's xdp_features.
> Frames enqueued in that window pass __xdp_enqueue()'s bond-level
> checks, and the bulk-queue flush later calls bond_xdp_xmit() without
> rechecking anything. The selected slave may be unable to transmit
> XDP frames:
>
> [...]
Here is the summary with links:
- [net] bonding: check slave xdp_features in bond_xdp_xmit
https://git.kernel.org/netdev/net-next/c/79bdbf36c64d
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-04 11:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 3:08 [PATCH net] bonding: check slave xdp_features in bond_xdp_xmit Hangbin Liu
2026-12-04 11:31 ` Paolo Abeni
2026-12-04 11:40 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox