From: Andrii Nakryiko Date: Fri, 17 Jan 2020 06:08:00 +0000 (-0800) Subject: libbpf: Fix potential multiplication overflow in mmap() size calculation X-Git-Tag: v5.10.7~3383^2~46^2~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c701917e647c6aaee5e7bbb7a2c1ca99e8552c58;p=platform%2Fkernel%2Flinux-rpi.git libbpf: Fix potential multiplication overflow in mmap() size calculation Prevent potential overflow performed in 32-bit integers, before assigning result to size_t. Reported by LGTM static analysis. Fixes: eba9c5f498a1 ("libbpf: Refactor global data map initialization") Signed-off-by: Andrii Nakryiko Signed-off-by: Alexei Starovoitov Link: https://lore.kernel.org/bpf/20200117060801.1311525-4-andriin@fb.com --- diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 3b0b88c..fc41c3f 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1283,7 +1283,7 @@ static size_t bpf_map_mmap_sz(const struct bpf_map *map) long page_sz = sysconf(_SC_PAGE_SIZE); size_t map_sz; - map_sz = roundup(map->def.value_size, 8) * map->def.max_entries; + map_sz = (size_t)roundup(map->def.value_size, 8) * map->def.max_entries; map_sz = roundup(map_sz, page_sz); return map_sz; }