]> sourceware.org Git - glibc.git/commitdiff
malloc: Fix a realloc crash with heap tagging [BZ 27468]
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Thu, 25 Feb 2021 14:49:58 +0000 (14:49 +0000)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Fri, 19 Mar 2021 11:46:20 +0000 (11:46 +0000)
_int_free must be called with a chunk that has its tag reset. This was
missing in a rare case that could crash when heap tagging is enabled:
when in a multi-threaded process the current arena runs out of memory
during realloc, but another arena still has space to finish the realloc
then _int_free was called without clearing the user allocation tags.

Fixes bug 27468.

Reviewed-by: DJ Delorie <dj@redhat.com>
malloc/malloc.c

index 1f4bbd8edf8b97701b779f183475565c7d0a6762..8f8f12c2768124055050cf4ec8cb8163968c4c7b 100644 (file)
@@ -3446,7 +3446,9 @@ __libc_realloc (void *oldmem, size_t bytes)
       newp = __libc_malloc (bytes);
       if (newp != NULL)
         {
-          memcpy (newp, oldmem, oldsize - SIZE_SZ);
+         size_t sz = CHUNK_AVAILABLE_SIZE (oldp) - CHUNK_HDR_SZ;
+         memcpy (newp, oldmem, sz);
+         (void) TAG_REGION (chunk2rawmem (oldp), sz);
           _int_free (ar_ptr, oldp, 0);
         }
     }
This page took 0.049023 seconds and 5 git commands to generate.