From: Slawomir Stepien <sst@poczta.fm>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Jesper Dangaard Brouer <hawk@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Stanislav Fomichev <sdf@fomichev.me>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
"Maciej Fijalkowski" <maciej.fijalkowski@intel.com>,
"Tianyi Gao" <tianyi@cloudflare.com>,
"Octavian Purdila" <tavip@google.com>,
"Toke Høiland-Jørgensen" <toke@redhat.com>,
"Alexander Lobakin" <aleksander.lobakin@intel.com>,
"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
"Lorenzo Bianconi" <lorenzo@kernel.org>,
"Magnus Karlsson" <magnus.karlsson@intel.com>,
"Ihor Solodrai" <ihor.solodrai@linux.dev>,
"Eric Dumazet" <edumazet@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"Simon Horman" <horms@kernel.org>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"Jiri Olsa" <jolsa@kernel.org>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Shuah Khan" <shuah@kernel.org>,
linux-kselftest@vger.kernel.org,
"Slawomir Stepien" <sst@poczta.fm>,
stable@vger.kernel.org
Subject: [PATCH v7 bpf 1/5] bpf: test_run: Use a private rxq info for XDP test runs
Date: Thu, 19 Nov 2026 14:30:28 +0100 [thread overview]
Message-ID: <20261119133032.2015656-2-sst@poczta.fm> (raw)
In-Reply-To: <20261119133032.2015656-1-sst@poczta.fm>
bpf_prog_test_run_xdp() runs the program with xdp->rxq pointing to the
xdp_rxq_info of a real device queue: queue 0 of the loopback device, or
the queue given by ingress_ifindex and rx_queue_index in the context.
The frags of a multi-buffer test packet come from alloc_page(), and when
the program releases one with bpf_xdp_adjust_tail() or
bpf_xdp_pull_data(), __xdp_return() frees it according to
xdp->rxq->mem.type. This only works as long as nobody else changes the
mem type of that shared queue.
The next patch makes generic XDP set the mem type of the queue it runs
on to MEM_TYPE_PAGE_POOL, since frags it hands to the program come from
skb_pp_cow_data(). After any packet went through generic XDP on lo, a
later test run would free its alloc_page() frags as page_pool pages:
WARNING: include/net/page_pool/helpers.h:305 at __xdp_return+0x828/0x9c0
Call Trace:
bpf_xdp_adjust_tail+0x8a0/0xd10
bpf_prog_..._xdp_adjust_tail_shrink+0xe1/0x101
bpf_test_run+0x31a/0xc30
bpf_prog_test_run_xdp+0x948/0x1740
and leak the page. Restoring the mem type after generic XDP would not
be enough, as generic XDP may run on the same queue on another CPU at
the same time.
Run the program on a private copy of the rxq info instead, with
MEM_TYPE_PAGE_SHARED, which describes the memory test_run allocates.
devmap and cpumap already do the same for the programs they run. The
device and queue index stay the same, so the program sees the same
ingress_ifindex and rx_queue_index, and xdp_convert_buff_to_md() still
drops the device reference. Live frames mode does not allow frags and
uses its own rxq info for the page_pool frames, so it is unaffected.
The problem was found by Sashiko AI review and BPF CI in the review of
v6 of this series.
Link: https://lore.kernel.org/all/sashiko-outbox-197255@kernel.org/
Cc: <stable@vger.kernel.org> # 6.4.x
Signed-off-by: Slawomir Stepien <sst@poczta.fm>
---
net/bpf/test_run.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index d6c9dc62182e..676107758678 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -1348,6 +1348,7 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
u32 repeat = kattr->test.repeat;
struct netdev_rx_queue *rxqueue;
struct skb_shared_info *sinfo;
+ struct xdp_rxq_info rxq;
struct xdp_buff xdp = {};
int i, ret = -EINVAL;
struct xdp_md *ctx;
@@ -1426,6 +1427,14 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
if (ret)
goto free_data;
+ /* xdp.rxq points to the rxq info of a real device queue, which
+ * generic XDP updates for every packet it runs on. Use a private
+ * copy with the mem type of the frags allocated below.
+ */
+ rxq = *xdp.rxq;
+ rxq.mem = (struct xdp_mem_info){ .type = MEM_TYPE_PAGE_SHARED };
+ xdp.rxq = &rxq;
+
size = linear_sz;
if (unlikely(kattr->test.data_size_in > size)) {
void __user *data_in = u64_to_user_ptr(kattr->test.data_in);
--
2.56.0
next prev parent reply other threads:[~2026-11-19 13:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 13:30 [PATCH v7 bpf 0/5] xdp: fix page_pool leaks Slawomir Stepien
2026-11-19 13:30 ` Slawomir Stepien [this message]
2026-11-19 13:30 ` [PATCH v7 bpf 2/5] xdp: introduce xdp_convert_skb_to_buff() Slawomir Stepien
2026-11-19 14:11 ` bot+bpf-ci
2026-11-20 8:45 ` Slawomir Stepien
2026-11-19 13:30 ` [PATCH v7 bpf 3/5] veth: use the frame mem type when running XDP on an xdp_frame Slawomir Stepien
2026-11-19 13:54 ` bot+bpf-ci
2026-11-19 14:24 ` Tianyi Gao
2026-11-20 8:56 ` Slawomir Stepien
2026-11-19 13:30 ` [PATCH v7 bpf 4/5] veth: update mem type in xdp_buff Slawomir Stepien
2026-11-19 13:30 ` [PATCH v7 bpf 5/5] selftests/bpf: Shrink test_run frags after generic XDP ran on lo Slawomir Stepien
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=20261119133032.2015656-2-sst@poczta.fm \
--to=sst@poczta.fm \
--cc=aleksander.lobakin@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@kernel.org \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=ilias.apalodimas@linaro.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=stable@vger.kernel.org \
--cc=tavip@google.com \
--cc=tianyi@cloudflare.com \
--cc=toke@redhat.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