diff options
author | Lorenz Bauer <lmb@cloudflare.com> | 2018-12-03 12:31:23 +0100 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2018-12-04 17:18:13 +0100 |
commit | b5a36b1e1b138285ea0df34bf96c759e1e30fafd (patch) | |
tree | 979d2a28beaa2dcb3bba77964e7e44630694e8eb /net/bpf/test_run.c | |
parent | samples: bpf: fix: seg fault with NULL pointer arg (diff) | |
download | linux-b5a36b1e1b138285ea0df34bf96c759e1e30fafd.tar.xz linux-b5a36b1e1b138285ea0df34bf96c759e1e30fafd.zip |
bpf: respect size hint to BPF_PROG_TEST_RUN if present
Use data_size_out as a size hint when copying test output to user space.
ENOSPC is returned if the output buffer is too small.
Callers which so far did not set data_size_out are not affected.
Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'net/bpf/test_run.c')
-rw-r--r-- | net/bpf/test_run.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index c89c22c49015..7663e6a57280 100644 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -74,8 +74,18 @@ static int bpf_test_finish(const union bpf_attr *kattr, { void __user *data_out = u64_to_user_ptr(kattr->test.data_out); int err = -EFAULT; + u32 copy_size = size; + + /* Clamp copy if the user has provided a size hint, but copy the full + * buffer if not to retain old behaviour. + */ + if (kattr->test.data_size_out && + copy_size > kattr->test.data_size_out) { + copy_size = kattr->test.data_size_out; + err = -ENOSPC; + } - if (data_out && copy_to_user(data_out, data, size)) + if (data_out && copy_to_user(data_out, data, copy_size)) goto out; if (copy_to_user(&uattr->test.data_size_out, &size, sizeof(size))) goto out; @@ -83,7 +93,8 @@ static int bpf_test_finish(const union bpf_attr *kattr, goto out; if (copy_to_user(&uattr->test.duration, &duration, sizeof(duration))) goto out; - err = 0; + if (err != -ENOSPC) + err = 0; out: return err; } |