Move memory corruption tests up a directory

This commit is contained in:
jvoisin 2022-01-21 20:47:21 +01:00 committed by Daniel Micay
parent 0bbcc5d610
commit 84eadd8568
42 changed files with 83 additions and 140 deletions

View File

@ -9,8 +9,12 @@ ifeq (,$(filter $(CONFIG_SLAB_CANARY),true false))
$(error CONFIG_SLAB_CANARY must be true or false) $(error CONFIG_SLAB_CANARY must be true or false)
endif endif
LDLIBS := -lpthread LDLIBS := -lpthread -lhardened_malloc
dir=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
LDFLAGS := -Wl,-L$(dir)../out,-R,$(dir)../out
CXXFLAGS := -std=c++17 -fsized-deallocation
CPPFLAGS += \ CPPFLAGS += \
-DSLAB_CANARY=$(CONFIG_SLAB_CANARY) \ -DSLAB_CANARY=$(CONFIG_SLAB_CANARY) \
-DCONFIG_EXTENDED_SIZE_CLASSES=$(CONFIG_EXTENDED_SIZE_CLASSES) -DCONFIG_EXTENDED_SIZE_CLASSES=$(CONFIG_EXTENDED_SIZE_CLASSES)
@ -20,11 +24,47 @@ EXECUTABLES := \
mallinfo \ mallinfo \
mallinfo2 \ mallinfo2 \
malloc_info \ malloc_info \
large_array_growth large_array_growth \
double_free_large \
double_free_large_delayed \
double_free_small \
double_free_small_delayed \
unaligned_free_large \
unaligned_free_small \
read_after_free_large \
read_after_free_small \
write_after_free_large \
write_after_free_large_reuse \
write_after_free_small \
write_after_free_small_reuse \
read_zero_size \
write_zero_size \
invalid_free_protected \
invalid_free_unprotected \
invalid_free_small_region \
invalid_free_small_region_far \
uninitialized_read_small \
uninitialized_read_large \
uninitialized_free \
uninitialized_realloc \
uninitialized_malloc_usable_size \
overflow_large_1_byte \
overflow_large_8_byte \
overflow_small_1_byte \
overflow_small_8_byte \
string_overflow \
delete_type_size_mismatch \
unaligned_malloc_usable_size_small \
invalid_malloc_usable_size_small \
invalid_malloc_usable_size_small_quarantine \
malloc_object_size \
malloc_object_size_offset \
invalid_malloc_object_size_small \
invalid_malloc_object_size_small_quarantine \
impossibly_large_malloc
all: $(EXECUTABLES) all: $(EXECUTABLES)
$(MAKE) -C simple-memory-corruption
clean: clean:
rm -f $(EXECUTABLES) rm -f $(EXECUTABLES)
$(MAKE) -C simple-memory-corruption clean

View File

