Commit 87e9cd3b authored by Daniel Borkmann's avatar Daniel Borkmann Committed by Kleber Sacilotto de Souza

bpf: fix map not being uncharged during map creation failure

BugLink: https://bugs.launchpad.net/bugs/1878232

commit 20b2b24f upstream.

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: aaac3ba9 ("bpf: charge user for creation of BPF maps and programs")
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarIan May <ian.may@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 7287564d
...@@ -152,7 +152,7 @@ static int map_create(union bpf_attr *attr) ...@@ -152,7 +152,7 @@ static int map_create(union bpf_attr *attr)
err = bpf_map_charge_memlock(map); err = bpf_map_charge_memlock(map);
if (err) if (err)
goto free_map; goto free_map_nouncharge;
err = bpf_map_new_fd(map); err = bpf_map_new_fd(map);
if (err < 0) if (err < 0)
...@@ -162,6 +162,8 @@ static int map_create(union bpf_attr *attr) ...@@ -162,6 +162,8 @@ static int map_create(union bpf_attr *attr)
return err; return err;
free_map: free_map:
bpf_map_uncharge_memlock(map);
free_map_nouncharge:
map->ops->map_free(map); map->ops->map_free(map);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment