libbpf: Handle size overflow for user ringbuf mmap
authorHou Tao <houtao1@huawei.com>
Wed, 16 Nov 2022 07:23:50 +0000 (15:23 +0800)
committerAndrii Nakryiko <andrii@kernel.org>
Thu, 17 Nov 2022 23:49:39 +0000 (15:49 -0800)
commit64176bff2446cd825b163976ee451fb6e5cd851d
treece7ea47216f9fb50875065ea9e850d5e1f6975b9
parent927cbb478adf917e0a142b94baa37f06279cc466
libbpf: Handle size overflow for user ringbuf mmap

Similar with the overflow problem on ringbuf mmap, in user_ringbuf_map()
2 * max_entries may overflow u32 when mapping writeable region.

Fixing it by casting the size of writable mmap region into a __u64 and
checking whether or not there will be overflow during mmap.

Fixes: b66ccae01f1d ("bpf: Add libbpf logic for user-space ring buffer")
Signed-off-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20221116072351.1168938-4-houtao@huaweicloud.com
tools/lib/bpf/ringbuf.c