Re: [PATCH net-next 02/15] xdp: Keep the shared info of a buffer in kernel memory

From: Björn Töpel

Date: Wed Nov 25 2026 - 14:39:13 EST


netdev-bot+sashiko@xxxxxxxxxx writes:

> Thank you for your contribution! Sashiko AI review found more severe
> issue(s) in other patches of this series. This mail is only an FYI, in case
> you want to address the nit picks below when you respin.
>
> Low priority / nit picks for your consideration:
>
> - [Low] A comment is now stale.
>
> Pre-existing issues:
> - [High] This problem wasn't introduced by this patch, but the patch's
> commit message names it and the series leaves it open.
>
> --
>
> xdp: Keep the shared info of a buffer in kernel memory
>
> This patch lets an RX queue keep the skb_shared_info of its XDP buffers
> in kernel memory, allocated by xdp_rxq_info_reg_ext_sinfo(). Buffers
> with the new XDP_FLAGS_SINFO_EXT flag look up their shared info there.
> For such buffers xdp_data_hard_end() reserves no tailroom, and frame
> and skb conversion refuse them.
>
>> diff --git a/include/net/xdp.h b/include/net/xdp.h
>> index 1629e347b71fb..944418111a86e 100644
>> --- a/include/net/xdp.h
>> +++ b/include/net/xdp.h
>
> [ ... ]
>
>> @@ -212,17 +226,27 @@ xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,
>>
>> /* Reserve memory area at end-of data area.
>> *
>> - * This macro reserves tailroom in the XDP buffer by limiting the
>> - * XDP/BPF data access to data_hard_end. Notice same area (and size)
>> - * is used for XDP_PASS, when constructing the SKB via build_skb().
>> + * This reserves tailroom in the XDP buffer by limiting the XDP/BPF data
>> + * access to data_hard_end. Notice same area (and size) is used for
>> + * XDP_PASS, when constructing the SKB via build_skb(). Buffers with
>> + * %XDP_FLAGS_SINFO_EXT keep the shared info elsewhere and reserve none.
>> */
>> -#define xdp_data_hard_end(xdp) \
>> - ((xdp)->data_hard_start + (xdp)->frame_sz - \
>> - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
>> +static __always_inline void *xdp_data_hard_end(const struct xdp_buff *xdp)
>> +{
>> + u32 tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
>> +
>> + if (xdp->flags & XDP_FLAGS_SINFO_EXT)
>> + tailroom = 0;
>> + return xdp->data_hard_start + xdp->frame_sz - tailroom;
>> +}
>
> [Severity: Low]
> This isn't a bug, but should the comment in bpf_xdp_adjust_tail() be
> updated along with this change?
>
> net/core/filter.c:bpf_xdp_adjust_tail() {
> ...
> /* Notice that xdp_data_hard_end have reserved some tailroom */
> if (unlikely(data_end > data_hard_end))
> return -EINVAL;
> ...
> }
>
> xdp_data_hard_end() no longer reserves tailroom for XDP_FLAGS_SINFO_EXT
> buffers. For those buffers this bound reaches the end of the frame, and
> frame_sz is the only limit.

Yes, will fix.

>>
>> static inline struct skb_shared_info *
>> xdp_get_shared_info_from_buff(const struct xdp_buff *xdp)
>> {
>> + /* Kernel structures stay out of memory that userspace may write */
>> + if (unlikely(xdp->flags & XDP_FLAGS_SINFO_EXT))
>> + return xdp->rxq->ext_sinfo;
>> +
>> return (struct skb_shared_info *)xdp_data_hard_end(xdp);
>> }
>
> [Severity: High]
> This is a pre-existing issue, not one introduced by this patch. The
> commit message gives it as the motivation:
>
> Classic AF_XDP zero copy keeps it in the tail of a UMEM chunk, where
> userspace can rewrite it.
>
> Is classic AF_XDP zero copy meant to stay exposed? XSK pool buffers
> never get XDP_FLAGS_SINFO_EXT, either here or later in the series. Later
> in the series only xdp_sink_mark() sets the flag, and only for
> MP_XDP_ONLY page pools.
>
> So xsk_buff_add_frag() still writes the fragment list into the UMEM
> tail:
>
> xsk_buff_add_frag()
> __xdp_buff_add_frag(head, ...)
> xdp_get_shared_info_from_buff(head)
> xdp_data_hard_end(head)
>
> That is the tailroom that xsk_pool_get_rx_frame_size() reserves when
> XDP_UMEM_SG_FLAG is set.
>
> Userspace can rewrite nr_frags and frags[] of chunks it has handed over
> through the fill ring while NAPI builds a multi-buffer packet. Can a
> forged nr_frags then overflow sinfo->frags[]? __xdp_buff_add_frag()
> only checks:
>
> } else if (unlikely(nr_frags == MAX_SKB_FRAGS)) {
> return false;
>
> With a value above MAX_SKB_FRAGS, it writes frags[nr_frags] past the
> end of the chunk.
>
> On XDP_PASS, xdp_copy_frags_from_zc() in net/core/xdp.c has the same
> problem:
>
> xinfo = xdp_get_shared_info_from_buff(xdp);
> nr_frags = xinfo->nr_frags;
>
> for (u32 i = 0; i < nr_frags; i++) {
>
> There is no bound on nr_frags here. It indexes skb_shinfo()->frags[] of
> the new skb and copies from skb_frag_address() of the forged frag
> netmems. xsk_rcv_zc() also sizes its RX ring reservation from nr_frags.
>
> Triggering this needs a zero-copy AF_XDP socket with XDP_UMEM_SG_FLAG
> and an attached XDP program.
>
> Could the commit message say that classic zero copy stays out of scope?
> Or could MEM_TYPE_XSK_BUFF_POOL buffers use ext_sinfo as well?

This is older than this series, and the series does not change it.
Classic is out of scope here.

I'll work with Magnus and Maciej to get a fix out for classic.