]> git.baikalelectronics.ru Git - kernel.git/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)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 3 May 2021 16:54:12 +0000 (09:54 -0700)
commit9b690d5e44e2c791f110b5de6882e297deea2be4
treec49a61cb379ced5ebd365645b999382e1399779a
parent52336fa0dc06fbdc7105ed51c9b80badd9d1a574
libbpf: Fix signed overflow in ringbuf_process_ring

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: 56ad61d8aa95 (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
tools/lib/bpf/ringbuf.c