]> git.baikalelectronics.ru Git - kernel.git/commitdiff
bpf: make bpf_check_uarg_tail_zero() use check_zeroed_user()
authorAl Viro <viro@zeniv.linux.org.uk>
Fri, 8 May 2020 04:16:31 +0000 (00:16 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Wed, 3 Jun 2020 20:59:45 +0000 (16:59 -0400)
... rather than open-coding it, and badly, at that.

Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
kernel/bpf/syscall.c

index 64783da342020212f12a1a57212b16e330786b5f..41ba746ecbc287c50845783fec48f5490f678abb 100644 (file)
@@ -67,32 +67,19 @@ int bpf_check_uarg_tail_zero(void __user *uaddr,
                             size_t expected_size,
                             size_t actual_size)
 {
-       unsigned char __user *addr;
-       unsigned char __user *end;
-       unsigned char val;
-       int err;
+       unsigned char __user *addr = uaddr + expected_size;
+       int res;
 
        if (unlikely(actual_size > PAGE_SIZE))  /* silly large */
                return -E2BIG;
 
-       if (unlikely(!access_ok(uaddr, actual_size)))
-               return -EFAULT;
-
        if (actual_size <= expected_size)
                return 0;
 
-       addr = uaddr + expected_size;
-       end  = uaddr + actual_size;
-
-       for (; addr < end; addr++) {
-               err = get_user(val, addr);
-               if (err)
-                       return err;
-               if (val)
-                       return -E2BIG;
-       }
-
-       return 0;
+       res = check_zeroed_user(addr, actual_size - expected_size);
+       if (res < 0)
+               return res;
+       return res ? 0 : -E2BIG;
 }
 
 const struct bpf_map_ops bpf_map_offload_ops = {