Skip to content

Commit 58291a7

Browse files
l0koddavem330
authored andcommitted
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 <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: David S. Miller <[email protected]> Cc: Kees Cook <[email protected]> Cc: Martin KaFai Lau <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7b83f52 commit 58291a7

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

kernel/bpf/syscall.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,32 @@ static const struct bpf_map_ops * const bpf_map_types[] = {
4848
#undef BPF_MAP_TYPE
4949
};
5050

51+
static int check_uarg_tail_zero(void __user *uaddr,
52+
size_t expected_size,
53+
size_t actual_size)
54+
{
55+
unsigned char __user *addr;
56+
unsigned char __user *end;
57+
unsigned char val;
58+
int err;
59+
60+
if (actual_size <= expected_size)
61+
return 0;
62+
63+
addr = uaddr + expected_size;
64+
end = uaddr + actual_size;
65+
66+
for (; addr < end; addr++) {
67+
err = get_user(val, addr);
68+
if (err)
69+
return err;
70+
if (val)
71+
return -E2BIG;
72+
}
73+
74+
return 0;
75+
}
76+
5177
static struct bpf_map *find_and_alloc_map(union bpf_attr *attr)
5278
{
5379
struct bpf_map *map;
@@ -1246,32 +1272,6 @@ static int bpf_map_get_fd_by_id(const union bpf_attr *attr)
12461272
return fd;
12471273
}
12481274

1249-
static int check_uarg_tail_zero(void __user *uaddr,
1250-
size_t expected_size,
1251-
size_t actual_size)
1252-
{
1253-
unsigned char __user *addr;
1254-
unsigned char __user *end;
1255-
unsigned char val;
1256-
int err;
1257-
1258-
if (actual_size <= expected_size)
1259-
return 0;
1260-
1261-
addr = uaddr + expected_size;
1262-
end = uaddr + actual_size;
1263-
1264-
for (; addr < end; addr++) {
1265-
err = get_user(val, addr);
1266-
if (err)
1267-
return err;
1268-
if (val)
1269-
return -E2BIG;
1270-
}
1271-
1272-
return 0;
1273-
}
1274-
12751275
static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
12761276
const union bpf_attr *attr,
12771277
union bpf_attr __user *uattr)

0 commit comments

Comments
 (0)