|
Message-ID: <20230909004835.GD4163@brightrain.aerifal.cx> Date: Fri, 8 Sep 2023 20:48:35 -0400 From: Rich Felker <dalias@...c.org> To: James Raphael Tiovalen <jamestiotio@...il.com> Cc: musl@...ts.openwall.com Subject: Re: [PATCH] Add a safe dequeue integrity check for mallocng On Sat, Sep 09, 2023 at 01:49:39AM +0800, James Raphael Tiovalen wrote: > This commit adds an integrity check to allow for safer dequeuing of meta > structs in mallocng. If the unlikely condition is true due to some sort > of heap corruption, we print an error message and abort. > > This approach is similar to the safe unlinking check performed by glibc. > > While this check would not prevent more sophisticated attacks in more > specific scenarios, as shown by the historical exploitation efforts on > glibc, this check would prevent more basic heap corruption attacks from > being successfully executed. > --- > src/malloc/mallocng/meta.h | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/src/malloc/mallocng/meta.h b/src/malloc/mallocng/meta.h > index 61ec53f9..57946d01 100644 > --- a/src/malloc/mallocng/meta.h > +++ b/src/malloc/mallocng/meta.h > @@ -2,9 +2,11 @@ > #define MALLOC_META_H > > #include <stdint.h> > +#include <stdio.h> > #include <errno.h> > #include <limits.h> > #include "glue.h" > +#include "libm.h" > > __attribute__((__visibility__("hidden"))) > extern const uint16_t size_classes[]; > @@ -90,6 +92,10 @@ static inline void queue(struct meta **phead, struct meta *m) > static inline void dequeue(struct meta **phead, struct meta *m) > { > if (m->next != m) { > + if (predict_false(m->prev->next != m || m->next->prev != m)) { > + fprintf(stderr, "Corrupted doubly-linked meta list\n"); > + abort(); > + } > m->prev->next = m->next; > m->next->prev = m->prev; > if (*phead == m) *phead = m->next; > -- > 2.42.0 This could and should be written with the assert macro, like all the other safety assertions in mallocng, not pulling in stdio and abort. But I think you're over-estimating the value of the check here. The pointers in question are not part of "the heap" but are out-of-band, intended not to be reachable except by an attacker who already has arbitrary code execution or at least strong gadgets for modifying memory they shouldn't with multiple levels of offsetting and indirection, which could generally be used in lots of other ways to obtain arbitrary code execution. Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.