From: Ben Kallus <benjamin.p.kallus.gr@dartmouth.edu>
To: libc-alpha@sourceware.org
Cc: adhemerval.zanella@linaro.org,
Ben Kallus <benjamin.p.kallus.gr@dartmouth.edu>
Subject: [PATCH] malloc: Add integrity check to largebin nextsizes
Date: Fri, 14 Feb 2025 00:34:54 -0500 [thread overview]
Message-ID: <20250214053454.2346370-1-benjamin.p.kallus.gr@dartmouth.edu> (raw)
If attacker overwrites the bk_nextsize link in the first chunk of a
largebin that later has a smaller chunk inserted into it, malloc will
write a heap pointer into an attacker-controlled address [0].
This patch adds an integrity check to mitigate this attack.
[0]: https://github.com/shellphish/how2heap/blob/master/glibc_2.39/large_bin_attack.c
Signed-off-by: Ben Kallus <benjamin.p.kallus.gr@dartmouth.edu>
---
malloc/malloc.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/malloc/malloc.c b/malloc/malloc.c
index dcac903e2a..931ca48112 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -4244,6 +4244,9 @@ _int_malloc (mstate av, size_t bytes)
fwd = bck;
bck = bck->bk;
+ if (__glibc_unlikely (fwd->fd->bk_nextsize->fd_nextsize != fwd->fd))
+ malloc_printerr ("malloc(): largebin double linked list corrupted (nextsize)");
+
victim->fd_nextsize = fwd->fd;
victim->bk_nextsize = fwd->fd->bk_nextsize;
fwd->fd->bk_nextsize = victim->bk_nextsize->fd_nextsize = victim;
--
2.48.1
next reply other threads:[~2025-02-14 5:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-14 5:34 Ben Kallus [this message]
2025-02-24 21:45 ` DJ Delorie
2025-02-24 22:04 ` Ben Kallus
2025-03-04 3:09 ` DJ Delorie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250214053454.2346370-1-benjamin.p.kallus.gr@dartmouth.edu \
--to=benjamin.p.kallus.gr@dartmouth.edu \
--cc=adhemerval.zanella@linaro.org \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).