From d398384b90723ae17d06f5db29ce4e18ddbed292 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Fri, 7 Sep 2018 00:17:22 -0400 Subject: [PATCH] add header for configuration --- Makefile | 2 +- config.h | 7 +++++++ malloc.c | 10 ++++------ 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 config.h diff --git a/Makefile b/Makefile index 346da77..deba7d9 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ hardened_malloc.so: $(OBJECTS) $(CC) $(CFLAGS) $(LDFLAGS) -shared $^ $(LDLIBS) -o $@ chacha.o: chacha.c chacha.h -malloc.o: malloc.c malloc.h memory.h pages.h random.h util.h +malloc.o: malloc.c malloc.h config.h memory.h pages.h random.h util.h memory.o: memory.c memory.h util.h pages.o: pages.c pages.h memory.h util.h random.o: random.c random.h chacha.h util.h diff --git a/config.h b/config.h new file mode 100644 index 0000000..dd1832e --- /dev/null +++ b/config.h @@ -0,0 +1,7 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#define GUARD_SLABS true +#define WRITE_AFTER_FREE_CHECK true + +#endif diff --git a/malloc.c b/malloc.c index b59f04d..7790261 100644 --- a/malloc.c +++ b/malloc.c @@ -11,6 +11,7 @@ #include "third_party/libdivide.h" +#include "config.h" #include "malloc.h" #include "memory.h" #include "pages.h" @@ -19,9 +20,6 @@ static_assert(sizeof(void *) == 8, "64-bit only"); -static const bool guard_slabs = true; -static const bool enable_write_after_free_check = true; - // either sizeof(uint64_t) or 0 static const size_t canary_size = sizeof(uint64_t); @@ -165,7 +163,7 @@ static struct slab_metadata *alloc_metadata(struct size_class *c, size_t slab_si return NULL; } c->metadata_count++; - if (guard_slabs) { + if (GUARD_SLABS) { c->metadata_count++; } return metadata; @@ -245,13 +243,13 @@ static void *slot_pointer(size_t size, void *slab, size_t slot) { } static void write_after_free_check(char *p, size_t size) { - if (!enable_write_after_free_check) { + if (!WRITE_AFTER_FREE_CHECK) { return; } for (size_t i = 0; i < size; i += sizeof(uint64_t)) { if (*(uint64_t *)(p + i)) { - fatal_error("write after free"); + fatal_error("detected write after free"); } } }