Skip to content

Commit 20b2b24

Browse files
borkmanndavem330
authored andcommitted
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: aaac3ba ("bpf: charge user for creation of BPF maps and programs") Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 483bed2 commit 20b2b24

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernel/bpf/syscall.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static int map_create(union bpf_attr *attr)
194194

195195
err = bpf_map_charge_memlock(map);
196196
if (err)
197-
goto free_map;
197+
goto free_map_nouncharge;
198198

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

206206
free_map:
207+
bpf_map_uncharge_memlock(map);
208+
free_map_nouncharge:
207209
map->ops->map_free(map);
208210
return err;
209211
}

0 commit comments

Comments
 (0)