From: Jakub Kicinski Date: Tue, 29 Nov 2022 21:04:52 +0000 (-0800) Subject: Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net X-Git-Tag: v6.6.17~5932^2~113 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f2bb566f5c977ff010baaa9e5e14d9a75b06e5f2;p=platform%2Fkernel%2Flinux-rpi.git Merge git://git./linux/kernel/git/netdev/net tools/lib/bpf/ringbuf.c 927cbb478adf ("libbpf: Handle size overflow for ringbuf mmap") b486d19a0ab0 ("libbpf: checkpatch: Fixed code alignments in ringbuf.c") https://lore.kernel.org/all/20221121122707.44d1446a@canb.auug.org.au/ Signed-off-by: Jakub Kicinski --- f2bb566f5c977ff010baaa9e5e14d9a75b06e5f2 diff --cc tools/lib/bpf/ringbuf.c index 51808c5,6af1429..47855af --- a/tools/lib/bpf/ringbuf.c +++ b/tools/lib/bpf/ringbuf.c @@@ -128,9 -128,13 +128,13 @@@ int ring_buffer__add(struct ring_buffe /* Map read-only producer page and data pages. We map twice as big * data size to allow simple reading of samples that wrap around the * end of a ring buffer. See kernel implementation for details. - * */ + */ - tmp = mmap(NULL, rb->page_size + 2 * info.max_entries, PROT_READ, - MAP_SHARED, map_fd, rb->page_size); + mmap_sz = rb->page_size + 2 * (__u64)info.max_entries; + if (mmap_sz != (__u64)(size_t)mmap_sz) { + pr_warn("ringbuf: ring buffer size (%u) is too big\n", info.max_entries); + return libbpf_err(-E2BIG); + } + tmp = mmap(NULL, (size_t)mmap_sz, PROT_READ, MAP_SHARED, map_fd, rb->page_size); if (tmp == MAP_FAILED) { err = -errno; ringbuf_unmap_ring(rb, r);