]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
malloc: Check for large bin list corruption when inserting unsorted chunk
authorAdam Maris <amaris@redhat.com>
Thu, 14 Mar 2019 20:51:16 +0000 (16:51 -0400)
committerArjun Shankar <arjun@redhat.com>
Thu, 2 May 2019 12:29:11 +0000 (14:29 +0200)
Fixes bug 24216. This patch adds security checks for bk and bk_nextsize pointers
of chunks in large bin when inserting chunk from unsorted bin. It was possible
to write the pointer to victim (newly inserted chunk) to arbitrary memory
locations if bk or bk_nextsize pointers of the next large bin chunk
got corrupted.

(cherry picked from commit 5b06f538c5aee0389ed034f60d90a8884d6d54de)

malloc/malloc.c

index 6ae22e61dc2de7ad634c08a768ef5ba71798823e..0e9a2e23ec87c3839f1101b2baa388b5703ef23d 100644 (file)
@@ -3869,10 +3869,14 @@ _int_malloc (mstate av, size_t bytes)
                         {
                           victim->fd_nextsize = fwd;
                           victim->bk_nextsize = fwd->bk_nextsize;
+                          if (__glibc_unlikely (fwd->bk_nextsize->fd_nextsize != fwd))
+                            malloc_printerr ("malloc(): largebin double linked list corrupted (nextsize)");
                           fwd->bk_nextsize = victim;
                           victim->bk_nextsize->fd_nextsize = victim;
                         }
                       bck = fwd->bk;
+                      if (bck->fd != fwd)
+                        malloc_printerr ("malloc(): largebin double linked list corrupted (bk)");
                     }
                 }
               else