Netdev List
 help / color / mirror / Atom feed
* [PATCH bpf v2 0/2] bpf: Fix overlapping copies in bpf_dynptr_copy()
@ 2026-10-26 16:28 Ayushman Rout
  2026-10-26 16:28 ` [PATCH bpf v2 2/2] selftests/bpf: Test overlapping dynptr copies on xdp frags Ayushman Rout
  0 siblings, 1 reply; 2+ messages in thread
From: Ayushman Rout @ 2026-10-26 16:28 UTC (permalink / raw)
  To: bpf
  Cc: ast, Ayushman Rout, Daniel Borkmann, David S. Miller,
	Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend,
	Stanislav Fomichev, netdev

bpf_dynptr_copy() can corrupt data when both ranges are in the same xdp
packet and overlap: a slice of one range is used as the buffer for
__bpf_dynptr_read() or __bpf_dynptr_write(), and the chunk loop always
copies forward.

Patch 1 does not use a slice as the buffer for a copy within one packet
and copies from the end when the destination is above the source.
Patch 2 adds selftests. They pass with the fix.

Changes in v2:
- Dropped the bpf_xdp_copy_buf() change and fixed everything in
  bpf_dynptr_copy(), as suggested by Alexei
- Reworked the tests into bpf_dynptr_copy() tests where only one of the
  ranges crosses into frag0

v1: https://lore.kernel.org/bpf/20261024092659.76422-1-ayushmanrout27@gmail.com/

Ayushman Rout (2):
  bpf: Fix bpf_dynptr_copy() for overlapping ranges in one packet
  selftests/bpf: Test overlapping dynptr copies on xdp frags

 kernel/bpf/helpers.c                          | 16 +++-
 .../testing/selftests/bpf/prog_tests/dynptr.c |  3 +
 .../selftests/bpf/progs/dynptr_success.c      | 90 +++++++++++++++++++
 3 files changed, 105 insertions(+), 4 deletions(-)

-- 
2.54.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-26 16:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-26 16:28 [PATCH bpf v2 0/2] bpf: Fix overlapping copies in bpf_dynptr_copy() Ayushman Rout
2026-10-26 16:28 ` [PATCH bpf v2 2/2] selftests/bpf: Test overlapping dynptr copies on xdp frags Ayushman Rout

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox