diff options
author | Daniel Borkmann <daniel@iogearbox.net> | 2016-11-03 19:56:31 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-11-07 13:22:26 -0500 |
commit | 20b2b24f91f70e7d3f0918c077546cb21bd73a87 (patch) | |
tree | ecdffd693fa3fd2d368def47c1ea510330119265 /kernel/bpf/syscall.c | |
parent | 483bed2b0ddd12ec33fc9407e0c6e1088e77a97c (diff) |
bpf: fix map not being uncharged during map creation failure
In map_create(), we first find and create the map, then once that
suceeded, we charge it to the user's RLIMIT_MEMLOCK, and then fetch
a new anon fd through anon_inode_getfd(). The problem is, once the
latter fails f.e. due to RLIMIT_NOFILE limit, then we only destruct
the map via map->ops->map_free(), but without uncharging the previously
locked memory first. That means that the user_struct allocation is
leaked as well as the accounted RLIMIT_MEMLOCK memory not released.
Make the label names in the fix consistent with bpf_prog_load().
Fixes: aaac3ba95e4c ("bpf: charge user for creation of BPF maps and programs")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'kernel/bpf/syscall.c')
-rw-r--r-- | kernel/bpf/syscall.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 228f962447a5..237f3d6a7ddc 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c | |||
@@ -194,7 +194,7 @@ static int map_create(union bpf_attr *attr) | |||
194 | 194 | ||
195 | err = bpf_map_charge_memlock(map); | 195 | err = bpf_map_charge_memlock(map); |
196 | if (err) | 196 | if (err) |
197 | goto free_map; | 197 | goto free_map_nouncharge; |
198 | 198 | ||
199 | err = bpf_map_new_fd(map); | 199 | err = bpf_map_new_fd(map); |
200 | if (err < 0) | 200 | if (err < 0) |
@@ -204,6 +204,8 @@ static int map_create(union bpf_attr *attr) | |||
204 | return err; | 204 | return err; |
205 | 205 | ||
206 | free_map: | 206 | free_map: |
207 | bpf_map_uncharge_memlock(map); | ||
208 | free_map_nouncharge: | ||
207 | map->ops->map_free(map); | 209 | map->ops->map_free(map); |
208 | return err; | 210 | return err; |
209 | } | 211 | } |