@ -1,6 +1,6 @@
#include <stdint.h> #include <stdint.h>
#include "../test_util.h" #include "test_util.h"
struct foo { struct foo {
uint64_t a, b, c, d; uint64_t a, b, c, d;

View File

@ -1,6 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
void *p = malloc(256 * 1024); void *p = malloc(256 * 1024);

View File

@ -1,6 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
void *p = malloc(256 * 1024); void *p = malloc(256 * 1024);

View File

@ -1,6 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
void *p = malloc(16); void *p = malloc(16);

View File

@ -1,6 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
void *p = malloc(16); void *p = malloc(16);

View File

@ -1,7 +1,7 @@
#include <malloc.h> #include <malloc.h>
#include <stddef.h> #include <stddef.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(-8); char *p = malloc(-8);

View File

@ -2,7 +2,7 @@
#include <sys/mman.h> #include <sys/mman.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
free(malloc(16)); free(malloc(16));

View File

@ -1,6 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(16); char *p = malloc(16);

View File

@ -1,6 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(16); char *p = malloc(16);

View File

@ -2,7 +2,7 @@
#include <sys/mman.h> #include <sys/mman.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
free(malloc(16)); free(malloc(16));

View File

@ -1,6 +1,6 @@
#include <malloc.h> #include <malloc.h>
#include "../test_util.h" #include "test_util.h"
size_t malloc_object_size(void *ptr); size_t malloc_object_size(void *ptr);

View File

@ -1,6 +1,6 @@
#include <malloc.h> #include <malloc.h>
#include "../test_util.h" #include "test_util.h"
size_t malloc_object_size(void *ptr); size_t malloc_object_size(void *ptr);

View File

@ -1,6 +1,6 @@
#include <malloc.h> #include <malloc.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(16); char *p = malloc(16);

View File

@ -1,6 +1,6 @@
#include <malloc.h> #include <malloc.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
void *p = malloc(16); void *p = malloc(16);

View File

@ -1,7 +1,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <malloc.h> #include <malloc.h>
#include "../test_util.h" #include "test_util.h"
size_t malloc_object_size(void *ptr); size_t malloc_object_size(void *ptr);

View File

@ -1,7 +1,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <malloc.h> #include <malloc.h>
#include "../test_util.h" #include "test_util.h"
size_t malloc_object_size(void *ptr); size_t malloc_object_size(void *ptr);

View File

@ -1,7 +1,7 @@
#include <malloc.h> #include <malloc.h>
#include <stdlib.h> #include <stdlib.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(256 * 1024); char *p = malloc(256 * 1024);

View File

@ -1,7 +1,7 @@
#include <malloc.h> #include <malloc.h>
#include <stdlib.h> #include <stdlib.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(256 * 1024); char *p = malloc(256 * 1024);

View File

@ -1,7 +1,7 @@
#include <malloc.h> #include <malloc.h>
#include <stdlib.h> #include <stdlib.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(8); char *p = malloc(8);

View File

@ -1,7 +1,7 @@
#include <malloc.h> #include <malloc.h>
#include <stdlib.h> #include <stdlib.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(8); char *p = malloc(8);

View File

@ -2,7 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(256 * 1024); char *p = malloc(256 * 1024);

View File

@ -2,7 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(16); char *p = malloc(16);

View File

@ -1,7 +1,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(0); char *p = malloc(0);

View File

@ -1,38 +0,0 @@
delete_type_size_mismatch
double_free_large
double_free_large_delayed
double_free_small
double_free_small_delayed
invalid_free_protected
invalid_free_small_region
invalid_free_small_region_far
invalid_free_unprotected
read_after_free_large
read_after_free_small
read_zero_size
string_overflow
unaligned_free_large
unaligned_free_small
uninitialized_free
uninitialized_malloc_usable_size
uninitialized_realloc
write_after_free_large
write_after_free_large_reuse
write_after_free_small
write_after_free_small_reuse
write_zero_size
unaligned_malloc_usable_size_small
invalid_malloc_usable_size_small
invalid_malloc_usable_size_small_quarantine
malloc_object_size
malloc_object_size_offset
invalid_malloc_object_size_small
invalid_malloc_object_size_small_quarantine
impossibly_large_malloc
overflow_large_1_byte
overflow_large_8_byte
overflow_small_1_byte
overflow_small_8_byte
uninitialized_read_large
uninitialized_read_small
__pycache__/

View File

@ -1,59 +0,0 @@
dir=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
CONFIG_SLAB_CANARY := true
CXXFLAGS := -std=c++17 -fsized-deallocation
ifeq (,$(filter $(CONFIG_SLAB_CANARY),true false))
$(error CONFIG_SLAB_CANARY must be true or false)
endif
CPPFLAGS += -D_GNU_SOURCE \
-DSLAB_CANARY=$(CONFIG_SLAB_CANARY)
LDLIBS := -lhardened_malloc
LDFLAGS := -Wl,-L$(dir)../../out,-R,$(dir)../../out
EXECUTABLES := \
double_free_large \
double_free_large_delayed \
double_free_small \
double_free_small_delayed \
unaligned_free_large \
unaligned_free_small \
read_after_free_large \
read_after_free_small \
write_after_free_large \
write_after_free_large_reuse \
write_after_free_small \
write_after_free_small_reuse \
read_zero_size \
write_zero_size \
invalid_free_protected \
invalid_free_unprotected \
invalid_free_small_region \
invalid_free_small_region_far \
uninitialized_read_small \
uninitialized_read_large \
uninitialized_free \
uninitialized_realloc \
uninitialized_malloc_usable_size \
overflow_large_1_byte \
overflow_large_8_byte \
overflow_small_1_byte \
overflow_small_8_byte \
string_overflow \
delete_type_size_mismatch \
unaligned_malloc_usable_size_small \
invalid_malloc_usable_size_small \
invalid_malloc_usable_size_small_quarantine \
malloc_object_size \
malloc_object_size_offset \
invalid_malloc_object_size_small \
invalid_malloc_object_size_small_quarantine \
impossibly_large_malloc
all: $(EXECUTABLES)
clean:
rm -f $(EXECUTABLES)

View File

@ -4,7 +4,7 @@
#include <malloc.h> #include <malloc.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(16); char *p = malloc(16);

View File

@ -1,6 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(256 * 1024); char *p = malloc(256 * 1024);

View File

@ -1,6 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(16); char *p = malloc(16);

View File

@ -1,6 +1,6 @@
#include <malloc.h> #include <malloc.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(16); char *p = malloc(16);

View File

@ -1,6 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
free((void *)1); free((void *)1);

View File

@ -1,6 +1,6 @@
#include <malloc.h> #include <malloc.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
malloc_usable_size((void *)1); malloc_usable_size((void *)1);

View File

@ -1,6 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(256 * 1024); char *p = malloc(256 * 1024);

View File

@ -1,6 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(8); char *p = malloc(8);

View File

@ -1,6 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
void *p = realloc((void *)1, 16); void *p = realloc((void *)1, 16);

View File

@ -1,7 +1,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(256 * 1024); char *p = malloc(256 * 1024);

View File

@ -1,8 +1,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "../test_util.h" #include "test_util.h"
#include "../../util.h" #include "../util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(256 * 1024); char *p = malloc(256 * 1024);

View File

@ -1,7 +1,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(128); char *p = malloc(128);

View File

@ -1,8 +1,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "../test_util.h" #include "test_util.h"
#include "../../util.h" #include "../util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(128); char *p = malloc(128);

View File

@ -1,7 +1,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "../test_util.h" #include "test_util.h"
OPTNONE int main(void) { OPTNONE int main(void) {
char *p = malloc(0); char *p = malloc(0);