Skip to content

Commit b450431

Browse files
ytcoodeborkmann
authored andcommitted
bpf: Fix excessive memory allocation in stack_map_alloc()
The 'n_buckets * (value_size + sizeof(struct stack_map_bucket))' part of the allocated memory for 'smap' is never used after the memlock accounting was removed, thus get rid of it. [ Note, Daniel: Commit b936ca6 ("bpf: rework memlock-based memory accounting for maps") moved `cost += n_buckets * (value_size + sizeof(struct stack_map_bucket))` up and therefore before the bpf_map_area_alloc() allocation, sigh. In a later step commit c85d691 ("bpf: move memory size checks to bpf_map_charge_init()"), and the overflow checks of `cost >= U32_MAX - PAGE_SIZE` moved into bpf_map_charge_init(). And then 3708681 ("bpf: Eliminate rlimit-based memory accounting for stackmap maps") finally removed the bpf_map_charge_init(). Anyway, the original code did the allocation same way as /after/ this fix. ] Fixes: b936ca6 ("bpf: rework memlock-based memory accounting for maps") Signed-off-by: Yuntao Wang <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 658d876 commit b450431

File tree

1 file changed

+0
-1
lines changed

1 file changed

+0
-1
lines changed

kernel/bpf/stackmap.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ static struct bpf_map *stack_map_alloc(union bpf_attr *attr)
100100
return ERR_PTR(-E2BIG);
101101

102102
cost = n_buckets * sizeof(struct stack_map_bucket *) + sizeof(*smap);
103-
cost += n_buckets * (value_size + sizeof(struct stack_map_bucket));
104103
smap = bpf_map_area_alloc(cost, bpf_map_attr_numa_node(attr));
105104
if (!smap)
106105
return ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)