Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2707561rwr; Fri, 21 Apr 2023 12:47:37 -0700 (PDT) X-Google-Smtp-Source: AKy350bBho+yxmgqAEhf6q4oIiTz0Zt3j1fAzzPLQ1oIHy1VTB64KY6mjT4gEovA8lr5aI019UYZ X-Received: by 2002:a17:902:f685:b0:1a9:4167:5db7 with SMTP id l5-20020a170902f68500b001a941675db7mr4910667plg.4.1682106457323; Fri, 21 Apr 2023 12:47:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682106457; cv=none; d=google.com; s=arc-20160816; b=JtmxG1AzFG35sIjKO6ARJ+ovqpJjwy7cGg1AgdUioffvPGiPOIMWzV2f6HW6vkJFTY FCVC/1NWyN3iaaIED0ieyD/+FizLRU2WxT2PSogl9rQHpBeElDSUnmVpSaZat7pBVtJf Ujoe7M3FR5iW1zGAU2Bie8MRNde/WuBGX/F8kqkk06DEDW5QHjWLA+K3TMo7vkoTeHRR xUGILFgUu41+drpku9LnL4hP92OHnOQwlqdeDjwEsaQxsfj0z8N/Ub0zrjudAvRac4Qr Mrqj1hHXMZAuk8gX7utTun/WQ/YAjosFrG27yJImLOlUib78eUh8gYMV0ULHgDNpoYy0 hp6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=EdCs8u1zE53PHCAFSaCBIkFUHPGTGSmSPYh5C3Pis2Y=; b=sMrHkO3X+9D0Wc4vI46PhQb3FKxn8lQKAKhRbKKpJAkKhS/hdeova7MmosbwCgK0u2 ilSjR0yE0sS4Elky6lfVFjeSRhdaXd4jfOBDWhafr8x02BaOfPB4u8fG9HYisrW9Aj+I Z3hPQw6KVqNd8aFZsSJvFtXP8lAx4q/s8SxCFvbnQ4aYrs9QyZZR/1sDqraLM0hqwFYH mlfqEfltwW6kzS7AdKSlChwmURGAeg+JqPdvCbzRsTd9vqIGKAofraWYuwOCyjAHMBeW QKf2wwEh+uuw8uxTgO0jp7wnuAKUZiB1Kcx9k1DMp33EUOTV9W/tRmnrieRTJktgeA52 e1DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b="vwKgMUq/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u8-20020a170902e5c800b0019fe9a63cf2si5491379plf.609.2023.04.21.12.47.25; Fri, 21 Apr 2023 12:47:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b="vwKgMUq/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233563AbjDUTjP (ORCPT + 99 others); Fri, 21 Apr 2023 15:39:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233439AbjDUTjN (ORCPT ); Fri, 21 Apr 2023 15:39:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B0F42702 for ; Fri, 21 Apr 2023 12:39:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 982C961CBD for ; Fri, 21 Apr 2023 19:39:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC2EAC433EF; Fri, 21 Apr 2023 19:39:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1682105952; bh=9jm7Yk/V2fA6/l+FztUl37nK9oPvvNK38u0eLqXt43o=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=vwKgMUq/niZu6Zr6QGOacFycbzkShwJwXE0iZaRgJGRwCHOmgVSU+AfL6aODnPa02 oAFu7qC/Zg91tLl/jrghkRhQBc3ZoVg7rA5sJjdkCKwnAtWoU7jJPd4u3Oj06kOc69 8jRXajxsU6zGUSALmIQiicXxFXi0eXi0GZUgTM5k= Date: Fri, 21 Apr 2023 12:39:11 -0700 From: Andrew Morton To: Alexey Dobriyan Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH] ELF: use __builtin_mul_overflow() more Message-Id: <20230421123911.3c4b1e3b56781ffdf043ef58@linux-foundation.org> In-Reply-To: References: X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 21 Apr 2023 21:54:36 +0300 Alexey Dobriyan wrote: > __builtin_mul_overflow() can do multiplication and overflow check > in one line. > > --- a/fs/binfmt_elf.c > +++ b/fs/binfmt_elf.c > @@ -1651,9 +1651,8 @@ static int fill_files_note(struct memelfnote *note, struct coredump_params *cprm > > /* *Estimated* file count and total data size needed */ > count = cprm->vma_count; > - if (count > UINT_MAX / 64) > + if (__builtin_mul_overflow(count, 64, &size)) > return -EINVAL; > - size = count * 64; Huh, what the heck is that ;) include/linux/overflow.h has check_mul_overflow() for us to use here. tools/lib/bpf/libbpf_internal.h uses #if __has_builtin(__builtin_mul_overflow) but check_mul_overflow() didn't bother testing for availability. Probably tools/lib/bpf/libbpf_internal.h should just use check_mul_overflow().