Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp3312420rwr; Sat, 22 Apr 2023 02:58:07 -0700 (PDT) X-Google-Smtp-Source: AKy350bZgASU9R9azEvEWk43c4oatph5sHZjQqF8DxxddPJE/3PrZ5Q8n0+NqjCcC0+o1S0UpBxe X-Received: by 2002:a17:902:d503:b0:1a6:7b92:15c2 with SMTP id b3-20020a170902d50300b001a67b9215c2mr9634489plg.4.1682157486910; Sat, 22 Apr 2023 02:58:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682157486; cv=none; d=google.com; s=arc-20160816; b=0x3pgPR5U8FKknod2lN1eAy9LM+688cLq1XJtCHZouU5zfiXLiFDs+aqDwYQgn7qMg oA3eleMA1bKBFs+krn7PwE0qzWJ87FOR397Drm+0WSuyityCGm+ps2zhNVPP5d4KFDb4 vjLwJ43Juj10h4jkAd7/1f7BzgXjFgMAH8t6fYI/8DlvqFUsaf3iek2ypnnufWi+8Xmu edaB7vjs4O5DXZuqUUXMYzkajrGfYQPL936ODsAnp6Ap1tbuh118zHi9BNKNkY4Z9Cui UebDGoyaUtinaFKofUWD68RLjiSQy7xRom8kmo/BUjV5f/jtZus8WTIfZt+ssVMOalUM YcUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=vnyeSeDoQt5xayBqxmJ4+9xcveaUtfXwuDg05vHt+yk=; b=MNt2DpKnegYim9Ie50ANVNqBKVC+hmdEvAOxKp6pSbv44xqSbtS7QU4fFJ3CYjCOm6 8F8/et3aijZwtT0I600YzcMUid8n4ckgUIOjGL/K5fCqg4VpQNaErr1kF5zL6a2q4mtd cGY4MGorwQ+bcqiNDZE8pLlmZ8WfanIbTVZIxSKNUbZDMy1R2b1RJo2AktIBBVB9mD4q IkBqkQ8Ty7Yf16k5BH0OPmplmk0eQJPIIMo++gKIjuZqX93JxuN7PFsMGrk60t38HC6w C21DT2EgoX35nl+vkVSORcbWYNi0QLifVu5PCiByacT5lyYchYGEZ7SUBYrjnsCh01Z3 RDhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=bgUUoP+i; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d6-20020a170903230600b0019ceaf40d5esi4044064plh.107.2023.04.22.02.57.52; Sat, 22 Apr 2023 02:58:06 -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=@gmail.com header.s=20221208 header.b=bgUUoP+i; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229595AbjDVJpU (ORCPT + 99 others); Sat, 22 Apr 2023 05:45:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjDVJpT (ORCPT ); Sat, 22 Apr 2023 05:45:19 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 192CEE6F for ; Sat, 22 Apr 2023 02:45:18 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-2fa0ce30ac2so2406418f8f.3 for ; Sat, 22 Apr 2023 02:45:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682156716; x=1684748716; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=vnyeSeDoQt5xayBqxmJ4+9xcveaUtfXwuDg05vHt+yk=; b=bgUUoP+ifj+A6YakQarfnw6siDlPE7FcFykOQD7DBTpkTn6rp09MmzjJqkFV8VPlof Ahs1oFPLZ6X91sEiGkoGC7d6BYUDmi+ziKdgx+Syys1+8lTqrCDEU2rWqkzxXDsGFO/8 C92VMZv/BRifS5872CMNasH4Z54j6iQN9H3Qr153+54F03fbN7AVhHxC/NEqV36BQPLJ glvpwnarLQr67m8XNdWc4RCauLluE36yauLm5s52i0hCMzQGeB5T/2K3DPIukFqpp7yx ceu2SK75wiAM8qRkkxvGtVcixjNPS7XJSd8sUHVJqJMst4znUBDbD3cIi8zsIEy21pqv Ot1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682156716; x=1684748716; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vnyeSeDoQt5xayBqxmJ4+9xcveaUtfXwuDg05vHt+yk=; b=gvoEpVaH0GcwqJZuA9Zwv3+wWq+O/gfXvcB33iFd4nIRhUztVUR9tO71Z5r6ibb1kD Uvu1KpJPnUK+Pq+2gbSLMtNRn1OMLAl+syFcO7y5sh+i02lQ5ZSLyLM8zjGQTOBhG0cL vzDSzuh4ZhGsIqiGtDa//mLqgQEB3c9Md4wI8lZfLZ+goxOoOe2HdeTUdgofCJ9aBnWV BVSA1X/kHimaEWCyNYAKa9R1RWuiL7iXjuuGk2h87TmEGiY4J6zizfAPa/gEGWzCUmSX JZz5rXaCz6AfTU3sgEjXrPetWxt2A2J5AtQVyTwFCSkkkPcN5ed5bmMESd1ebITBZHYe h10g== X-Gm-Message-State: AAQBX9dF0W2VLI9HVknz+Hw5oQBksRmwD2rkqcj1HYUU+tw+pNGvtnyV 3rYFt+lpYQDgQQIZkjTZ/TaNKBkt3w== X-Received: by 2002:adf:e8c4:0:b0:2f5:aadb:4642 with SMTP id k4-20020adfe8c4000000b002f5aadb4642mr5588115wrn.41.1682156716419; Sat, 22 Apr 2023 02:45:16 -0700 (PDT) Received: from p183 ([46.53.251.93]) by smtp.gmail.com with ESMTPSA id 14-20020a05600c028e00b003f18b942338sm6616525wmk.3.2023.04.22.02.45.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 02:45:16 -0700 (PDT) Date: Sat, 22 Apr 2023 12:45:14 +0300 From: Alexey Dobriyan To: Andrew Morton Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH] ELF: use __builtin_mul_overflow() more Message-ID: References: <20230421123911.3c4b1e3b56781ffdf043ef58@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230421123911.3c4b1e3b56781ffdf043ef58@linux-foundation.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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, Apr 21, 2023 at 12:39:11PM -0700, Andrew Morton wrote: > 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. Oh, no, wrappers. > tools/lib/bpf/libbpf_internal.h uses > > #if __has_builtin(__builtin_mul_overflow) > > but check_mul_overflow() didn't bother testing for availability. gcc 5.1 has __builtin_mul_overflow() > Probably tools/lib/bpf/libbpf_internal.h should just use > check_mul_overflow(). I don't know, this is userspace stuff.