diff --git a/Makefile b/Makefile index 9676452..3041f83 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,14 @@ CONFIG_WRITE_AFTER_FREE_CHECK := true CONFIG_SLOT_RANDOMIZE := true CONFIG_ZERO_ON_FREE := true CONFIG_SLAB_CANARY := true +CONFIG_SLAB_QUARANTINE_RANDOM_SIZE := 0 +CONFIG_SLAB_QUARANTINE_QUEUE_SIZE := 0 +CONFIG_GUARD_SLABS_INTERVAL := 1 +CONFIG_GUARD_SIZE_DIVISOR := 2 +CONFIG_REGION_QUARANTINE_RANDOM_SIZE := 128 +CONFIG_REGION_QUARANTINE_QUEUE_SIZE := 1024 +CONFIG_REGION_QUARANTINE_SKIP_THRESHOLD := 33554432 +CONFIG_FREE_SLABS_QUARANTINE_RANDOM_SIZE := 32 define safe_flag $(shell $(CC) -E $1 - /dev/null 2>&1 && echo $1) @@ -61,13 +69,21 @@ CPPFLAGS += \ -DZERO_ON_FREE=$(CONFIG_ZERO_ON_FREE) \ -DWRITE_AFTER_FREE_CHECK=$(CONFIG_WRITE_AFTER_FREE_CHECK) \ -DSLOT_RANDOMIZE=$(CONFIG_SLOT_RANDOMIZE) \ - -DSLAB_CANARY=$(CONFIG_SLAB_CANARY) + -DSLAB_CANARY=$(CONFIG_SLAB_CANARY) \ + -DSLAB_QUARANTINE_RANDOM_SIZE=$(CONFIG_SLAB_QUARANTINE_RANDOM_SIZE) \ + -DSLAB_QUARANTINE_QUEUE_SIZE=$(CONFIG_SLAB_QUARANTINE_QUEUE_SIZE) \ + -DGUARD_SLABS_INTERVAL=$(CONFIG_GUARD_SLABS_INTERVAL) \ + -DGUARD_SIZE_DIVISOR=$(CONFIG_GUARD_SIZE_DIVISOR) \ + -DREGION_QUARANTINE_RANDOM_SIZE=$(CONFIG_REGION_QUARANTINE_RANDOM_SIZE) \ + -DREGION_QUARANTINE_QUEUE_SIZE=$(CONFIG_REGION_QUARANTINE_QUEUE_SIZE) \ + -DREGION_QUARANTINE_SKIP_THRESHOLD=$(CONFIG_REGION_QUARANTINE_SKIP_THRESHOLD) \ + -DFREE_SLABS_QUARANTINE_RANDOM_SIZE=$(CONFIG_FREE_SLABS_QUARANTINE_RANDOM_SIZE) hardened_malloc.so: $(OBJECTS) $(CC) $(CFLAGS) $(LDFLAGS) -shared $^ $(LDLIBS) -o $@ chacha.o: chacha.c chacha.h util.h -malloc.o: malloc.c malloc.h config.h mutex.h memory.h pages.h random.h util.h +malloc.o: malloc.c malloc.h mutex.h memory.h pages.h random.h util.h memory.o: memory.c memory.h util.h new.o: new.cc malloc.h util.h pages.o: pages.c pages.h memory.h util.h diff --git a/README.md b/README.md index f97a534..221e411 100644 --- a/README.md +++ b/README.md @@ -102,20 +102,17 @@ options are available: contained within an isolated memory region with high entropy random guard regions around it. -More advanced compile-time configuration is available in the `config.h` file -and will be migrated to the main configuration when proper sanity checks and -documentation are written. The following advanced options are available: +The following are more advanced configuration options without proper sanity +checks and documentation written yet, so use them at your own peril: -``` -#define SLAB_QUARANTINE_RANDOM_SIZE 0 -#define SLAB_QUARANTINE_QUEUE_SIZE 0 -#define GUARD_SLABS_INTERVAL 1 -#define GUARD_SIZE_DIVISOR 2 -#define REGION_QUARANTINE_RANDOM_SIZE 128 -#define REGION_QUARANTINE_QUEUE_SIZE 1024 -#define REGION_QUARANTINE_SKIP_THRESHOLD (32 * 1024 * 1024) -#define FREE_SLABS_QUARANTINE_RANDOM_SIZE 32 -``` +* `CONFIG_SLAB_QUARANTINE_RANDOM_SIZE`: `0` (default) +* `CONFIG_SLAB_QUARANTINE_QUEUE_SIZE`: `0` (default) +* `CONFIG_GUARD_SLABS_INTERVAL`: `1` (default) +* `CONFIG_GUARD_SIZE_DIVISOR`: `2` (default) +* `CONFIG_REGION_QUARANTINE_RANDOM_SIZE`: `128` (default) +* `CONFIG_REGION_QUARANTINE_QUEUE_SIZE`: `1024` (default) +* `CONFIG_REGION_QUARANTINE_SKIP_THRESHOLD`: `33554432` (default) +* `CONFIG_FREE_SLABS_QUARANTINE_RANDOM_SIZE`: `32` (default) There will be more control over enabled features in the future along with control over fairly arbitrarily chosen values like the size of empty slab diff --git a/config.h b/config.h deleted file mode 100644 index 9f61159..0000000 --- a/config.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef CONFIG_H -#define CONFIG_H - -#include - -#define SLAB_QUARANTINE_RANDOM_SIZE 0 -#define SLAB_QUARANTINE_QUEUE_SIZE 0 -#define GUARD_SLABS_INTERVAL 1 -#define GUARD_SIZE_DIVISOR 2 -#define REGION_QUARANTINE_RANDOM_SIZE 128 -#define REGION_QUARANTINE_QUEUE_SIZE 1024 -#define REGION_QUARANTINE_SKIP_THRESHOLD (32 * 1024 * 1024) -#define FREE_SLABS_QUARANTINE_RANDOM_SIZE 32 - -#endif diff --git a/malloc.c b/malloc.c index c4c4e4e..074d63f 100644 --- a/malloc.c +++ b/malloc.c @@ -11,7 +11,6 @@ #include "third_party/libdivide.h" -#include "config.h" #include "malloc.h" #include "mutex.h" #include "memory.h" diff --git a/test/Makefile b/test/Makefile index e488fa3..42bf111 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,3 +1,12 @@ +CONFIG_SLAB_CANARY := true + +ifeq (,$(filter $(CONFIG_SLAB_CANARY),true false)) + $(error CONFIG_SLAB_CANARY must be true or false) +endif + +CPPFLAGS += \ + -DSLAB_CANARY=$(CONFIG_SLAB_CANARY) + EXECUTABLES := \ offset diff --git a/test/offset.c b/test/offset.c index afcfb6a..522e2e2 100644 --- a/test/offset.c +++ b/test/offset.c @@ -1,9 +1,8 @@ +#include #include #include #include -#include "../config.h" - static unsigned size_classes[] = { /* large */ 4 * 1024 * 1024, /* 0 */ 0,