From: bot+bpf-ci@kernel.org
To: ayushmanrout27@gmail.com,bpf@vger.kernel.org
Cc: ayushmanrout27@gmail.com,daniel@iogearbox.net,john.fastabend@gmail.com,sdf@fomichev.me,martin.lau@linux.dev,ast@kernel.org,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,ihor.solodrai@linux.dev,davem@davemloft.net,edumazet@kernel.org,kuba@kernel.org,pabeni@redhat.com,horms@kernel.org,hawk@kernel.org,drosen@google.com,netdev@vger.kernel.org,linux-kernel@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v2] bpf: Use memmove() to load bytes from an skb and an xdp_buff
Date: Thu, 22 Oct 2026 12:05:27 +0000 (UTC) [thread overview]
Message-ID: <9e67828ba31a6f6e2d7c4b86bfdbba903cfa05cd468b58d4c03558cb8f453f3a@mail.kernel.org> (raw)
In-Reply-To: <20261022112312.31563-1-ayushmanrout27@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2488 bytes --]
> bpf: Use memmove() to load bytes from an skb and an xdp_buff
TL;DR: memmove() fix leaves the multi-frag xdp path (bpf_xdp_copy_buf) using
forward memcpy(), so bpf_dynptr_read() into an overlapping rdwr slice may
still corrupt data; the store path looks similar.
> diff --git a/net/core/filter.c b/net/core/filter.c
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
[ ... ]
> @@ -4298,7 +4298,7 @@ BPF_CALL_4(bpf_xdp_load_bytes, struct xdp_buff *, xdp, u32, offset,
> if (!ptr)
> bpf_xdp_copy_buf(xdp, offset, buf, len, false);
> else
> - memcpy(buf, ptr, len);
> + memmove(buf, ptr, len);
>
> return 0;
> }
The commit message says "A read that spans xdp frags still goes through
bpf_xdp_copy_buf() and is not changed here."
Can the same corruption still happen on that path?
bpf_xdp_copy_buf() copies segment by segment and writes into buf as it goes:
memcpy(dst, src, copy_len);
For an xdp dynptr, bpf_dynptr_slice_rdwr() with a NULL buffer returns a
direct pointer into whichever frag holds the requested range, so buf can
still be a slice of the same packet.
Consider a linear part of 100 bytes and a 4096 byte frag0:
dst = bpf_dynptr_slice_rdwr(&ptr, 110, NULL, 64); /* frag0 + 10 */
bpf_dynptr_read(dst, 64, &ptr, 90, 0);
bpf_dynptr_read()
__bpf_dynptr_read()
__bpf_xdp_load_bytes()
bpf_xdp_load_bytes()
bpf_xdp_pointer(xdp, 90, 64) /* NULL, since 90 + 64 > 100 */
bpf_xdp_copy_buf(xdp, 90, dst, 64, false)
The first memcpy() copies linear[90..100) onto frag0[10..20), which
clobbers source bytes that have not been read yet.
The next memcpy() then copies frag0[0..54) onto frag0[20..74), a forward
copy over an overlapping range.
A user-space model of this loop with forward copying returned 44 of 64 bytes
wrong.
The skb side does not look affected, since skb slices are always in the
linear head and skb_copy_bits() copies into a destination below the source.
Would it make sense to make the multi-segment copy overlap safe, for example
by going through a bounce buffer, or else to say in the commit message that
the xdp frag case remains broken? The store path
(bpf_xdp_store_bytes() -> bpf_xdp_copy_buf(..., true)) has the same shape.
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/39772397846
next prev parent reply other threads:[~2026-10-22 12:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 11:23 Ayushman Rout
2026-10-22 12:05 ` bot+bpf-ci [this message]
2026-10-24 4:00 ` patchwork-bot+netdevbpf
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=9e67828ba31a6f6e2d7c4b86bfdbba903cfa05cd468b58d4c03558cb8f453f3a@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=ayushmanrout27@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=drosen@google.com \
--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=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mason@kernel.org \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--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®