Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp2720615pxy; Mon, 3 May 2021 06:38:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4c7CKQlX4xIsJCDYdZWKbt3m+vv+K2tGxHG8zmdY70oB/rgjVVMVE93NV5XqpiUlrL5F1 X-Received: by 2002:a17:90a:f68f:: with SMTP id cl15mr31109361pjb.99.1620049097727; Mon, 03 May 2021 06:38:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620049097; cv=none; d=google.com; s=arc-20160816; b=wl2L6it6juDPj6UgfivcMwK3jSNZEtadyBhvg2pMWrDDC7DYAVTRmyHafTOwxpwI+3 Mw/9cZWExwv/1NtKP8+tFrOc5PrppIz/Ti2jHXJhlce3I4IdELyNYoKqS0WkMjLw371x CU1nrLgIYlPLm2eCQftLBh1BVTFG6mLkOE0ghkeuBVbfhJoWjF1+71+uR4VxpqJWGRwW 2snmZ8oqV97jigbMatD3X1aaPsF/snfDX01M7/4We/nRwPsSTWPUWpoQtVN8St0Msq4M stsIdJomZqKL1/BU+Ykm41v1qKNUfImqUKVSnZphiUKCp9ilnsSuAH8/q0fardsB45Tq u/Uw== 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=s+RwNQE6LklMpMlC7/iRT4MHt+ceTv7XUchB/czKmcE=; b=Z3p5KecjD/P6gwKJYnsB6v2jjrCOwAmXpTkzKdHtjPUMWB9+KZb+d/auLKb5+AdV8V KiPtqSKdsMunu85Ap/7tJDNkbSnQ10KgyGSEpiR3kzJfxCfWEzN26DNIREOGCfduTfB3 m2ewrnOodiUAJebyTVHtHDVX/mkN71PaAbUEHUyfQuVby0e1BAYb8QBwuTdLyqh4x53M +SNQ3WN9mmUNNpVu+z5Dm2S0bcS0Nwqq5Y1qir/7T5Nx8pSLLEXIQeDX2Jz1k20zW5VQ ElXZ/v876WUFPFNfiY+qRwZzrfW8tywgnQ3YF6amX8CsItgjWHQzgA9u0RcH9kjPzLTJ /Yug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VUYtUdRS; 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 q36si13034301pgl.469.2021.05.03.06.38.04; Mon, 03 May 2021 06:38:17 -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=VUYtUdRS; 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 S233597AbhECMDg (ORCPT + 99 others); Mon, 3 May 2021 08:03:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233977AbhECMCJ (ORCPT ); Mon, 3 May 2021 08:02:09 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D1F5C061348 for ; Mon, 3 May 2021 05:01:14 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id a4so7466655ejk.1 for ; Mon, 03 May 2021 05:01:14 -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=s+RwNQE6LklMpMlC7/iRT4MHt+ceTv7XUchB/czKmcE=; b=VUYtUdRS35j5f7KzTo1RJ4Uj7c+3dSMRjwbG0AyH7ZkM50sTSaPdvp2+bzZiOyPSWl rhRxFlXD4HoWhP4hwvWgIcpNl9fkZtcIZKNxp1p0N1tj5/rNScaPUGLYE0SYHIyyxUQu pUv3QTuK8u7vm+sK5lByW77ACS8NFZMorBtWJs/EfMybCyAbSkxHpQmdpvm0jSXf/I/t zINpVQp9Zj5ObKftx7UObzdLfobOt11rhBp/0EZN0mhnEJVYKF9EskaKFmDtdkyvPO1+ +YSMiISVQ78aZsas9vVSaf95PUK8nB+7md4miDj/doZhveTda3AZZTDCgkCI7zn78DQl OAOA== 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=s+RwNQE6LklMpMlC7/iRT4MHt+ceTv7XUchB/czKmcE=; b=KU22BRrAZfZC9JybaU+97r6IgY5bRCGeqAMuhW+54J4MapcllgYCgLu+8c8imC+AGf 4/ZcRV11/kYbpQ/XyBTs+q8HsTmyA5hq0Lokl9P5asXtnlv+utD+kpURObJ26OSAlktU vw7/lwPJTb25HEXml7DeLrSVG7R+Y+30iXh9OQrSJm5aMQK+ccst69q0p40f4zvmQR7p ijP+rtjkHvC23xntuJmOtvs6uso93O65x0+8tKaWvYK0EnW/CsQuzSX3lJ0xYcK5AVav MFABR+99VTBlY9cnjeaFZ9pb3qJIj/GuTvtXOPQ5B/zARe/q2VZeU/RNPKubSEFnpPct qDvg== X-Gm-Message-State: AOAM53140bSCsml87X7OTKIUNKOrqicJ2+09Rhz2bwrGpefkWZOR2T3c QIyZWntvMpt+rFQeIbddNt1yX8WUN8yeegSXSwB8rg== X-Received: by 2002:a17:906:168d:: with SMTP id s13mr15971516ejd.81.1620043272065; Mon, 03 May 2021 05:01:12 -0700 (PDT) MIME-Version: 1.0 References: <20210429130510.1621665-1-jackmanb@google.com> In-Reply-To: From: Brendan Jackman Date: Mon, 3 May 2021 14:01:00 +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 Fri, 30 Apr 2021 at 18:31, Andrii Nakryiko wrote: > > On Thu, Apr 29, 2021 at 6:05 AM Brendan Jackman wrote: > > Note: I feel a bit guilty about the fact that this makes the reader > > think about implicit conversions. Nobody likes thinking about that. > > > > But explicit casts don't really help with clarity: > > > > return (int)min(cnt, (int64_t)INT_MAX); // ugh > > > > I'd go with > > if (cnt > INT_MAX) > return INT_MAX; > > return cnt; Sure, it has all the same implicit casts/promotions but I guess it's clearer anyway. > If you don't mind, I can patch it up while applying? Yes please do, thanks!