]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
bpf: Fix excessive memory allocation in stack_map_alloc()
authorYuntao Wang <ytcoode@gmail.com>
Thu, 7 Apr 2022 13:04:23 +0000 (21:04 +0800)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 10 Aug 2022 07:23:27 +0000 (09:23 +0200)
commit2b250b0cc662c759bc0b95aea82545e14980b566
tree721b1d3f93ce9be81fa2935dca2cf507b8350517
parent45110e5ab719d4238f8a89bceb1dc66dc76415b2
bpf: Fix excessive memory allocation in stack_map_alloc()

BugLink: https://bugs.launchpad.net/bugs/1981862
commit b45043192b3e481304062938a6561da2ceea46a6 upstream.

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 b936ca643ade ("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 c85d69135a91 ("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 370868107bf6 ("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: b936ca643ade ("bpf: rework memlock-based memory accounting for maps")
Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220407130423.798386-1-ytcoode@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
kernel/bpf/stackmap.c