Skip to content

Commit 78e5227

Browse files
committed
bpf: Do not dereference user pointer in bpf_test_finish().
Instead, pass the kattr in which has a kernel side copy of this data structure from userspace already. Fix based upon a suggestion from Alexei Starovoitov. Signed-off-by: David S. Miller <[email protected]> Acked-by: Daniel Borkmann <[email protected]>
1 parent 4e9c3a6 commit 78e5227

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

net/bpf/test_run.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ static u32 bpf_test_run(struct bpf_prog *prog, void *ctx, u32 repeat, u32 *time)
4949
return ret;
5050
}
5151

52-
static int bpf_test_finish(union bpf_attr __user *uattr, const void *data,
52+
static int bpf_test_finish(const union bpf_attr *kattr,
53+
union bpf_attr __user *uattr, const void *data,
5354
u32 size, u32 retval, u32 duration)
5455
{
55-
void __user *data_out = u64_to_user_ptr(uattr->test.data_out);
56+
void __user *data_out = u64_to_user_ptr(kattr->test.data_out);
5657
int err = -EFAULT;
5758

5859
if (data_out && copy_to_user(data_out, data, size))
@@ -140,7 +141,7 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
140141
/* bpf program can never convert linear skb to non-linear */
141142
if (WARN_ON_ONCE(skb_is_nonlinear(skb)))
142143
size = skb_headlen(skb);
143-
ret = bpf_test_finish(uattr, skb->data, size, retval, duration);
144+
ret = bpf_test_finish(kattr, uattr, skb->data, size, retval, duration);
144145
kfree_skb(skb);
145146
return ret;
146147
}
@@ -166,7 +167,7 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
166167
retval = bpf_test_run(prog, &xdp, repeat, &duration);
167168
if (xdp.data != data + XDP_PACKET_HEADROOM)
168169
size = xdp.data_end - xdp.data;
169-
ret = bpf_test_finish(uattr, xdp.data, size, retval, duration);
170+
ret = bpf_test_finish(kattr, uattr, xdp.data, size, retval, duration);
170171
kfree(data);
171172
return ret;
172173
}

0 commit comments

Comments
 (0)