]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
libbpf: Handle size overflow for ringbuf mmap
authorHou Tao <houtao1@huawei.com>
Wed, 16 Nov 2022 07:23:49 +0000 (15:23 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 8 Dec 2022 10:23:54 +0000 (11:23 +0100)
commit8a549ab6724520aa3c07f47e0eba820293551490
treeac372e341e884a9ac37ee7f03e97e6e99c9daff7
parentcc140c729c6832eef8eed07cf09b0aa634857603
libbpf: Handle size overflow for ringbuf mmap

[ Upstream commit 927cbb478adf917e0a142b94baa37f06279cc466 ]

The maximum size of ringbuf is 2GB on x86-64 host, so 2 * max_entries
will overflow u32 when mapping producer page and data pages. Only
casting max_entries to size_t is not enough, because for 32-bits
application on 64-bits kernel the size of read-only mmap region
also could overflow size_t.

So fixing it by casting the size of read-only mmap region into a __u64
and checking whether or not there will be overflow during mmap.

Fixes: bf99c936f947 ("libbpf: Add BPF ring buffer support")
Signed-off-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20221116072351.1168938-3-houtao@huaweicloud.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/lib/bpf/ringbuf.c