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