aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
authorAndrii Nakryiko <andriin@fb.com>2020-01-16 22:08:00 -0800
committerAlexei Starovoitov <ast@kernel.org>2020-01-17 08:33:18 -0800
commitc701917e647c6aaee5e7bbb7a2c1ca99e8552c58 (patch)
treeed0c7062d3151b9b6cfcb9707830726159069f84 /tools/lib
parentlibbpf: Simplify BTF initialization logic (diff)
downloadlinux-dev-c701917e647c6aaee5e7bbb7a2c1ca99e8552c58.tar.xz
linux-dev-c701917e647c6aaee5e7bbb7a2c1ca99e8552c58.zip
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 <andriin@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200117060801.1311525-4-andriin@fb.com
Diffstat (limited to '')
-rw-r--r--tools/lib/bpf/libbpf.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 3b0b88c3377d..fc41c3f2e983 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;
}