Skip to content

Commit

Permalink
bpf: fix map not being uncharged during map creation failure
Browse files Browse the repository at this point in the history
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: aaac3ba ("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>
  • Loading branch information
Daniel Borkmann authored and David S. Miller committed Nov 7, 2016
1 parent 483bed2 commit 20b2b24
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kernel/bpf/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static int map_create(union bpf_attr *attr)

err = bpf_map_charge_memlock(map);
if (err)
goto free_map;
goto free_map_nouncharge;

err = bpf_map_new_fd(map);
if (err < 0)
Expand All @@ -204,6 +204,8 @@ static int map_create(union bpf_attr *attr)
return err;

free_map:
bpf_map_uncharge_memlock(map);
free_map_nouncharge:
map->ops->map_free(map);
return err;
}
Expand Down

0 comments on commit 20b2b24

Please sign in to comment.