077c9d
commit 5b06f538c5aee0389ed034f60d90a8884d6d54de
077c9d
Author: Adam Maris <amaris@redhat.com>
077c9d
Date:   Thu Mar 14 16:51:16 2019 -0400
077c9d
077c9d
    malloc: Check for large bin list corruption when inserting unsorted chunk
077c9d
    
077c9d
    Fixes bug 24216. This patch adds security checks for bk and bk_nextsize pointers
077c9d
    of chunks in large bin when inserting chunk from unsorted bin. It was possible
077c9d
    to write the pointer to victim (newly inserted chunk) to arbitrary memory
077c9d
    locations if bk or bk_nextsize pointers of the next large bin chunk
077c9d
    got corrupted.
077c9d
077c9d
diff --git a/malloc/malloc.c b/malloc/malloc.c
077c9d
index 4412a4ffc83b013b..723d393f529bdb4c 100644
077c9d
--- a/malloc/malloc.c
077c9d
+++ b/malloc/malloc.c
077c9d
@@ -3876,10 +3876,14 @@ _int_malloc (mstate av, size_t bytes)
077c9d
                         {
077c9d
                           victim->fd_nextsize = fwd;
077c9d
                           victim->bk_nextsize = fwd->bk_nextsize;
077c9d
+                          if (__glibc_unlikely (fwd->bk_nextsize->fd_nextsize != fwd))
077c9d
+                            malloc_printerr ("malloc(): largebin double linked list corrupted (nextsize)");
077c9d
                           fwd->bk_nextsize = victim;
077c9d
                           victim->bk_nextsize->fd_nextsize = victim;
077c9d
                         }
077c9d
                       bck = fwd->bk;
077c9d
+                      if (bck->fd != fwd)
077c9d
+                        malloc_printerr ("malloc(): largebin double linked list corrupted (bk)");
077c9d
                     }
077c9d
                 }
077c9d
               else