Skip to content

Commit 0fcd636

Browse files
Makefile: tools/check-postbuild.sh: add postbuild script
When compiling SYZOS into the executor binary, the compiler often attempts to emit a jump table, putting it into the data section of the executor. SYZOS is unable to access that data and crashes. Introduce a script that validates the arm64 executor by scanning its `guest` section for the ADRP instructions. In the future, this script can be extended to perform other types of checks.
1 parent 77908e5 commit 0fcd636

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ else
134134
$(CXX) -o ./bin/$(TARGETOS)_$(TARGETARCH)/syz-executor$(EXE) executor/executor.cc \
135135
$(ADDCXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -DGOOS_$(TARGETOS)=1 -DGOARCH_$(TARGETARCH)=1 \
136136
-DHOSTGOOS_$(HOSTOS)=1 -DGIT_REVISION=\"$(REV)\"
137+
tools/check-postbuild.sh $(TARGETOS) $(TARGETARCH) ./bin/$(TARGETOS)_$(TARGETARCH)/syz-executor$(EXE) $(CXX)
137138
endif
138139
endif
139140
endif

tools/check-postbuild.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
# Post-build validation for syzkaller binaries.
3+
4+
target_os="$1"; shift
5+
target_arch="$1"; shift
6+
executor_binary="$1"; shift
7+
cxx_binary="$1"; shift
8+
9+
function get_objdump_for_arm64() {
10+
local compiler_binary="$1"
11+
local objdump_binary=""
12+
13+
case "${compiler_binary}" in
14+
"aarch64-linux-gnu-g++")
15+
objdump_binary="aarch64-linux-gnu-objdump"
16+
;;
17+
"g++")
18+
objdump_binary="objdump"
19+
;;
20+
clang++-[0-9]*)
21+
# Extract the version number part
22+
version="${compiler_binary#clang++-}"
23+
objdump_binary="llvm-objdump-$version"
24+
;;
25+
"clang++")
26+
objdump_binary="llvm-objdump"
27+
;;
28+
*)
29+
# Default
30+
echo "Error: Unknown compiler binary '${compiler_binary}'" >&2
31+
objdump_binary=""
32+
;;
33+
esac
34+
35+
echo "${objdump_binary}"
36+
}
37+
38+
function validate_arm64_guest_code() {
39+
local section="guest"
40+
local objdump_bin=$(get_objdump_for_arm64 ${cxx_binary})
41+
local objdump_tmp=$(mktemp -t objdump_output.XXXXXX)
42+
trap "rm -f \"${objdump_tmp}\"" EXIT
43+
${objdump_bin} -d -j ${section} ${executor_binary} >${objdump_tmp} 2>&1 || exit 1
44+
( cat ${objdump_tmp} | grep "\<adrp\>" > /dev/null ) &&
45+
echo "Postbuild error: found ADRP in executor's '${section}' section!" && exit 1
46+
return 0
47+
}
48+
49+
# For now, we only validate Linux binaries.
50+
[ "${target_os}" != "linux" ] && exit 0
51+
52+
# For now, we only validate ARM64 binaries.
53+
[ "${target_arch}" != "arm64" ] && exit 0
54+
55+
validate_arm64_guest_code

0 commit comments

Comments
 (0)