From: netdev-bot+sashiko@kernel.org
To: bjorn@kernel.org
Cc: magnus.karlsson@intel.com, maciej.fijalkowski@intel.com,
aleksander.lobakin@intel.com, ast@kernel.org,
daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com,
andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, willemb@google.com, andrew+netdev@lunn.ch,
anthony.l.nguyen@intel.com, przemyslaw.kitszel@intel.com,
netdev@vger.kernel.org, bpf@vger.kernel.org, horms@kernel.org,
sdf@fomichev.me, martin.lau@linux.dev, song@kernel.org,
yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com,
ihor.solodrai@linux.dev, intel-wired-lan@lists.osuosl.org,
clecigne@google.com, michal.swiatkowski@linux.intel.com,
sriram.yagnaraman@ericsson.com, kurt@linutronix.de
Subject: Re: [PATCH net v3 4/4] xsk: Keep the shared info of zero-copy buffers in kernel memory
Date: Fri, 04 Dec 2026 10:39:39 +0000 [thread overview]
Message-ID: <179638077906.3146.4204032299868924468@kernel.org> (raw)
In-Reply-To: <20261203095647.3448925-5-bjorn@kernel.org>
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] The commit message understates the bug it fixes.
- [Low] The AF_XDP selftests still model the old UMEM layout, in which ZC
multi-buffer pools reserved skb_shared_info tailroom at the end of…
--
xsk: Keep the shared info of zero-copy buffers in kernel memory
This moves the skb_shared_info of zero-copy multi-buffer packets out of the
user-writable UMEM chunk tailroom and into the xsk_buff_pool. A new
XDP_FLAGS_SINFO_EXT flag tells xdp_get_shared_info_from_buff() to use
rxq->ext_sinfo, and xdp_data_hard_end() then reserves no tailroom. The
UMEM headroom limit in xdp_umem_reg() is relaxed to match.
> A packet that a driver receives in zero-copy mode over several buffers
> keeps its shared info, the fragment list and its count, in the
> tailroom of the UMEM chunk of its head. Userspace may write the UMEM
> at any time, also while the kernel walks the fragments, and a
> rewritten list or count makes the kernel read and write out of bounds.
[Severity: Low]
Does "read and write out of bounds" fully describe the impact?
Before this patch, xdp_get_shared_info_from_buff() returned a pointer into
the UMEM chunk tailroom for a zero-copy head. Each skb_frag_t stored there
holds a netmem_ref plus len and offset. That means userspace could forge
the page pointer, the length and the offset, not just nr_frags.
The consumers use those values directly. xdp_copy_frags_from_zc() does:
memcpy(page_address(page) + offset, skb_frag_address(frag),
len);
This copies from a kernel address that userspace chooses into an skb that
is passed up the stack. bpf_xdp_frags_increase_tail() does:
memset(skb_frag_address(frag) + skb_frag_size(frag), 0, offset);
This writes at an address that userspace chooses.
__xdp_buff_add_frag() also reads nr_frags back from the UMEM. It only
rejects nr_frags == MAX_SKB_FRAGS, so a forged count of up to 255 sends
the frags[] write far past the chunk.
This gives userspace a kernel read and write at addresses it picks, not an
access limited to the area next to the chunk. To reach it you need
ns_capable(CAP_NET_RAW) in xsk_create(), a netdev that supports zero-copy,
and an AF_XDP socket bound with XDP_USE_SG in zero-copy mode.
Could the commit message state the real impact and the privilege needed?
Stable reviewers and backporters use that to triage. The patch also relaxes
the headroom check in xdp_umem_reg(), so they need it to weigh that change.
> diff --git a/include/net/xdp.h b/include/net/xdp.h
> index 07231adfb5f82..0524027669882 100644
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h
[ ... ]
> @@ -178,17 +189,26 @@ xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,
[ ... ]
> -#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]
Should the AF_XDP selftests be updated along with this layout change?
They still assume that zero-copy multi-buffer chunks reserve
skb_shared_info tailroom at the end. test_xsk() in prog_tests/xsk.c and
main() in xskxceiver.c both compute:
/* 48 bytes is a part of skb_shared_info w/o frags array;
* 16 bytes is sizeof(skb_frag_t)
*/
umem_tailroom = ALIGN(48 + (max_frags * 16), cache_line_size);
In prog_tests/test_xsk.c, testapp_adjust_tail_grow_mb() still has the
comment "4k is truesize, 3k payload, 256 HR, 320 TR". It also subtracts
umem_tailroom from grow_size.
testapp_stats_rx_dropped() subtracts umem_tr when it sets frame_headroom.
That lands exactly on the old xdp_umem_reg() limit
(4096 - 256 - 128 - 320 = 3392).
These sizes are conservative, so the tests still pass. However, no test
covers a zero-copy bpf_xdp_adjust_tail() grow up to the end of the chunk.
No test uses a UMEM headroom above the old limit either.
Wouldn't these tests pass just the same if the kernel still reserved the
tailroom?
>
> static inline struct skb_shared_info *
> xdp_get_shared_info_from_buff(const struct xdp_buff *xdp)
> {
> + if (xdp->flags & XDP_FLAGS_SINFO_EXT)
> + return READ_ONCE(xdp->rxq)->ext_sinfo;
> +
> return (struct skb_shared_info *)xdp_data_hard_end(xdp);
> }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203095647.3448925-1-bjorn%40kernel.org
prev parent reply other threads:[~2026-12-04 10:39 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 9:56 [PATCH net v3 0/4] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
2026-12-03 9:56 ` [PATCH net v3 1/4] libeth: xsk: Count each XDP_TX buffer on its own Björn Töpel
2026-12-04 10:39 ` netdev-bot+sashiko
2026-12-03 9:56 ` [PATCH net v3 2/4] xdp: Size zero-copy skbs from the data, not the frame size Björn Töpel
2026-12-03 14:04 ` Maciej Fijalkowski
2026-12-04 10:39 ` netdev-bot+sashiko
2026-12-03 9:56 ` [PATCH net v3 3/4] intel: Copy the exact length of XSk packets to skbs Björn Töpel
2026-12-03 14:07 ` Maciej Fijalkowski
2026-12-03 9:56 ` [PATCH net v3 4/4] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
2026-12-03 15:16 ` Maciej Fijalkowski
2026-12-04 10:39 ` netdev-bot+sashiko [this message]
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=179638077906.3146.4204032299868924468@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=aleksander.lobakin@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrii@kernel.org \
--cc=anthony.l.nguyen@intel.com \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=clecigne@google.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--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=intel-wired-lan@lists.osuosl.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=kurt@linutronix.de \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=michal.swiatkowski@linux.intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=sriram.yagnaraman@ericsson.com \
--cc=willemb@google.com \
--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