public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Istvan Kurucsai <pistukem@gmail.com>, DJ Delorie <dj@redhat.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH v2 4/7] malloc: Ensure lower bound on chunk size in __libc_realloc.
Date: Fri, 17 Aug 2018 14:12:00 -0000	[thread overview]
Message-ID: <92108102-50a3-ad30-9573-df26d982d3cb@redhat.com> (raw)
In-Reply-To: <1510068430-27816-5-git-send-email-pistukem@gmail.com>

On 11/07/2017 04:27 PM, Istvan Kurucsai wrote:
> Under some circumstances, a chunk size of SIZE_SZ could lead to an underflow
> when calculating the length argument of memcpy.
> 
>     * malloc/malloc.c (__libc_realloc): Check chunk size.
> ---
>   malloc/malloc.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index 51d703c..8e48952 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -3154,8 +3154,9 @@ __libc_realloc (void *oldmem, size_t bytes)
>        accident or by "design" from some intruder.  We need to bypass
>        this check for dumped fake mmap chunks from the old main arena
>        because the new malloc may provide additional alignment.  */
> -  if ((__builtin_expect ((uintptr_t) oldp > (uintptr_t) -oldsize, 0)
> -       || __builtin_expect (misaligned_chunk (oldp), 0))
> +  if ((__glibc_unlikely ((uintptr_t) oldp > (uintptr_t) -oldsize)
> +       || __glibc_unlikely (misaligned_chunk (oldp))
> +       || __glibc_unlikely (oldsize <= 2 * SIZE_SZ))
>         && !DUMPED_MAIN_ARENA_CHUNK (oldp))
>         malloc_printerr ("realloc(): invalid pointer");

DJ, can you benchmark this change?  If it turns out this is visible in 
profiles, we may have to move this check closer to the actual memcpy.

Thanks,
Florian

  reply	other threads:[~2018-08-17 14:12 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-07 15:27 [PATCH v2 0/7] Additional integrity checks for the malloc Istvan Kurucsai
2017-11-07 15:27 ` [PATCH v2 7/7] malloc: Check the alignment of mmapped chunks before unmapping Istvan Kurucsai
2018-11-15 23:58   ` DJ Delorie
2018-11-16 10:35     ` Florian Weimer
2018-12-21  6:33       ` DJ Delorie
2017-11-07 15:27 ` [PATCH v2 5/7] malloc: Verify the integrity of mmapped chunks in calloc Istvan Kurucsai
2018-08-17 14:15   ` Florian Weimer
2018-11-16 10:33     ` Florian Weimer
2017-11-07 15:27 ` [PATCH v2 3/7] malloc: Ensure that the consolidated fast chunk has a sane size Istvan Kurucsai
2018-01-12 14:29   ` Florian Weimer
2017-11-07 15:27 ` [PATCH v2 1/7] malloc: Add check for top size corruption Istvan Kurucsai
2017-11-07 15:53   ` Andreas Schwab
2018-01-11 12:05   ` Florian Weimer
2018-01-16 12:05     ` Istvan Kurucsai
2018-02-20 13:49       ` Florian Weimer
2018-08-17 14:08         ` Florian Weimer
2017-11-07 15:27 ` [PATCH v2 2/7] malloc: Additional checks for unsorted bin integrity I Istvan Kurucsai
2018-01-11 14:50   ` Florian Weimer
2018-01-16 13:54     ` Istvan Kurucsai
2018-08-17 14:07       ` Florian Weimer
2018-08-20 12:59         ` Florian Weimer
2017-11-07 15:27 ` [PATCH v2 4/7] malloc: Ensure lower bound on chunk size in __libc_realloc Istvan Kurucsai
2018-08-17 14:12   ` Florian Weimer [this message]
2018-08-20 21:20     ` DJ Delorie
2018-08-21  0:07       ` Carlos O'Donell
2018-08-21  0:17         ` DJ Delorie
2018-08-21  0:40           ` Carlos O'Donell
2017-11-07 15:27 ` [PATCH v2 6/7] malloc: Add more integrity checks to mremap_chunk Istvan Kurucsai
2018-11-15 23:55   ` DJ Delorie
2018-11-16 10:32     ` Florian Weimer
2018-12-21  6:32       ` DJ Delorie
2017-11-16  4:18 ` [PATCH v2 0/7] Additional integrity checks for the malloc DJ Delorie

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=92108102-50a3-ad30-9573-df26d982d3cb@redhat.com \
    --to=fweimer@redhat.com \
    --cc=dj@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=pistukem@gmail.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).