From: Alexey Dobriyan <adobriyan@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ELF: use __builtin_mul_overflow() more
Date: Sat, 22 Apr 2023 12:45:14 +0300 [thread overview]
Message-ID: <a7f51d49-cb6a-4066-a58f-2505e29f25e8@p183> (raw)
In-Reply-To: <20230421123911.3c4b1e3b56781ffdf043ef58@linux-foundation.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 <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.
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.
prev parent reply other threads:[~2023-04-22 9:45 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
2023-04-22 9:45 ` Alexey Dobriyan [this message]
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=a7f51d49-cb6a-4066-a58f-2505e29f25e8@p183 \
--to=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--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®