bpf: Move check_uarg_tail_zero() upward
The function check_uarg_tail_zero() may be useful for other part of the code in the syscall.c file. Move this function at the beginning of the file. Signed-off-by: Mickaël Salaün <mic@digikod.net> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Cc: Alexei Starovoitov <ast@kernel.org> Cc: David S. Miller <davem@davemloft.net> Cc: Kees Cook <keescook@chromium.org> Cc: Martin KaFai Lau <kafai@fb.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
7b83f52047
commit
58291a7465
|
@ -48,6 +48,32 @@ static const struct bpf_map_ops * const bpf_map_types[] = {
|
||||||
#undef BPF_MAP_TYPE
|
#undef BPF_MAP_TYPE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int 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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
static struct bpf_map *find_and_alloc_map(union bpf_attr *attr)
|
static struct bpf_map *find_and_alloc_map(union bpf_attr *attr)
|
||||||
{
|
{
|
||||||
struct bpf_map *map;
|
struct bpf_map *map;
|
||||||
|
@ -1246,32 +1272,6 @@ static int bpf_map_get_fd_by_id(const union bpf_attr *attr)
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int 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;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
|
static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
|
||||||
const union bpf_attr *attr,
|
const union bpf_attr *attr,
|
||||||
union bpf_attr __user *uattr)
|
union bpf_attr __user *uattr)
|
||||||
|
|
Loading…
Reference in New Issue