Thread (6 messages) 6 messages, 2 authors, 2021-05-05

Re: [PATCH v2 bpf-next] libbpf: Fix signed overflow in ringbuf_process_ring

From: Andrii Nakryiko <hidden>
Date: 2021-05-05 00:37:46
Also in: lkml

On Tue, May 4, 2021 at 2:01 AM Brendan Jackman [off-list ref] wrote:
quoted hunk ↗ jump to hunk
On Mon, 3 May 2021 at 19:46, Andrii Nakryiko [off-list ref] wrote:
quoted
On Mon, May 3, 2021 at 5:01 AM Brendan Jackman [off-list ref] wrote:
quoted
On Fri, 30 Apr 2021 at 18:31, Andrii Nakryiko [off-list ref] wrote:
quoted
So while doing that I noticed that you didn't fix ring_buffer__poll(),
so I had to fix it up a bit more extensively. Please check the end
result in bpf tree and let me know if there are any problems with it:

2a30f9440640 ("libbpf: Fix signed overflow in ringbuf_process_ring")
Ah, thanks for that. Yep, the additional fix looks good to me.

I think it actually fixes another very niche issue:

 int ring_buffer__poll(struct ring_buffer *rb, int timeout_ms)
 {
-       int i, cnt, err, res = 0;
+       int i, cnt;
+       int64_t err, res = 0;

        cnt = epoll_wait(rb->epoll_fd, rb->events, rb->ring_cnt, timeout_ms);
+       if (cnt < 0)
+               return -errno;
+
        for (i = 0; i < cnt; i++) {
                __u32 ring_id = rb->events[i].data.fd;
                struct ring *ring = &rb->rings[ring_id];
@@ -280,7 +290,9 @@ int ring_buffer__poll(struct ring_buffer *rb, int
timeout_ms)
                        return err;
                res += err;
        }
-       return cnt < 0 ? -errno : res;

If the callback returns an error but errno is 0 this fails to report the error.
Yeah, there was no need to be clever about that. Explicit if (cnt < 0)
check is obvious and correct.
errno(3) says "the value of errno is never set to zero by any system
call or library function" but then describes a scenario where an
application might usefully set it to zero itself. Maybe it can also be
0 in new threads, depending on your metaphysical interpretation of "by
a system call or library function".

+       if (res > INT_MAX)
+               return INT_MAX;
+       return res;
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help