Blame SOURCES/glibc-rh1284959-3.patch

147e83
Short description: Don't corrupt heap if top chunk is MINSIZE.
147e83
Author(s): Mel Gorman <mgorman@suse.de>
147e83
Origin: git://sourceware.org/git/glibc.git
147e83
Bug-RHEL: N/A
147e83
Bug-Fedora: N/A
147e83
Bug-Upstream: #18502
147e83
Upstream status: committed
147e83
147e83
commit f8ef472c0ff4644445ec716036d31430b4fa4bab
147e83
Author: Mel Gorman <mgorman@suse.de>
147e83
Date:   Mon Jun 8 13:36:13 2015 +0100
147e83
147e83
    malloc: Do not corrupt the top of a threaded heap if top chunk is MINSIZE [BZ #18502]
147e83
    
147e83
    mksquashfs was reported in openSUSE to be causing segmentation faults when
147e83
    creating installation images. Testing showed that mksquashfs sometimes
147e83
    failed and could be reproduced within 10 attempts. The core dump looked
147e83
    like the heap top was corrupted and was pointing to an unmapped area. In
147e83
    other cases, this has been due to an application corrupting glibc structures
147e83
    but mksquashfs appears to be fine in this regard.
147e83
    
147e83
    The problem is that heap_trim is "growing" the top into unmapped space.
147e83
    If the top chunk == MINSIZE then top_area is -1 and this check does not
147e83
    behave as expected due to a signed/unsigned comparison
147e83
    
147e83
      if (top_area <= pad)
147e83
        return 0;
147e83
    
147e83
    The next calculation extra = ALIGN_DOWN(top_area - pad, pagesz) calculates
147e83
    extra as a negative number which also is unnoticed due to a signed/unsigned
147e83
    comparison. We then call shrink_heap(heap, negative_number) which crashes
147e83
    later. This patch adds a simple check against MINSIZE to make sure extra
147e83
    does not become negative. It adds a cast to hint to the reader that this
147e83
    is a signed vs unsigned issue.
147e83
    
147e83
    Without the patch, mksquash fails within 10 attempts. With it applied, it
147e83
    completed 1000 times without error. The standard test suite "make check"
147e83
    showed no changes in the summary of test results.
147e83
147e83
Index: glibc-2.17-c758a686/malloc/arena.c
147e83
===================================================================
147e83
--- glibc-2.17-c758a686.orig/malloc/arena.c
147e83
+++ glibc-2.17-c758a686/malloc/arena.c
147e83
@@ -705,7 +705,7 @@ heap_trim(heap_info *heap, size_t pad)
147e83
     return 0;
147e83
 
147e83
   top_area = top_size - MINSIZE - 1;
147e83
-  if (top_area <= pad)
147e83
+  if (top_area < 0 || (size_t) top_area <= pad)
147e83
     return 0;
147e83
 
147e83
   /* Release in pagesize units and round down to the nearest page.  */