summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSun Jian <sun.jian.kdev@gmail.com>2026-06-17 17:35:56 +0800
committerAlexei Starovoitov <ast@kernel.org>2026-06-21 17:55:06 -0700
commitb5f3534268e3f91c9d3e9dc79ee5a32555880ee9 (patch)
treee25a409fca3e0d6bb4ab064832a149eeeab00445
parent3eb21c86913439043c400cf9bbc521b015084b99 (diff)
bpf: Fix partial copy of non-linear test_run output
For non-linear test_run output, bpf_test_finish() derives the linear data copy length from copy_size - frag_size. This only matches the linear data length when copy_size is the full packet size. When userspace provides a short data_out buffer, copy_size is clamped to that buffer size. If copy_size is smaller than frag_size, the computed length becomes negative and bpf_test_finish() returns -ENOSPC before copying the packet prefix or updating data_size_out. Compute the linear data length from the packet layout instead, and clamp the linear copy length to copy_size. This preserves the expected partial-copy semantics: return -ENOSPC, copy the packet prefix that fits in data_out, and report the full packet length through data_size_out. Fixes: 7855e0db150ad ("bpf: test_run: add xdp_shared_info pointer in bpf_test_finish signature") Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com> Acked-by: Paul Chaignon <paul.chaignon@gmail.com> Link: https://lore.kernel.org/r/20260617093557.63880-2-sun.jian.kdev@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r--net/bpf/test_run.c8
1 files changed, 2 insertions, 6 deletions
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index 7fdee8f52ee2..5d51f6cb7d15 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -452,12 +452,8 @@ static int bpf_test_finish(const union bpf_attr *kattr,
}
if (data_out) {
- int len = sinfo ? copy_size - frag_size : copy_size;
-
- if (len < 0) {
- err = -ENOSPC;
- goto out;
- }
+ u32 head_len = size - frag_size;
+ u32 len = min(copy_size, head_len);
if (copy_to_user(data_out, data, len))
goto out;