Skip to content

Commit b7e4b65

Browse files
author
Al Viro
committed
bpf: make bpf_check_uarg_tail_zero() use check_zeroed_user()
... rather than open-coding it, and badly, at that. Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 9eb41c5 commit b7e4b65

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

kernel/bpf/syscall.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,32 +67,19 @@ int bpf_check_uarg_tail_zero(void __user *uaddr,
6767
size_t expected_size,
6868
size_t actual_size)
6969
{
70-
unsigned char __user *addr;
71-
unsigned char __user *end;
72-
unsigned char val;
73-
int err;
70+
unsigned char __user *addr = uaddr + expected_size;
71+
int res;
7472

7573
if (unlikely(actual_size > PAGE_SIZE)) /* silly large */
7674
return -E2BIG;
7775

78-
if (unlikely(!access_ok(uaddr, actual_size)))
79-
return -EFAULT;
80-
8176
if (actual_size <= expected_size)
8277
return 0;
8378

84-
addr = uaddr + expected_size;
85-
end = uaddr + actual_size;
86-
87-
for (; addr < end; addr++) {
88-
err = get_user(val, addr);
89-
if (err)
90-
return err;
91-
if (val)
92-
return -E2BIG;
93-
}
94-
95-
return 0;
79+
res = check_zeroed_user(addr, actual_size - expected_size);
80+
if (res < 0)
81+
return res;
82+
return res ? 0 : -E2BIG;
9683
}
9784

9885
const struct bpf_map_ops bpf_map_offload_ops = {

0 commit comments

Comments
 (0)