-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
142 lines (104 loc) · 5.25 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# PT privesc exploit
cpu-clock := 2GHz
memsize := 200MB
# benchmarks
# cpu-clock := 3GHz
# memsize := 1GB
args := --mem-size "$(memsize)" --cpu-clock "$(cpu-clock)" --caches --num-cpus 4 --mem-type=DRAMsim3
# Make saving multiple checkpoints with differing memory sizes possible.
outdir := "m5out-$(memsize)"
gem5_args += --outdir="$(outdir)"
# Debugging flags:
# specify with eg make se DEBUG=Uart
ifdef DEBUG
# debug to file
# args += --debug-file=debug
gem5_args += --debug-flags="$(DEBUG)"
endif
fs-args := $(args) --kernel=./img/x86-linux-kernel-5.4.49 --disk-image=./img/x86-ubuntu-18.04-patched.img --disk-image=./build/tmp.img
se-args := $(args) --cpu-type=X86AtomicSimpleCPU --repeat-switch 1
################################################################################
TARGET_ISA=x86
GEM5_HOME=$(realpath ./gem5)
$(info GEM5_HOME is $(GEM5_HOME))
CFLAGS += -static -Wall -O2 -I.
LDFLAGS += -Lbuild -lswapcpu -L$(GEM5_HOME)/util/m5/build/$(TARGET_ISA)/out -lm5
CC=gcc
CXX=g++
################################################################################
# This builds gem5.opt with dramsim3.
hammulator: dramsim3 m5
yes | scons -C gem5 build/X86/gem5.opt -j$(shell nproc)
# NOTE: Use this when developing for faster linkage.
# requires the mold linker
hammulator-mold: dramsim3 m5
yes | scons -C gem5 --linker=mold build/X86/gem5.opt -j$(shell nproc)
# This builds m5term and the cpu swapping libraries.
m5:
scons -C gem5/util/m5 build/x86/out/m5
build/libswapcpu.o: libswapcpu.c m5
$(CXX) -c -fPIC libswapcpu.c -o build/libswapcpu.o -I$(GEM5_HOME)/include -I$(GEM5_HOME)/util/m5/src $(CFLAGS)
build/libswapcpu.a: build/libswapcpu.o
ar rcs build/libswapcpu.a build/libswapcpu.o
dramsim3:
cmake -S gem5/ext/dramsim3/DRAMsim3 -B gem5/ext/dramsim3/DRAMsim3/build
make -C gem5/ext/dramsim3/DRAMsim3/build -j$(shell nproc)
compile_commands:
yes | scons -C gem5 build/X86/compile_commands.json -j$(shell nproc)
################################################################################
fix_perf:
sudo sysctl -w kernel.perf_event_paranoid=1
################################################################################
# A simple binary that tests for Rowhammer bit flips.
build/tmp_root/verify: progs/verify/verify.c build/libswapcpu.a
mkdir -p build/tmp_root
$(CXX) -o build/tmp_root/verify progs/verify/verify.c $(CFLAGS) $(LDFLAGS)
# The privelege escalation binary for the page table exploit by Google Project Zero.
build/tmp_root/priv: progs/privesc/privesc.cc build/libswapcpu.a
mkdir -p build/tmp_root
$(CXX) -o build/tmp_root/priv progs/privesc/privesc.cc $(CFLAGS) $(LDFLAGS)
# The target program for the page table privelege escalation exploit by Google Project Zero.
build/tmp_root/target_prog: progs/privesc/target_prog.c
mkdir -p build/tmp_root
# NOTE: static linkage is important for this binary since load_start=0x400000 in pt code
$(CC) -o build/tmp_root/target_prog progs/privesc/target_prog.c $(CFLAGS) $(LDFLAGS)
build/tmp_root/rsa: progs/tiny-bignum-c/tests/rsa.c
mkdir -p build/tmp_root
$(CC) -o build/tmp_root/rsa progs/tiny-bignum-c/tests/rsa.c progs/tiny-bignum-c/bn.c -Iprogs/tiny-bignum-c $(CFLAGS) $(LDFLAGS)
build/tmp_root/rsa-public: progs/tiny-bignum-c/tests/rsa-public.c
mkdir -p build/tmp_root
$(CC) -o build/tmp_root/rsa-public progs/tiny-bignum-c/tests/rsa-public.c progs/tiny-bignum-c/bn.c -Iprogs/tiny-bignum-c $(CFLAGS) $(LDFLAGS)
comp: build/tmp_root/verify build/tmp_root/priv build/tmp_root/target_prog
build/tmp.img: comp
mkdir -p build/tmp_root
cp img/tmp_root/* build/tmp_root/
genext2fs -b 524288 --root build/tmp_root build/tmp.img
################################################################################
# NOTE: img checkpoint needs recreation when ubuntu img changes
fs-create-checkpoint: build/tmp.img
rm -rf "$(outdir)"
# TODO: why does kvm not work here?
build/X86/gem5.opt $(gem5_args) gem5/configs/example/fs.py $(fs-args) --cpu-type=X86AtomicSimpleCPU --checkpoint-at-end
# NOTE: it may be that this only works with intel cpus
fs-restore: build/tmp.img
build/X86/gem5.opt $(gem5_args) gem5/configs/example/fs.py $(fs-args) --cpu-type=X86KvmCPU -r 1 --restore-with-cpu=X86KvmCPU --repeat-switch 1
verify: build/tmp_root/verify
build/X86/gem5.opt $(gem5_args) gem5/configs/example/se.py $(se-args) --cmd=build/tmp_root/verify
rsa: build/tmp_root/rsa
build/X86/gem5.opt $(gem5_args) gem5/configs/example/se.py $(se-args) --cmd=build/tmp_root/rsa
rsa-public: build/tmp_root/rsa-public
build/X86/gem5.opt $(gem5_args) gem5/configs/example/se.py $(se-args) --cmd=build/tmp_root/rsa-public
se:
build/X86/gem5.opt $(gem5_args) gem5/configs/example/se.py $(se-args) --cmd="$(CMD)"
kvm: build/tmp.img
build/X86/gem5.opt $(gem5_args) gem5/configs/example/fs.py --cpu-type=X86KvmCPU --caches -n 8 --kernel=./x86-linux-kernel-5.4.49 --disk-image=img/spec-2017-patched --disk-image=./build/tmp.img --script img/sleep.sh
################################################################################
fs-help:
build/X86/gem5.opt $(gem5_args) gem5/configs/example/fs.py --help | less
se-help:
build/X86/gem5.opt $(gem5_args) gem5/configs/example/se.py --help | less
################################################################################
clean:
rm -rf build
rm -rf gem5/util/m5/build
rm -rf gem5/ext/dramsim3/DRAMsim3/build