Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp25909pxy; Tue, 4 May 2021 17:41:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHzTWsez7s2ct/0Ide8/4DzGbjETZUGr4L/jOlFQ+6t82/4J8UwU2FaWOFZR/r58ZQuQyb X-Received: by 2002:a17:906:4d8d:: with SMTP id s13mr24410369eju.37.1620175301693; Tue, 04 May 2021 17:41:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620175301; cv=none; d=google.com; s=arc-20160816; b=Z7KmkX+PGYNiFQaNyNVPOwREhuA8JKu0CTdsl/mQatGgJ7g+NTshI/UdvgOA2dJtPt r1UR98cchACP35/TKbovRzjWNqA5EWb2Klp0SEABZcEw+hPrcbC6uHCU1jzcmHChN2Pb GL5hf63Uxcp5DYEeQbppgNmG+QqxiXJ/E5JD4nq6a2oRbEAJDNNaFB5KR/MMddpWuAX5 Egr/ih3TF8MolrM6S8tC14js2bVsuusnU5jmboQ6Ag8slEVRY4rPwrIU4eAxKXxdTR63 ibCB3Alh35ov/g6O5iW7hr7KTkmTHxxVVYn67Gkj9BJjnBwxgk3+z+WcpHuHMe9rjIhB sE8Q== 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=qZ6UQO/t/anayyvxHYL8y/BSgNgKydNeCjijU78LDB0=; b=u3tpK2VfFVyxhzY26dh+NOoKuFtNsfAiQcZGbWsJlOQPfCTBwHlz4QbXS+KuxZRnOj LYmdK6zUXwSmDSgZThbNxTYw3IcURqOsVWOBolkMjOjSL8He2B0l2TZ7zIfB7EgTqzcG +5rYOkiGM6cTA2rBYlH8uqY7qvrUc9BshoNfnw8esIrz3B5K27cbCYai7tgcY0JK76qC wp4w/4REj4O0I2zfgOmir6PJJW4me5i3Cemwvj+i78n8CrSW/oMVUYuqL5uiYDGxQW/H 4LqVhHG7mr/DiMS+lm2y2NmE9np+F7WgHxmuvBeEiLy+DLJwm4lxgja4uDcj7XVn01ZJ wUpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hTrd2XUl; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id go43si3544572ejc.620.2021.05.04.17.41.18; Tue, 04 May 2021 17:41:41 -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=@gmail.com header.s=20161025 header.b=hTrd2XUl; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231181AbhEEAik (ORCPT + 99 others); Tue, 4 May 2021 20:38:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230328AbhEEAij (ORCPT ); Tue, 4 May 2021 20:38:39 -0400 Received: from mail-yb1-xb35.google.com (mail-yb1-xb35.google.com [IPv6:2607:f8b0:4864:20::b35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1CBAC061574; Tue, 4 May 2021 17:37:42 -0700 (PDT) Received: by mail-yb1-xb35.google.com with SMTP id z1so466741ybf.6; Tue, 04 May 2021 17:37:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qZ6UQO/t/anayyvxHYL8y/BSgNgKydNeCjijU78LDB0=; b=hTrd2XUlYhsfMMGGIx5klGnci50oDrRl0xMOhc7gSeBJ6JyUSZSgBRRcYDumzNziIN EW5jBXVq223SV2a2bUU3WoIC2DwuDg5vWWm5sxYcwOcg1nDU3F/lctBBfvTbHTFoxASa ULAT2IF1dTAC+zmX7fZNwTcLNckpJtwUJ4+wntOO3gx/MlKWZgPbwVDAEtAcwEMesfWu p/H9/NmzXx0tqku0UN23HP3r4o/La/tBByaHFsGTe5yFG6uoXGnqmdXYAyYWVzKSBE61 x8EXnsRW67ETjsqK/6yFzR8w7Z5BICLypDRkgtNRZg6RuYY1nGehmrqkvHgApzUrVEtp MSaw== 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=qZ6UQO/t/anayyvxHYL8y/BSgNgKydNeCjijU78LDB0=; b=PS2LyAhrRBXCR9FTkdVfGzfh1IG0e7iVCHVWQz4R4uDsVE3U1vrUb+SOzSc+hyDNrN QZcGK97UTR9m2STN45Z/AixGG8j3iIXTaUO/9RY7AHyB85akUtW0UoTwBoXn1tqAqizn 8zrUm13bMxc+BZEQ/57h1Y2zisPQiYb215CodhU5JfFMr9y9qXLgqd6eV7QYzNQTvnh+ XCKDPhE06livCavy/2D5NZ9DRQEY8/cDRKUmAhohSdmcajx+maI35JmmTGVUdrLhWT6q zO0vgrmo6gaJgw1ipXdgTCK6/0BwUwqjgHMk0joVA7z2+Jm134ejP4rv0EhwKJaquOBX zsvg== X-Gm-Message-State: AOAM531LGCR5RcL8NfPWU5AiDEj0hGc+wc7VbSpDB6lP7v/BhJxlth9y 6abGEQLiQRpOxO2DkB1G7IG50Zl4PzJGwO739J7rhma1 X-Received: by 2002:a25:c4c5:: with SMTP id u188mr36960466ybf.425.1620175062113; Tue, 04 May 2021 17:37:42 -0700 (PDT) MIME-Version: 1.0 References: <20210429130510.1621665-1-jackmanb@google.com> In-Reply-To: From: Andrii Nakryiko Date: Tue, 4 May 2021 17:37:31 -0700 Message-ID: Subject: Re: [PATCH v2 bpf-next] libbpf: Fix signed overflow in ringbuf_process_ring To: Brendan Jackman 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 Tue, May 4, 2021 at 2:01 AM Brendan Jackman wrote: > > 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. 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;