libbpf: fix potential overflow in ring__consume_n()
Andrii Nakryiko
maintainerPATCH 1/2 libbpf: fix potential overflow in ring__consume_n()
ringbuf_process_ring() return int64_t, while ring__consume_n() assigns it to int. It's highly unlikely, but possible for ringbuf_process_ring() to return value larger than INT_MAX, so use int64_t. ring__consume_n() does check INT_MAX before returning int result to the user.
--- tools/lib/bpf/ringbuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/ringbuf.c +1 -1
@@ -405,7 +405,7 @@ int ring__map_fd(const struct ring *r)int ring__consume_n (struct ring *r,size_t n) { -int res; +int64_t res; res =ringbuf_process_ring (r, n);if (res <0 )
Signature · 1 line
2.43.0
Andrii Nakryiko
maintainerPATCH 2/2 libbpf: fix ring_buffer__consume_n() return result logic
Add INT_MAX check to ring_buffer__consume_n(). We do the similar check to handle int return result of all these ring buffer APIs in other APIs and ring_buffer__consume_n() is missing one. This patch fixes this omission.
--- tools/lib/bpf/ringbuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/ringbuf.c +1 -1
@@ -301,7 +301,7 @@ int ring_buffer__consume_n(struct ring_buffer *rb, size_t n)if (n ==0 )break ; } -return res; +return res >INT_MAX ?INT_MAX : res; }/* Consume available ring buffer(s) data without event polling.
Signature · 1 line
2.43.0
Re: [PATCH bpf-next 2/2] libbpf: fix ring_buffer__consume_n() return result logic
Quoted 8 lines · Andrii Nakryiko
Add
INT_MAXcheck toring_buffer__consume_n(). We do the similar check to handle int return result of all these ring buffer APIs in other APIs andring_buffer__consume_n()is missing one. This patch fixes this omission.Signed-off-by Andrii Nakryiko <[email protected]>---
Quoted 9 lines · Andrii Nakryiko
ringbuf_process_ring()returnint64_t, whilering__consume_n()assigns it to int. It's highly unlikely, but possible forringbuf_process_ring()to return value larger thanINT_MAX, so useint64_t.ring__consume_n()does checkINT_MAXbefore returning int result to the user.Fixes 4d22ea94ea33 ("libbpf: Add ring__consume_n / ring_buffer__consume_n")Signed-off-by Andrii Nakryiko <[email protected]>---
This series was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:
Quoted 9 lines · On Tue, 30 Apr 2024 13:19:51 -0700 you wrote:
ringbuf_process_ring()returnint64_t, whilering__consume_n()assigns it to int. It's highly unlikely, but possible forringbuf_process_ring()to return value larger thanINT_MAX, so useint64_t.ring__consume_n()does checkINT_MAXbefore returning int result to the user.Fixes 4d22ea94ea33 ("libbpf: Add ring__consume_n / ring_buffer__consume_n")Signed-off-by Andrii Nakryiko <[email protected]>[...]
Here is the summary with links:
- [bpf-next,1/2] libbpf: fix potential overflow in ring__consume_n()
https://git.kernel.org/bpf/bpf-next/c/00f0e08f23fc - [bpf-next,2/2] libbpf: fix ring_buffer__consume_n() return result logic https://git.kernel.org/bpf/bpf-next/c/087d757fb473
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html