From: Ayushman Rout <ayushmanrout27@gmail.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, Ayushman Rout <ayushmanrout27@gmail.com>,
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>,
netdev@vger.kernel.org
Subject: [PATCH bpf 0/3] bpf: Fix overlapping copies in xdp and dynptr helpers
Date: Sat, 24 Oct 2026 14:56:55 +0530 [thread overview]
Message-ID: <20261024092659.76422-1-ayushmanrout27@gmail.com> (raw)
My patch "bpf: Use memmove() to load bytes from an skb and an xdp_buff"
was applied as b93cf2c8a055. The AI review on it noted that the
multi-frag path of bpf_xdp_copy_buf() still copies forward with
memcpy() and breaks when the buffer is a slice of the same packet. This
series fixes that.
Commit ab08863c58b1 ("bpf: Use memmove() to store bytes in an xdp_buff") fixed the
single-segment store path and left the cross-fragment case open. Patch 1
fixes that case for both load and store.
Patch 1 fixes bpf_xdp_copy_buf().
Patch 2 fixes bpf_dynptr_copy(), which has the same problem when both
ranges overlap in one packet and cross a segment boundary.
Patch 3 adds selftests.
Testing: x86_64 QEMU VM, ./test_progs -t dynptr. With the fixes all
four new tests pass. Without them the three xdp tests fail and the skb
test passes.
I also read the other memcpy() calls that could touch packet memory.
I found no overlap path, but this is not proven, so I left them
unchanged: the sock_ops header option copies, bpf_file_fetch_bytes(),
bpf_flow_dissector_load_bytes() and bpf_lwt_seg6_store_bytes().
v2 of the earlier patch:
https://patch.msgid.link/20261022112312.31563-1-ayushmanrout27@gmail.com
Ayushman Rout (3):
bpf: Fix bpf_xdp_copy_buf() when the buffer overlaps the packet
bpf: Fix bpf_dynptr_copy() for overlapping ranges in one packet
selftests/bpf: Test overlapping dynptr copies on xdp frags
kernel/bpf/helpers.c | 7 +-
net/core/filter.c | 59 ++++----
.../testing/selftests/bpf/prog_tests/dynptr.c | 4 +
.../selftests/bpf/progs/dynptr_success.c | 128 ++++++++++++++++++
4 files changed, 172 insertions(+), 26 deletions(-)
--
2.54.0
next reply other threads:[~2026-10-24 9:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-24 9:26 Ayushman Rout [this message]
2026-10-24 9:26 ` [PATCH bpf 1/3] bpf: Fix bpf_xdp_copy_buf() when the buffer overlaps the packet Ayushman Rout
2026-10-25 0:57 ` Alexei Starovoitov
2026-10-24 9:26 ` [PATCH bpf 3/3] selftests/bpf: Test overlapping dynptr copies on xdp frags Ayushman Rout
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=20261024092659.76422-1-ayushmanrout27@gmail.com \
--to=ayushmanrout27@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=hawk@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sdf@fomichev.me \
/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