diff options
author | Lorenz Bauer <lmb@cloudflare.com> | 2018-12-03 06:31:23 -0500 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2018-12-04 11:18:13 -0500 |
commit | b5a36b1e1b138285ea0df34bf96c759e1e30fafd (patch) | |
tree | 979d2a28beaa2dcb3bba77964e7e44630694e8eb /net/bpf | |
parent | d59dd69d5576d699d7d3f5da0b4738c3a36d0133 (diff) |
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')
-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, | |||
74 | { | 74 | { |
75 | void __user *data_out = u64_to_user_ptr(kattr->test.data_out); | 75 | void __user *data_out = u64_to_user_ptr(kattr->test.data_out); |
76 | int err = -EFAULT; | 76 | int err = -EFAULT; |
77 | u32 copy_size = size; | ||
78 | |||
79 | /* Clamp copy if the user has provided a size hint, but copy the full | ||
80 | * buffer if not to retain old behaviour. | ||
81 | */ | ||
82 | if (kattr->test.data_size_out && | ||
83 | copy_size > kattr->test.data_size_out) { | ||
84 | copy_size = kattr->test.data_size_out; | ||
85 | err = -ENOSPC; | ||
86 | } | ||
77 | 87 | ||
78 | if (data_out && copy_to_user(data_out, data, size)) | 88 | if (data_out && copy_to_user(data_out, data, copy_size)) |
79 | goto out; | 89 | goto out; |
80 | if (copy_to_user(&uattr->test.data_size_out, &size, sizeof(size))) | 90 | if (copy_to_user(&uattr->test.data_size_out, &size, sizeof(size))) |
81 | goto out; | 91 | goto out; |
@@ -83,7 +93,8 @@ static int bpf_test_finish(const union bpf_attr *kattr, | |||
83 | goto out; | 93 | goto out; |
84 | if (copy_to_user(&uattr->test.duration, &duration, sizeof(duration))) | 94 | if (copy_to_user(&uattr->test.duration, &duration, sizeof(duration))) |
85 | goto out; | 95 | goto out; |
86 | err = 0; | 96 | if (err != -ENOSPC) |
97 | err = 0; | ||
87 | out: | 98 | out: |
88 | return err; | 99 | return err; |
89 | } | 100 | } |