]> git.ipfire.org Git - thirdparty/glibc.git/commit
malloc: Add size check when moving fastbin->tcache
authorBen Kallus <benjamin.p.kallus.gr@dartmouth.edu>
Tue, 11 Feb 2025 19:29:51 +0000 (14:29 -0500)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 13 Feb 2025 19:31:28 +0000 (16:31 -0300)
commitd10176c0ffeadbc0bcd443741f53ebd85e70db44
treea222f17cc39ec66b9ca7e2c895a37c6b49bdeb56
parent6a3cb6b1bd63e167fc525cce07010ff78197b271
malloc: Add size check when moving fastbin->tcache

By overwriting a forward link in a fastbin chunk that is subsequently
moved into the tcache, it's possible to get malloc to return an
arbitrary address [0].

When a chunk is fetched from a fastbin, its size is checked against the
expected chunk size for that fastbin (see malloc.c:3991). This patch
adds a similar check for chunks being moved from a fastbin to tcache,
which renders obsolete the exploitation technique described above.

Now updated to use __glibc_unlikely instead of __builtin_expect, as
requested.

[0]: https://github.com/shellphish/how2heap/blob/master/glibc_2.39/fastbin_reverse_into_tcache.c

Signed-off-by: Ben Kallus <benjamin.p.kallus.gr@dartmouth.edu>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
malloc/malloc.c