Re: [PATCH net-next 05/15] xdp: Run programs on buffers that must not hold kernel structures
From: Maciej Fijalkowski
Date: Wed Nov 25 2026 - 10:41:44 EST
On Tue, Nov 24, 2026 at 01:56:40PM +0100, Björn Töpel wrote:
> Currently, the core refuses native XDP programs next to a memory
> provider. An AF_XDP sink needs XDP to steer its packets and to use the
> RX metadata kfuncs. Its buffers are UMEM chunks that XDP may read
> through the kernel mapping, but that userspace may write at any time,
> also while the kernel reads them. If drivers build XDP buffers on them
> as on pages, the core puts kernel structures into them, such as the
> shared info of a multi-buffer packet, the xdp_frame of XDP_TX and
> redirects, and the skb of XDP_PASS.
>
> Let programs run on sink buffers as on pages, and keep every kernel
> structure out of them.
>
> A sink offers an XDP view of its UMEM, so drivers build the buffer as
> for a page, while netmem_address() and skb_frag_address() still give
> NULL for sink net_iovs. Programs and helpers read and write the packet
> in place, fragments included. xdp_prepare_buff() tells a sink head by
> its address, with one range check under a static key, and marks the
> buffer before the driver adds fragments. Other buffers pay nothing
> while no sink is bound.
>
> A marked buffer keeps its shared info in the queue, with
> XDP_FLAGS_SINFO_EXT, set up when the driver registers a sink page pool
> as its memory model.
>
> A sink buffer may only go to the AF_XDP socket of its queue. The core
> turns XDP_TX and XDP_PASS into XDP_DROP, so drivers need no checks of
> their own. XDP_ABORTED and invalid verdicts reach the driver, which
> traces them and drops the packet. Frame conversion and skb
> construction refuse sink buffers too, so devmap and cpumap drop them,
> and sink net_iovs never become skb frags, so every net_iov frag stays
> unreadable.
>
> As userspace may change the bytes meanwhile, the kernel takes bounds
> only from its own fields, and only the program and its helpers read
> the bytes. A helper that reads bytes twice must check a copy.
>
> Signed-off-by: Björn Töpel <bjorn@xxxxxxxxxx>
> ---
> include/net/netmem.h | 5 ++-
> include/net/page_pool/types.h | 7 ++--
> include/net/xdp.h | 60 +++++++++++++++++++++++++++++++++--
> net/core/xdp.c | 46 +++++++++++++++++++++++++--
> 4 files changed, 108 insertions(+), 10 deletions(-)
> xdp_frame->data = xdp->data;
> @@ -763,6 +812,11 @@ static __always_inline u32 bpf_prog_run_xdp(const struct bpf_prog *prog,
> */
> u32 act = __bpf_prog_run(prog, xdp, BPF_DISPATCHER_FUNC(xdp));
>
> + /* Sink buffers go to the AF_XDP socket of their queue, or nowhere */
> + if (static_branch_unlikely(&xdp_sink_key) && xdp_buff_is_sink(xdp) &&
> + (act == XDP_PASS || act == XDP_TX))
> + act = XDP_DROP;
I think it would be better to follow SEC(xdp.frags) approach and from
verifier POV disallow progs doing anything different than XDP_REDIRECT...?
Here you affect whole system.
Also, I don't follow currently why xdp pass is not allowed, management
traffic gonna be dead on this queue.
> +
> if (static_branch_unlikely(&bpf_master_redirect_enabled_key)) {
> if (act == XDP_TX && netif_is_bond_slave(xdp->rxq->dev))
> act = xdp_master_redirect(xdp);