diff options
author | Roman Gushchin <guro@fb.com> | 2019-05-29 21:03:59 -0400 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2019-05-31 19:52:56 -0400 |
commit | c85d69135a9175c50a823d04d62d932312d037b3 (patch) | |
tree | edd6ec707ebbf68a89fc1c3fc2b2d06364978ad3 /kernel/bpf/syscall.c | |
parent | b936ca643ade11f265fa10e5fb71c20d9c5243f1 (diff) |
bpf: move memory size checks to bpf_map_charge_init()
Most bpf map types doing similar checks and bytes to pages
conversion during memory allocation and charging.
Let's unify these checks by moving them into bpf_map_charge_init().
Signed-off-by: Roman Gushchin <guro@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel/bpf/syscall.c')
-rw-r--r-- | kernel/bpf/syscall.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 4a5ebad99154..4c53cbd3329d 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c | |||
@@ -205,11 +205,16 @@ static void bpf_uncharge_memlock(struct user_struct *user, u32 pages) | |||
205 | atomic_long_sub(pages, &user->locked_vm); | 205 | atomic_long_sub(pages, &user->locked_vm); |
206 | } | 206 | } |
207 | 207 | ||
208 | int bpf_map_charge_init(struct bpf_map_memory *mem, u32 pages) | 208 | int bpf_map_charge_init(struct bpf_map_memory *mem, size_t size) |
209 | { | 209 | { |
210 | struct user_struct *user = get_current_user(); | 210 | u32 pages = round_up(size, PAGE_SIZE) >> PAGE_SHIFT; |
211 | struct user_struct *user; | ||
211 | int ret; | 212 | int ret; |
212 | 213 | ||
214 | if (size >= U32_MAX - PAGE_SIZE) | ||
215 | return -E2BIG; | ||
216 | |||
217 | user = get_current_user(); | ||
213 | ret = bpf_charge_memlock(user, pages); | 218 | ret = bpf_charge_memlock(user, pages); |
214 | if (ret) { | 219 | if (ret) { |
215 | free_uid(user); | 220 | free_uid(user); |