]> git.hungrycats.org Git - linux/commit
libbpf: Fix signed overflow in ringbuf_process_ring
authorBrendan Jackman <jackmanb@google.com>
Thu, 29 Apr 2021 13:05:10 +0000 (13:05 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 May 2021 08:29:44 +0000 (10:29 +0200)
commit7b8ea4953a3fd4eb690a1c0272015ade3e2cefc3
tree8eabe8c345ffedd6a9c6776f09aaa5c384a2596b
parenta521954cc34f2df86d2e0fa8a553b25dff6736a4
libbpf: Fix signed overflow in ringbuf_process_ring

[ Upstream commit 2a30f9440640c418bcfbea9b2b344d268b58e0a2 ]

One of our benchmarks running in (Google-internal) CI pushes data
through the ringbuf faster htan than userspace is able to consume
it. In this case it seems we're actually able to get >INT_MAX entries
in a single ring_buffer__consume() call. ASAN detected that cnt
overflows in this case.

Fix by using 64-bit counter internally and then capping the result to
INT_MAX before converting to the int return type. Do the same for
the ring_buffer__poll().

Fixes: bf99c936f947 (libbpf: Add BPF ring buffer support)
Signed-off-by: Brendan Jackman <jackmanb@google.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210429130510.1621665-1-jackmanb@google.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/lib/bpf/ringbuf.c