From: "Björn Töpel" <bjorn@kernel.org>
To: netdev-bot+sashiko@kernel.org
Cc: magnus.karlsson@intel.com, maciej.fijalkowski@intel.com,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, andrew+netdev@lunn.ch, ast@kernel.org,
daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com,
andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com,
ilias.apalodimas@linaro.org, alexanderduyck@fb.com,
saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com,
leon@kernel.org, michael.chan@broadcom.com,
pavan.chebbi@broadcom.com, corbet@lwn.net, shuah@kernel.org,
bpf@vger.kernel.org, netdev@vger.kernel.org, stuclar@meta.com,
sdf@fomichev.me, horms@kernel.org, martin.lau@linux.dev,
almasrymina@google.com, song@kernel.org, yonghong.song@linux.dev,
jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev,
rdunlap@infradead.org, kernel-team@meta.com,
dimitri.daskalakis1@gmail.com, bobbyeshleman@meta.com,
mohsin.bashr@gmail.com, kees@kernel.org, leitao@debian.org,
maxime.chevallier@bootlin.com, cuitao@kylinos.cn,
vadim.fedorenko@linux.dev, mike.marciniszyn@gmail.com,
kuniyu@google.com, jiayuan.chen@linux.dev, mkarsten@uwaterloo.ca,
razor@blackwall.org, dw@davidwei.uk, asml.silence@gmail.com,
linux-rdma@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 02/15] xdp: Keep the shared info of a buffer in kernel memory
Date: Wed, 25 Nov 2026 20:39:04 +0100 [thread overview]
Message-ID: <87ld6gog4n.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <179561567996.3135.9952128421877275714@kernel.org>
netdev-bot+sashiko@kernel.org 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.
next prev parent reply other threads:[~2026-11-25 19:39 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 11:26 [PATCH net-next 00/15] xsk: Receive in the device's buffer layout Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 01/15] xdp: Let memory providers offer XDP a view of their net_iovs Björn Töpel
2026-11-25 14:07 ` netdev-bot+sashiko
2026-11-25 19:34 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 02/15] xdp: Keep the shared info of a buffer in kernel memory Björn Töpel
2026-11-25 14:07 ` netdev-bot+sashiko
2026-11-25 19:39 ` Björn Töpel [this message]
2026-11-25 15:17 ` Maciej Fijalkowski
2026-11-25 19:36 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 03/15] net: Add memory providers that only feed XDP Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 19:43 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 04/15] page_pool: Let memory providers take back net_iovs Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 19:45 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 05/15] xdp: Run programs on buffers that must not hold kernel structures Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 19:55 ` Björn Töpel
2026-11-25 15:22 ` Maciej Fijalkowski
2026-11-25 15:28 ` Maciej Fijalkowski
2026-11-25 19:50 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 06/15] xsk: Lend UMEM chunks to the page pools of a queue Björn Töpel
2026-11-24 14:34 ` Magnus Karlsson
2026-11-24 15:12 ` Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 20:02 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 07/15] xsk: Deliver to the socket in the device's buffer layout Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 20:11 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 08/15] xsk: Receive " Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 20:16 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 09/15] eth: fbnic: Support XDP redirect Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 10/15] eth: fbnic: Receive into XDP-only memory providers Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 11/15] net: Add netif_rxq_has_xdp_only_mp() Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 12/15] eth: mlx5e: Receive into XDP-only memory providers Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 20:26 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 13/15] eth: bnxt: " Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 20:33 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 14/15] selftests: net: xsk: Test the device's RX buffer layout Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-24 12:56 ` [PATCH net-next 15/15] Documentation: networking: Describe AF_XDP RX in the device's layout Björn Töpel
2026-11-25 14:08 ` 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=87ld6gog4n.fsf@all.your.base.are.belong.to.us \
--to=bjorn@kernel.org \
--cc=alexanderduyck@fb.com \
--cc=almasrymina@google.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrii@kernel.org \
--cc=asml.silence@gmail.com \
--cc=ast@kernel.org \
--cc=bobbyeshleman@meta.com \
--cc=bpf@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=cuitao@kylinos.cn \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dimitri.daskalakis1@gmail.com \
--cc=dw@davidwei.uk \
--cc=eddyz87@gmail.com \
--cc=edumazet@kernel.org \
--cc=emil@etsalapatis.com \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=ilias.apalodimas@linaro.org \
--cc=jiayuan.chen@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kees@kernel.org \
--cc=kernel-team@meta.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=leitao@debian.org \
--cc=leon@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=martin.lau@linux.dev \
--cc=maxime.chevallier@bootlin.com \
--cc=mbloch@nvidia.com \
--cc=memxor@gmail.com \
--cc=michael.chan@broadcom.com \
--cc=mike.marciniszyn@gmail.com \
--cc=mkarsten@uwaterloo.ca \
--cc=mohsin.bashr@gmail.com \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pavan.chebbi@broadcom.com \
--cc=razor@blackwall.org \
--cc=rdunlap@infradead.org \
--cc=saeedm@nvidia.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=stuclar@meta.com \
--cc=tariqt@nvidia.com \
--cc=vadim.fedorenko@linux.dev \
--cc=yonghong.song@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
all inboxes | Powered by JetHome®