Refactor spectre.c and add multiple targets to the Makefile:
- GCC support - RETPOLINE for both GCC and clang - LLD dynamic linker to support RETPOLINE mitigations on dynamic executables - Results aggregation using SFTP
This commit is contained in:
119
Makefile
119
Makefile
@@ -1,7 +1,12 @@
|
||||
DEPENDENCIES= glibc-static
|
||||
.PHONY: clean build upload
|
||||
.SILENT:
|
||||
.NOTPARALLEL:
|
||||
|
||||
EXECUTABLES = clang gcc uuid rsync
|
||||
DEPENDENCIES := $(foreach exec,$(EXECUTABLES), $(if $(shell which $(exec) 2> /dev/null),X,$(error "No '$(exec)' in PATH, please install it and restart octopus !")))
|
||||
|
||||
|
||||
CC= clang
|
||||
### Generic flags
|
||||
PROG= spectre
|
||||
CFLAGS= -march=native
|
||||
CFLAGS+= -W
|
||||
@@ -9,36 +14,104 @@ CFLAGS+= -Wall
|
||||
CFLAGS+= -Werror
|
||||
CFLAGS+= -Wno-unused-parameter
|
||||
CFLAGS+= -Wno-missing-field-initializers
|
||||
LDFLAGS= -fuse-ld=lld
|
||||
|
||||
|
||||
### Octopus flags
|
||||
CCS= clang gcc
|
||||
OPTIMIZATIONS= 0 1 2 3
|
||||
LINKAGE= static
|
||||
RETPOLINE= mretpoline
|
||||
UUID= $(shell uuid)
|
||||
RESULTS_FILE= results-$(UUID).log
|
||||
SSH_KEY= octoupload
|
||||
TIMES= 1
|
||||
#FLAGS= -v
|
||||
|
||||
OPROGS= $(foreach O, $(OPTIMIZATIONS), $(addsuffix -O$(O), $(PROG)))
|
||||
PROGS+= $(OPROGS) $(foreach L, $(LINKAGE), $(addsuffix -$(L), $(foreach O, $(OPTIMIZATIONS), $(addsuffix -O$(O), $(PROG)))))
|
||||
### Octopus internals
|
||||
TEMP= $(shell mktemp)
|
||||
TEE= | tee -a $(TEMP)
|
||||
|
||||
.PHONY: clean
|
||||
.SILENT:
|
||||
.NOTPARALLEL:
|
||||
### Compilers
|
||||
CPROGS= $(foreach C, $(CCS), $(addsuffix -$(C), $(PROG)))
|
||||
|
||||
all: $(PROGS)
|
||||
echo -e "\033[1mCPU\t\t" $$(LC_ALL=en_US.UTF-8 lscpu | grep "Model name" | cut -d":" -f 2 | sort | uniq | awk '{$$1=$$1;print}')
|
||||
echo -e "Kernel\t\t" $$(uname -a)
|
||||
echo -e "Test date\t" $$(date "+%d-%m-%Y")
|
||||
echo -e "Clang\t\t" $$(clang -v 2>&1 | head -n 1)"\033[0m"
|
||||
### Optimizations
|
||||
OPROGS= $(foreach O, $(OPTIMIZATIONS), $(addsuffix -O$(O), $(CPROGS)))
|
||||
|
||||
### Static
|
||||
SPROGS= $(addsuffix -static, $(foreach O, $(OPTIMIZATIONS), $(addsuffix -O$(O), $(CPROGS))))
|
||||
|
||||
### Retpoline
|
||||
## clang
|
||||
# dynamic
|
||||
RCPROGS= $(addsuffix -retpoline, $(filter spectre-clang%, $(OPROGS)))
|
||||
# static
|
||||
RSCPROGS= $(addsuffix -retpoline, $(filter spectre-clang%, $(SPROGS)))
|
||||
## gcc
|
||||
# dynamic
|
||||
RGPROGS= $(addsuffix -retpoline, $(filter spectre-gcc%, $(OPROGS)))
|
||||
# static
|
||||
RSGPROGS= $(addsuffix -retpoline, $(filter spectre-gcc%, $(SPROGS)))
|
||||
|
||||
PROGS= $(OPROGS)
|
||||
PROGS+= $(SPROGS)
|
||||
PROGS+= $(RCPROGS)
|
||||
PROGS+= $(RSCPROGS)
|
||||
PROGS+= $(RGROGS)
|
||||
PROGS+= $(RSGPROGS)
|
||||
|
||||
|
||||
all: upload
|
||||
|
||||
upload: $(RESULTS_FILE)
|
||||
echo -e "\033[4mUploading $^ to www.sk4.nz\033[0m"
|
||||
sftp -b - -i $(SSH_KEY) -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
|
||||
octoupload@www.sk4.nz: <<< $$'put $^'
|
||||
|
||||
build: $(PROGS)
|
||||
|
||||
%.log: build
|
||||
echo -e "\033[1m\033[94m________ __";
|
||||
echo "\_____ \ _____/ |_ ____ ______ __ __ ______";
|
||||
echo " / | \_/ ___\ __\/ _ \\____ \| | \/ ___/";
|
||||
echo "/ | \ \___| | ( <_> ) |_> > | /\___ \ ";
|
||||
echo "\_______ /\___ >__| \____/| __/|____//____ >";
|
||||
echo -e " \/ \/ |__| \/\033[0m";
|
||||
echo -e " Samuel AUBERTIN - EURECOM\n"
|
||||
echo -e "\033[4mUUID\033[0m\t\t$(UUID)" $(TEE)
|
||||
echo -e "\033[4mCPU\033[0m\t\t"$$(LC_ALL=en_US.UTF-8 lscpu | grep "Model name" | cut -d":" -f 2 | sort | uniq | awk '{$$1=$$1;print}') $(TEE)
|
||||
echo -e "\033[4mMicrocode\033[0m\t"$$(grep microcode /proc/cpuinfo | sort | uniq | awk '{print $$NF}') $(TEE)
|
||||
echo -e "\033[4mKernel\033[0m\t\t"$$(uname -svm) $(TEE)
|
||||
echo -e "\033[4mKRETPOLINE\033[0m\t"$$(cat /boot/config-$$(uname -r) | grep RETPOLINE)
|
||||
echo -e "\033[4mClang\033[0m\t\t"$$(clang -v 2>&1 | head -n 1) $(TEE)
|
||||
echo -e "\033[4mGCC\033[0m\t\t"$$(gcc -v 2>&1 | grep 'gcc version') $(TEE)
|
||||
echo -e "\033[4mVulnerablities\033[0m" $(TEE)
|
||||
LC_ALL=en_US.UTF-8 lscpu | grep Vuln | awk '{s = ""; for(i = 2; i <= NF; i++) s = s $$i " "; print "\t\t" s }' $(TEE)
|
||||
echo
|
||||
taskset 01 ./$(firstword $(PROGS)) -c $(TEE); \
|
||||
for p in $(PROGS); do \
|
||||
sleep 1; \
|
||||
echo -e "\033[4m$$p\033[0m "; \
|
||||
taskset 01 ./$$p; \
|
||||
echo; done
|
||||
for t in $$(seq $(TIMES)); do \
|
||||
sleep 1; \
|
||||
taskset 01 ./$$p $(FLAGS) $(TEE); \
|
||||
done \
|
||||
done
|
||||
mv $(TEMP) $@
|
||||
|
||||
$(OPROGS):
|
||||
$(word 2, $(subst -, ,$@)) $(CFLAGS) $(LDFLAGS) -$(word 3, $(subst -, ,$@)) -o $@ $(PROG).c
|
||||
|
||||
$(foreach O, $(OPTIMIZATIONS), $(addsuffix -O$(O), $(PROG))):
|
||||
$(CC) $(CFLAGS) -$(word 2, $(subst -, ,$@)) -o $@ $(PROG).c
|
||||
$(SPROGS):
|
||||
$(word 2, $(subst -, ,$@)) $(addprefix -, $(word 4, $(subst -, ,$@))) $(CFLAGS) -$(word 3, $(subst -, ,$@)) -o $@ $(PROG).c
|
||||
|
||||
$(foreach L, $(LINKAGE), $(addsuffix -$(L), $(foreach O, $(OPTIMIZATIONS), $(addsuffix -O$(O), $(PROG))))):
|
||||
$(CC) $(addprefix -, $(word 3, $(subst -, ,$@))) $(CFLAGS) -$(word 2, $(subst -, ,$@)) -o $@ $(PROG).c
|
||||
$(RCPROGS):
|
||||
$(word 2, $(subst -, ,$@)) $(CFLAGS) -mretpoline $(LDFLAGS) -z retpolineplt -$(word 3, $(subst -, ,$@)) -o $@ $(PROG).c
|
||||
|
||||
$(RSCPROGS):
|
||||
$(word 2, $(subst -, ,$@)) $(addprefix -, $(word 4, $(subst -, ,$@))) $(CFLAGS) -mretpoline -$(word 3, $(subst -, ,$@)) -o $@ $(PROG).c
|
||||
|
||||
$(RGPROGS):
|
||||
$(word 2, $(subst -, ,$@)) $(CFLAGS) -mfunction-return=thunk -mindirect-branch=thunk -mindirect-branch-register $(LDFLAGS) -z retpolineplt -$(word 3, $(subst -, ,$@)) -o $@ $(PROG).c
|
||||
|
||||
$(RSGPROGS):
|
||||
$(word 2, $(subst -, ,$@)) $(addprefix -, $(word 4, $(subst -, ,$@))) $(CFLAGS) -mfunction-return=thunk -mindirect-branch=thunk -mindirect-branch-register -$(word 3, $(subst -, ,$@)) -o $@ $(PROG).c
|
||||
|
||||
clean:
|
||||
rm -rf $(PROGS)
|
||||
rm -rf $(PROGS) *.log
|
||||
|
||||
Reference in New Issue
Block a user