finish migration away from config.h
parent
06149aa156
commit
f3623e1f2b
20
Makefile
20
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 >/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
|
||||
|
|
23
README.md
23
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
|
||||
|
|
15
config.h
15
config.h
|
@ -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
|
1
malloc.c
1
malloc.c
|
@ -11,7 +11,6 @@
|
|||
|
||||
#include "third_party/libdivide.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "malloc.h"
|
||||
#include "mutex.h"
|
||||
#include "memory.h"
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../config.h"
|
||||
|
||||
static unsigned size_classes[] = {
|
||||
/* large */ 4 * 1024 * 1024,
|
||||
/* 0 */ 0,
|
||||
|
|
Loading…
Reference in New Issue