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: eba9c5f498 ("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
This commit is contained in:
Andrii Nakryiko 2020-01-16 22:08:00 -08:00 committed by Alexei Starovoitov
parent b7d7f3e185
commit c701917e64
1 changed files with 1 additions and 1 deletions

View File

@ -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;
}