finish migration away from config.h

This commit is contained in:
Daniel Micay 2018-11-16 15:25:35 -05:00
parent 06149aa156
commit f3623e1f2b
6 changed files with 38 additions and 33 deletions

View File

@ -6,6 +6,14 @@ CONFIG_WRITE_AFTER_FREE_CHECK := true
CONFIG_SLOT_RANDOMIZE := true CONFIG_SLOT_RANDOMIZE := true
CONFIG_ZERO_ON_FREE := true CONFIG_ZERO_ON_FREE := true
CONFIG_SLAB_CANARY := 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 define safe_flag
$(shell $(CC) -E $1 - </dev/null >/dev/null 2>&1 && echo $1) $(shell $(CC) -E $1 - </dev/null >/dev/null 2>&1 && echo $1)
@ -61,13 +69,21 @@ CPPFLAGS += \
-DZERO_ON_FREE=$(CONFIG_ZERO_ON_FREE) \ -DZERO_ON_FREE=$(CONFIG_ZERO_ON_FREE) \
-DWRITE_AFTER_FREE_CHECK=$(CONFIG_WRITE_AFTER_FREE_CHECK) \ -DWRITE_AFTER_FREE_CHECK=$(CONFIG_WRITE_AFTER_FREE_CHECK) \
-DSLOT_RANDOMIZE=$(CONFIG_SLOT_RANDOMIZE) \ -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) hardened_malloc.so: $(OBJECTS)
$(CC) $(CFLAGS) $(LDFLAGS) -shared $^ $(LDLIBS) -o $@ $(CC) $(CFLAGS) $(LDFLAGS) -shared $^ $(LDLIBS) -o $@
chacha.o: chacha.c chacha.h util.h 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 memory.o: memory.c memory.h util.h
new.o: new.cc malloc.h util.h new.o: new.cc malloc.h util.h
pages.o: pages.c pages.h memory.h util.h pages.o: pages.c pages.h memory.h util.h

View File

@ -102,20 +102,17 @@ options are available:
contained within an isolated memory region with high entropy random guard contained within an isolated memory region with high entropy random guard
regions around it. regions around it.
More advanced compile-time configuration is available in the `config.h` file The following are more advanced configuration options without proper sanity
and will be migrated to the main configuration when proper sanity checks and checks and documentation written yet, so use them at your own peril:
documentation are written. The following advanced options are available:
``` * `CONFIG_SLAB_QUARANTINE_RANDOM_SIZE`: `0` (default)
#define SLAB_QUARANTINE_RANDOM_SIZE 0 * `CONFIG_SLAB_QUARANTINE_QUEUE_SIZE`: `0` (default)
#define SLAB_QUARANTINE_QUEUE_SIZE 0 * `CONFIG_GUARD_SLABS_INTERVAL`: `1` (default)
#define GUARD_SLABS_INTERVAL 1 * `CONFIG_GUARD_SIZE_DIVISOR`: `2` (default)
#define GUARD_SIZE_DIVISOR 2 * `CONFIG_REGION_QUARANTINE_RANDOM_SIZE`: `128` (default)
#define REGION_QUARANTINE_RANDOM_SIZE 128 * `CONFIG_REGION_QUARANTINE_QUEUE_SIZE`: `1024` (default)
#define REGION_QUARANTINE_QUEUE_SIZE 1024 * `CONFIG_REGION_QUARANTINE_SKIP_THRESHOLD`: `33554432` (default)
#define REGION_QUARANTINE_SKIP_THRESHOLD (32 * 1024 * 1024) * `CONFIG_FREE_SLABS_QUARANTINE_RANDOM_SIZE`: `32` (default)
#define FREE_SLABS_QUARANTINE_RANDOM_SIZE 32
```
There will be more control over enabled features in the future along with 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 control over fairly arbitrarily chosen values like the size of empty slab

View File

@ -1,15 +0,0 @@
#ifndef CONFIG_H
#define CONFIG_H
#include <stdbool.h>
#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

View File

@ -11,7 +11,6 @@
#include "third_party/libdivide.h" #include "third_party/libdivide.h"
#include "config.h"
#include "malloc.h" #include "malloc.h"
#include "mutex.h" #include "mutex.h"
#include "memory.h" #include "memory.h"

View File

@ -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 := \ EXECUTABLES := \
offset offset

View File

@ -1,9 +1,8 @@
#include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "../config.h"
static unsigned size_classes[] = { static unsigned size_classes[] = {
/* large */ 4 * 1024 * 1024, /* large */ 4 * 1024 * 1024,
/* 0 */ 0, /* 0 */ 0,