mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ELF: use __builtin_mul_overflow() more
Date: Fri, 21 Apr 2023 12:39:11 -0700	[thread overview]
Message-ID: <20230421123911.3c4b1e3b56781ffdf043ef58@linux-foundation.org> (raw)
In-Reply-To: <dd85c092-379e-4d14-88f0-8f3910de9f7f@p183>

On Fri, 21 Apr 2023 21:54:36 +0300 Alexey Dobriyan <adobriyan@gmail.com> 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().



  reply	other threads:[~2023-04-21 19:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-21 18:54 Alexey Dobriyan
2023-04-21 19:39 ` Andrew Morton [this message]
2023-04-22  9:45   ` Alexey Dobriyan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230421123911.3c4b1e3b56781ffdf043ef58@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=adobriyan@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®