BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hangbin Liu" <hangbin.liu@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net-next] bonding: check XDP support before enslaving changes state
Date: Wed, 25 Nov 2026 13:41:54 +0000	[thread overview]
Message-ID: <sashiko-outbox-233496@kernel.org> (raw)
In-Reply-To: <20261124-bond_xdp_fix-v1-1-e67983924324@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] bonding: bond_xdp_xmit() checks ndo_xdp_xmit instead of
  xdp_features
- [Low] bonding: missing Fixes trailer for NULL ndo_xdp_xmit dereference
  fix
--

commit 4e12b56c05de5cd18169514e7abb34d8e38f9fd6
Author: Hangbin Liu <hangbin.liu@linux.dev>

> bonding: check XDP support before enslaving changes state
>
> 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>

[Severity: Low]
Since this fixes a NULL ndo_xdp_xmit dereference and the enslavement check
ordering from the original bonding XDP support, should it include a Fixes:
tag?

  Fixes: 9e2ee5c7e7c3 ("net, bonding: Add XDP support to the bonding driver")

> 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
[ ... ]
> @@ -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]
Should bond_xdp_xmit() check slave_dev->xdp_features for
NETDEV_XDP_ACT_NDO_XMIT (and NETDEV_XDP_ACT_NDO_XMIT_SG when
xdp_frame_has_frags(frame) is true), mirroring __xdp_enqueue(), instead of
only checking whether ndo_xdp_xmit is non-NULL?

Many drivers (such as gve and mvpp2) always set a non-NULL .ndo_xdp_xmit
pointer in their static net_device_ops and only enable
NETDEV_XDP_ACT_NDO_XMIT in dev->xdp_features when XDP TX queues are
allocated.  Because bond_enslave() publishes new_slave to the TX selection
paths before dev_xdp_propagate() and bond_xdp_set_features() run,
bond_xdp_xmit() can pick a newly enslaved device whose ndo_xdp_xmit pointer
is non-NULL while its XDP queues are uninitialized:

drivers/net/ethernet/google/gve/gve_tx_dqo.c:gve_xdp_xmit_dqo() {
	...
	qid = gve_xdp_tx_queue_id(priv,
				  smp_processor_id() % priv->tx_cfg.num_xdp_queues);
	...
}

In gve, priv->tx_cfg.num_xdp_queues is 0 when NETDEV_XDP_ACT_NDO_XMIT is
unset, causing a divide-by-zero panic in softirq context.  Similarly, a
multi-buffer frame enqueued while existing slaves advertised
NETDEV_XDP_ACT_NDO_XMIT_SG can be handed to a newly enslaved slave that only
supports linear XDP xmit.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-bond_xdp_fix-v1-1-e67983924324@kylinos.cn?part=1

  parent reply	other threads:[~2026-11-25 13:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 13:41 ` sashiko-bot [this message]
2026-11-25 14:12 ` 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-233496@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox