Skip to content

Commit 35a97b9

Browse files
Alexei SafinKernel Patches Daemon
authored andcommitted
bpf: hashtab: fix 32-bit overflow in memory usage calculation
The intermediate product value_size * num_possible_cpus() is evaluated in 32-bit arithmetic and only then promoted to 64 bits. On systems with large value_size and many possible CPUs this can overflow and lead to an underestimated memory usage. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 304849a ("bpf: hashtab memory usage") Cc: stable@vger.kernel.org Suggested-by: Yafang Shao <laoar.shao@gmail.com> Signed-off-by: Alexei Safin <a.safin@rosa.ru>
1 parent b6555d5 commit 35a97b9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/bpf/hashtab.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2199,7 +2199,7 @@ static long bpf_for_each_hash_elem(struct bpf_map *map, bpf_callback_t callback_
21992199
static u64 htab_map_mem_usage(const struct bpf_map *map)
22002200
{
22012201
struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
2202-
u32 value_size = round_up(htab->map.value_size, 8);
2202+
u64 value_size = round_up(htab->map.value_size, 8);
22032203
bool prealloc = htab_is_prealloc(htab);
22042204
bool percpu = htab_is_percpu(htab);
22052205
bool lru = htab_is_lru(htab);

0 commit comments

Comments
 (0)