On Thu, Dec 03, 2026 at 10:56:43AM +0100, Björn Töpel wrote:
> xdp_build_skb_from_zc() gives the skb head the frame size of the XSk
> buffer, and the skb shared info takes the end of it. A device may fill
> a single-buffer XSk frame to its end, so a long packet overwrites the
> shared info of the new skb with packet data. With 2K chunks, no UMEM
> headroom and the default MTU, a 1514 byte frame that XDP passes on
> ice, idpf or gve needs 256 + 1514 + 320 = 2090 bytes and gets 2048.
> The sender controls up to 48 bytes of the shared info, its frag list
> among them. The last patch of this series lets multi-buffer pools and
> bpf_xdp_adjust_tail() reach the end of the frame as well.
>
> The copies of the head and of the fragments also round the length up
> to 16 bytes, and read and write past the end of the data.
>
> Size the head from the data, and copy the exact length. Heads larger
> than a page come from kmalloc, not the page pool.
>
> Found again by an AI code review agent, and the 2K case by reading the
> code. Reproduced out of tree, with a test module and the AF_XDP
> page-pool RFC on fbnic in QEMU.
>
> Reported-by: Clément Lecigne <clec…@google.com>
> Link: https://lore.kernel.org/bpf/2026…@google.com/
> Fixes: 560d958c6c68 ("xsk: add generic XSk &xdp_buff -> skb conversion")
> Acked-by: Alexander Lobakin <alek…@intel.com>
> Signed-off-by: Björn Töpel <bjo…@kernel.org>
Reviewed-by: Maciej Fijalkowski <maci…@intel.com>
> ---
> net/core/xdp.c | 40 ++++++++++++++++++++++++++++------------
> 1 file changed, 28 insertions(+), 12 deletions(-)
>
> diff --git a/net/core/xdp.c b/net/core/xdp.c
> index 1d679e8fd649..33a6740b411f 100644
> --- a/net/core/xdp.c
> +++ b/net/core/xdp.c
> @@ -709,7 +709,7 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
> }
>
> memcpy(page_address(page) + offset, skb_frag_address(frag),
> - LARGEST_ALIGN(len));
> + len);
> __skb_fill_page_desc_noacc(sinfo, i, page, offset, len);
>
> tsize += truesize;
> @@ -723,6 +723,27 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
> return true;
> }
>
> +static struct sk_buff *xdp_zc_alloc_head(struct page_pool *pp,
> + struct net_device *dev, u32 size)
> +{
> + u32 truesize = SKB_HEAD_ALIGN(size);
> + struct sk_buff *skb;
> + void *data;
> +
> + if (truesize > PAGE_SIZE)
> + return __netdev_alloc_skb(dev, size, GFP_ATOMIC | __GFP_NOWARN);
> +
> + data = page_pool_dev_alloc_va(pp, &truesize);
> + if (unlikely(!data))
> + return NULL;
> +
> + skb = napi_build_skb(data, truesize);
> + if (unlikely(!skb))
> + page_pool_free_va(pp, data, true);
> +
> + return skb;
> +}
> +
> /**
> * xdp_build_skb_from_zc - create an skb from XSk &xdp_buff
> * @xdp: source XSk buff
> @@ -730,7 +751,8 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
> * Similar to xdp_build_skb_from_buff(), but for XSk frames. Allocate an skb
> * head, new buffer for the head, copy the data and initialize the skb fields.
> * If there are frags, allocate new buffers for them and copy.
> - * Buffers are allocated from the system percpu pools to try recycling them.
> + * Buffers are allocated from the system percpu pools to try recycling them,
> + * except a head that does not fit into a page.
> * If new skb was built successfully, @xdp is returned to XSk pool's freelist.
> * On error, it remains untouched and the caller must take care of this.
> *
> @@ -738,33 +760,27 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
> */
> struct sk_buff *xdp_build_skb_from_zc(struct xdp_buff *xdp)
> {
> + u32 size = xdp->data_end - xdp->data_hard_start;
> const struct xdp_rxq_info *rxq = xdp->rxq;
> u32 len = xdp->data_end - xdp->data_meta;
> - u32 truesize = xdp->frame_sz;
> struct sk_buff *skb = NULL;
> struct page_pool *pp;
> int metalen;
> - void *data;
>
> if (!IS_ENABLED(CONFIG_PAGE_POOL))
> return NULL;
>
> local_lock_nested_bh(&system_page_pool.bh_lock);
> pp = this_cpu_read(system_page_pool.pool);
> - data = page_pool_dev_alloc_va(pp, &truesize);
> - if (unlikely(!data))
> - goto out;
>
> - skb = napi_build_skb(data, truesize);
> - if (unlikely(!skb)) {
> - page_pool_free_va(pp, data, true);
> + skb = xdp_zc_alloc_head(pp, rxq->dev, size);
> + if (unlikely(!skb))
> goto out;
> - }
>
> skb_mark_for_recycle(skb);
> skb_reserve(skb, xdp->data_meta - xdp->data_hard_start);
>
> - memcpy(__skb_put(skb, len), xdp->data_meta, LARGEST_ALIGN(len));
> + memcpy(__skb_put(skb, len), xdp->data_meta, len);
>
> metalen = xdp->data - xdp->data_meta;
> if (metalen > 0) {
> --
> 2.53.1-Meta
>