diff options
| author | Ayushman Rout <ayushmanrout27@gmail.com> | 2026-10-26 21:58:08 +0530 |
|---|---|---|
| committer | Alexei Starovoitov <ast@kernel.org> | 2026-11-01 01:10:23 +0000 |
| commit | 696f0954e3b6280aa87ea4a6196153e506b0ab9c (patch) | |
| tree | 57cdf71a6958d0a43af723c4ea933b72f1e0cab1 /scripts/basic | |
| parent | bcd07fd1673beb873e2bee2731e4ef4d716e70c7 (diff) | |
| download | linux-696f0954e3b6280aa87ea4a6196153e506b0ab9c.tar.gz linux-696f0954e3b6280aa87ea4a6196153e506b0ab9c.zip | |
bpf: Fix bpf_dynptr_copy() for overlapping ranges in one packet
When both dynptrs point into the same packet and the ranges overlap,
bpf_dynptr_copy() can copy wrong data in two ways.
If one range fits into a segment and the other one does not, the slice
of the first range is used as the buffer for __bpf_dynptr_read() or
__bpf_dynptr_write(). The range that crosses into a frag is copied piece
by piece, and an earlier piece can overwrite bytes that a later piece
has yet to read.
If neither range fits into a segment, the chunks are copied from the
start to the end through a 256 byte stack buffer. When the destination
is above the source, a chunk written to the destination overwrites
source bytes that later chunks have yet to read. For a copy of 1200
bytes with the destination 100 bytes above the source, the first chunk
writes source bytes 100..355 and the second chunk then reads bytes
256..355 after they were overwritten.
Do not use a slice as the buffer when both dynptrs share the same data,
and copy the chunks from the end to the start when the destination is
above the source, like memmove() does.
The selftests added later in this series pass with this change.
Fixes: daec295a7094 ("bpf/helpers: Introduce bpf_dynptr_copy kfunc")
Suggested-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Ayushman Rout <ayushmanrout27@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://patch.msgid.link/20261026162810.12862-2-ayushmanrout27@gmail.com
Diffstat (limited to 'scripts/basic')
0 files changed, 0 insertions, 0 deletions
