Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp3445926pxy; Tue, 4 May 2021 02:19:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIOJFiyUGUqAIwZ6bBe4r0H09dYG9K9g82q0rKzMdUkcmPJFf1D5KNEHLH26l8IhLuztwQ X-Received: by 2002:a17:90a:690b:: with SMTP id r11mr26571783pjj.140.1620119998332; Tue, 04 May 2021 02:19:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620119998; cv=none; d=google.com; s=arc-20160816; b=e7Outb/wfwL3KZgNyP8HfIxH3CD5yI1y+lsypS4DWcsHVyqpxHeinJZ3XblAc7H9jP CY6nB3gLqitFFsGM4iw0vxuauGvajQqLRk8DyNhSPWZGrgvnUEiARry7aYgv7bSd1cvV S4e/bfdPymRRvTag0lZr4JlbQvdaGixy1XY89iS64ORCGaexANTCY9t7n0YLxQnfm5QZ SjgOFw3ZwkSTNKyKg8kB343XtG+FDKrzSFsuCthLg44e3YjJbtL0tC6WwcV1c7lgL33D yfwKwHq/SDzXqrIy1mN3sciawTol5jwCK8T8qTXBVbZqzgfCogA+McwarN+S6zgYegnl PFmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=/BEtiHEyLUH0pHUzx4+zlxAJRANLxFJIE2T50Nx0vuQ=; b=cEFWI8Mz1SsvdtnI58pqGtUJUebVaMS9qxCdS0bobwN0izICdUmG8RP9Q7xQ99OUAv UgKK/SriQ+gFrgbRMlttqHisC2ZAICVokxtoB2LVHBMIFk5l7i4IWFgBOtJQYknAQSoS K360h8N86i/XWQSte1cfARF4brx2MolBpkeRl/E4H+fQO47WT9Am/DMDBVxLld6e93Nq /9e1lhnTrXn4iK2A6JPQulZunAfuz4qIn46wnWuwMBS3sNWfSlKwLNEXOZddGnvot7zZ Tj4VmzyvBb6doI++8m6amUlOERVLYrB6iNUcfNk0PInndUvVRcSxT0npxxDVHEdBmp2T FCxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eEhoA9Og; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g36si2312997pgb.208.2021.05.04.02.19.45; Tue, 04 May 2021 02:19:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eEhoA9Og; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229703AbhEDJCm (ORCPT + 99 others); Tue, 4 May 2021 05:02:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229814AbhEDJCk (ORCPT ); Tue, 4 May 2021 05:02:40 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2266CC06174A for ; Tue, 4 May 2021 02:01:46 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id f24so11995874ejc.6 for ; Tue, 04 May 2021 02:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/BEtiHEyLUH0pHUzx4+zlxAJRANLxFJIE2T50Nx0vuQ=; b=eEhoA9OgAL3QwPqmzGoQ5J/vgDLmh59eBzeVStjZNQFW1WVZ7zmwHYS4bHjqXROkTJ oz9wR9HvE5nssKpODv77U8N+v1YdmKuEaYFNpob0ThWN/GzKV0lGeB4Q6e52PnxfV4k2 Utlh6DJhVA+lhxwTqFyi88TlVxIIfwnm/io1tuMqEFrzApTRouEvUi1tJZ+CJZoXmEIR SUh43X7p+a1UL5HScIFnrFISbnOvhM1nvBXBcHv/pNgv1t84V0N5MuRleVz4X98zWEHE /E+vfo6TZ2AVLoLOIreuY5fkfEm/6FMoskfOlT/YIL/fXNZg0Nh0uu7KWEe7Vt0Svbg6 C45w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/BEtiHEyLUH0pHUzx4+zlxAJRANLxFJIE2T50Nx0vuQ=; b=RWvmx8wF2fQQbp45usfIDd9I6W1jsR5WMNK9c5/ptKUeg4Yr+VMP0aBnUGmeQYGFRr duIfiewE4LBNvi7w+kO3dEfNJGLqfs65zpFlqq9cyc7A0rb5B7UnQcGBDV1opTTZnmcQ snexphjhV7ig7bLAkqymaTDhGQiPKR0ufqj1YD3AjET9PPfPR/fu+8uhc0GQKgcEedRI rtzrgNUyx4LQ8oKpD+PTARjjYI+NdVJLxIVs3zrSx0xKnYaxgmmsrC3iwwuGv/KCOGrc XDC+7GRzUcwBHZ8xnhEO3F1vzrkLHn0HvKwfWMhH7SsQ+CCwpjtvIE2b0E9ei2Z8gVte scDA== X-Gm-Message-State: AOAM530P6BYLA3pwUCjIQIh5vD12F4mwwl5nD0O/4EqHgdoh55xXIKtZ abP7+AQvuErdcPKwKk7EFRDd//NEFPBaaRgL6lMAhA== X-Received: by 2002:a17:906:2559:: with SMTP id j25mr20412002ejb.42.1620118904443; Tue, 04 May 2021 02:01:44 -0700 (PDT) MIME-Version: 1.0 References: <20210429130510.1621665-1-jackmanb@google.com> In-Reply-To: From: Brendan Jackman Date: Tue, 4 May 2021 11:01:33 +0200 Message-ID: Subject: Re: [PATCH v2 bpf-next] libbpf: Fix signed overflow in ringbuf_process_ring To: Andrii Nakryiko Cc: bpf , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , open list , KP Singh , Florent Revest Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 3 May 2021 at 19:46, Andrii Nakryiko wrote: > > On Mon, May 3, 2021 at 5:01 AM Brendan Jackman wrote: > > > > On Fri, 30 Apr 2021 at 18:31, Andrii Nakryiko wrote: > 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. 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;