Skip to content

bpf: Fix overlapping copies in bpf_dynptr_copy()

Ayushman Rout bpf linux-kselftest lkml netdev 1 version Applied

Status from this message: This series was applied to bpf/bpf.git (master)

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest2 patches 0 repliesApplied 2/2

Changes in v2 from the cover letter

- 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

Patches in v2 All 2 applied

#Subject and filesSizeRepliesApplied
1/2bpf: Fix bpf_dynptr_copy() for overlapping ranges in one packetkernel/bpf/helpers.c+12 -40 repliesApplied
2/2selftests/bpf: Test overlapping dynptr copies on xdp fragstools/testing/selftests/bpf/prog_tests/dynptr.c tools/testing/selftests/bpf/progs/dynptr_success.c+93 -00 repliesApplied

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH bpf v2 0/2] bpf: Fix overlapping copies in bpf_dynptr_copy()

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/[email protected]/

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(-)
Signature · 1 line
2.54.0