Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp2912818pxy; Mon, 3 May 2021 10:47:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDTilYyqXDZwRYzYKWvTQRbqh5+YMM8XaEVpdeoNwLQzsBA9Vr9l65U9H5jAPHogMFxGmi X-Received: by 2002:a62:754d:0:b029:289:11e7:4103 with SMTP id q74-20020a62754d0000b029028911e74103mr18198991pfc.25.1620064030390; Mon, 03 May 2021 10:47:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620064030; cv=none; d=google.com; s=arc-20160816; b=rzTg2r5Y/FpE4CmNLBF21iD7hdHdKuvEZ0QU5WXBDevgJHrLGWKxz/vb1J+/ZG1uyt AsiFVo9BMXKTnIT2BjhApW1k1hSWqsFsxJpgwjjR7jMzCMT2x+fD4WjfkSZWF16YQFFI iZovsJXahwl9yDRvTYnIh00mtZ2fcVUmsFYBV47rmvfl+gMnttH6AsrK7b7qN+zSmQe7 uCLkmZVlknFwFcDWz//ndaF6+2ljai6/4j1Z15dspF5v+B0GKJHZCfs/xdhNjLricE8d RHivaEk6QdkGyh0rCa04Os/RQu+DeRCVzNsY8XHtse87GoXuaNKAHFF65LHmR9LZYo7p FUPA== 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=61DmlyfSeY6yLCYawyfyAB+9RV3mvk/E1watnYBOyt4=; b=KPKkhJvvVnDU4bXQ7/anXqS2rFNkIO6VDIV5zTFHTBhJOZ7ZciCIRnqtPlI6+YzlIp SPACUEExn7waxL9LFik66TniFLKi9TudIToncOMQegXCTcFUECFlpL57pXnkdwqdh38k Fn3u2YDjjNTCYh6292Zb1Lk0kcGxCsCSXcmrjUSUxQWs0VgL8NVQCnKbYSGgtp5jR4GB h8m6Anza+yjlF1Z8O/9ID7EdYCRvA/Gu+7eINoiNErGGrbGsaqMOnyzHkE6UZ0TgTDAR J52IqMTDXVkOhDZscPnIozwN63Lhyy2V3B9H0GQnWzmo7HHpSHwW1Jp5qMZlNlvRCBk0 VaLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NIzJ7pGh; 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 v23si13499564pjh.137.2021.05.03.10.46.56; Mon, 03 May 2021 10:47:10 -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=NIzJ7pGh; 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 S231414AbhECRrR (ORCPT + 99 others); Mon, 3 May 2021 13:47:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231285AbhECRrR (ORCPT ); Mon, 3 May 2021 13:47:17 -0400 Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFC32C06174A; Mon, 3 May 2021 10:46:22 -0700 (PDT) Received: by mail-yb1-xb31.google.com with SMTP id i4so8647819ybe.2; Mon, 03 May 2021 10:46:22 -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=61DmlyfSeY6yLCYawyfyAB+9RV3mvk/E1watnYBOyt4=; b=NIzJ7pGhABFW2kwxbJ9EkwgYblB66DQlx3vWG5XCnZmfiDtALwIvynEGGkg4bOLrjY ExsGaFEElS8M4udyTOcMq/mKQxl6ONSeCKRjQqham9YwI5EPa+km6RwYP+D+8BECR5qD +EajlaEf7qzOZZMR0eakjUZcvW14dxi7bbb68eB4GGnVa2EanPuXjdqIPwX54riI/LyI NEoVIG7HjW793pdw4vKhRVBQw3jvxK9EtHEzAJGrp51t9ys6scYCeBwCcfRYo6w9H3M+ nXbNLCg4p0VQ251k2m3l5lcG/qbPzLScMOPwp+cznjz/AuaCzgT24yt3TUK3ieSNVGZ0 d3yg== 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=61DmlyfSeY6yLCYawyfyAB+9RV3mvk/E1watnYBOyt4=; b=TP8D99DjX/WPo6eHjrxLAP1lBpdGbmb+Z3b2SAvtJAfcCb+A0HmwrF81nZRss9Wl6d DsMsNIf1e15AS0S1lC/MFrhMPDkDRGfM+wx1n9jsEOUEDBW7Emty8GGzq7hsU5NWU85V pz/GSiwoV08PaDSmmiL9qUThFcTB1oMyIqI4JY/nSDavbtjYe9OHJ1Fay6uGVZ/ITJS+ GN3Ai7r0axTc91FcRXggfvCZG5wFoiI69ok5FF1oxhYzidejkuWFUWTCAVq7M+oPnenI hslF4zsJYVlz69JWj+8ahe4JKlspXYfUuYIFROFWs0r+g7/AqreOgRuLnXHU3XtQv/CD Usug== X-Gm-Message-State: AOAM531kpeTwyr8fF84oHV5zKD2B0VyL0bHTmWqu1KIfxWb8P61UNqG6 pvqNzfxESBAFkxD+aM+KQWMLQ59IAhLJQLN0b+IjRTukzHQ= X-Received: by 2002:a25:1455:: with SMTP id 82mr28219792ybu.403.1620063982218; Mon, 03 May 2021 10:46:22 -0700 (PDT) MIME-Version: 1.0 References: <20210429130510.1621665-1-jackmanb@google.com> In-Reply-To: From: Andrii Nakryiko Date: Mon, 3 May 2021 10:46:11 -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 Mon, May 3, 2021 at 5:01 AM Brendan Jackman wrote: > > 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. I might be wrong, but given INT_MAX is defined as # define INT_MAX 2147483647 (notice no suffix specifying which type it is), this constant will be interpreted by compiler as desired type in the given context. So in if (cnt > INT_MAX) INT_MAX should be a uint64_t constant. But even if not, it is up-converted to int64_t with no loss anyway. > > > If you don't mind, I can patch it up while applying? > > Yes please do, thanks! 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")