aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/syscall.c
diff options
context:
space:
mode:
authorMickaël Salaün <mic@digikod.net>2017-08-07 14:45:19 -0400
committerDavid S. Miller <davem@davemloft.net>2017-08-08 21:11:17 -0400
commit58291a7465f6b88248c9f34807c16705bd5698f8 (patch)
tree2dc746ed8009ea1033d853839ca2d51649f84adb /kernel/bpf/syscall.c
parent7b83f52047e8a3d551a9495b0267df5d0754c5bf (diff)
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>
Diffstat (limited to 'kernel/bpf/syscall.c')
-rw-r--r--kernel/bpf/syscall.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 6c772adabad2..c653ee0bd162 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -48,6 +48,32 @@ static const struct bpf_map_ops * const bpf_map_types[] = {
48#undef BPF_MAP_TYPE 48#undef BPF_MAP_TYPE
49}; 49};
50 50
51static 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
51static struct bpf_map *find_and_alloc_map(union bpf_attr *attr) 77static struct bpf_map *find_and_alloc_map(union bpf_attr *attr)
52{ 78{
53 struct bpf_map *map; 79 struct bpf_map *map;
@@ -1246,32 +1272,6 @@ static int bpf_map_get_fd_by_id(const union bpf_attr *attr)
1246 return fd; 1272 return fd;
1247} 1273}
1248 1274
1249static 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
1275static int bpf_prog_get_info_by_fd(struct bpf_prog *prog, 1275static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
1276 const union bpf_attr *attr, 1276 const union bpf_attr *attr,
1277 union bpf_attr __user *uattr) 1277 union bpf_attr __user *uattr)