2024-02-27 09:29:10 -06:00
|
|
|
#!/bin/bash
|
2020-03-26 04:51:14 -05:00
|
|
|
set -exuo pipefail
|
|
|
|
|
|
|
|
function build {
|
|
|
|
CRATE=enclave
|
|
|
|
|
2024-02-27 09:29:10 -06:00
|
|
|
mkdir -p "${WORK_DIR}"
|
|
|
|
pushd "${WORK_DIR}"
|
|
|
|
rm -rf "${CRATE}"
|
|
|
|
cp -a "${TEST_DIR}"/enclave .
|
2020-03-26 04:51:14 -05:00
|
|
|
pushd $CRATE
|
2024-02-27 09:29:10 -06:00
|
|
|
echo "${WORK_DIR}"
|
2020-03-26 04:51:14 -05:00
|
|
|
# HACK(eddyb) sets `RUSTC_BOOTSTRAP=1` so Cargo can accept nightly features.
|
|
|
|
# These come from the top-level Rust workspace, that this crate is not a
|
|
|
|
# member of, but Cargo tries to load the workspace `Cargo.toml` anyway.
|
2020-03-26 07:57:37 -05:00
|
|
|
env RUSTC_BOOTSTRAP=1
|
2024-02-27 09:29:10 -06:00
|
|
|
cargo -v run --target "${TARGET}"
|
2020-03-26 04:51:14 -05:00
|
|
|
popd
|
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
|
|
|
function check {
|
2023-02-22 06:29:12 -06:00
|
|
|
local func_re="$1"
|
2020-03-26 04:51:14 -05:00
|
|
|
local checks="${TEST_DIR}/$2"
|
2024-02-27 09:29:10 -06:00
|
|
|
local asm=""
|
2023-02-22 06:29:12 -06:00
|
|
|
local objdump="${LLVM_BIN_DIR}/llvm-objdump"
|
|
|
|
local filecheck="${LLVM_BIN_DIR}/FileCheck"
|
|
|
|
local enclave=${WORK_DIR}/enclave/target/x86_64-fortanix-unknown-sgx/debug/enclave
|
|
|
|
|
2024-02-27 09:29:10 -06:00
|
|
|
asm=$(mktemp)
|
|
|
|
func="$(${objdump} --syms --demangle "${enclave}" | \
|
2023-02-22 06:29:12 -06:00
|
|
|
grep --only-matching -E "[[:blank:]]+${func_re}\$" | \
|
|
|
|
sed -e 's/^[[:space:]]*//' )"
|
|
|
|
${objdump} --disassemble-symbols="${func}" --demangle \
|
2024-02-27 09:29:10 -06:00
|
|
|
"${enclave}" > "${asm}"
|
|
|
|
${filecheck} --input-file "${asm}" "${checks}"
|
2023-06-05 08:10:03 -05:00
|
|
|
|
2024-02-27 09:29:21 -06:00
|
|
|
if [ "${func_re}" != "rust_plus_one_global_asm" ] &&
|
|
|
|
[ "${func_re}" != "cmake_plus_one_c_global_asm" ] &&
|
|
|
|
[ "${func_re}" != "cmake_plus_one_cxx_global_asm" ]; then
|
2023-06-05 08:10:03 -05:00
|
|
|
# The assembler cannot avoid explicit `ret` instructions. Sequences
|
|
|
|
# of `shlq $0x0, (%rsp); lfence; retq` are used instead.
|
|
|
|
# https://www.intel.com/content/www/us/en/developer/articles/technical/
|
|
|
|
# software-security-guidance/technical-documentation/load-value-injection.html
|
2024-02-27 09:29:10 -06:00
|
|
|
${filecheck} --implicit-check-not ret --input-file "${asm}" "${checks}"
|
2023-06-05 08:10:03 -05:00
|
|
|
fi
|
2020-03-26 04:51:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
build
|
|
|
|
|
2023-02-22 06:29:12 -06:00
|
|
|
check "unw_getcontext" unw_getcontext.checks
|
|
|
|
check "__libunwind_Registers_x86_64_jumpto" jumpto.checks
|
2024-02-27 09:29:21 -06:00
|
|
|
check 'std::io::stdio::_print::[[:alnum:]]+' print.with_frame_pointers.checks ||
|
|
|
|
check 'std::io::stdio::_print::[[:alnum:]]+' print.without_frame_pointers.checks
|
2023-02-22 06:29:12 -06:00
|
|
|
check rust_plus_one_global_asm rust_plus_one_global_asm.checks
|
2020-03-27 09:48:10 -05:00
|
|
|
|
2020-03-26 07:57:37 -05:00
|
|
|
check cc_plus_one_c cc_plus_one_c.checks
|
2020-03-26 09:05:43 -05:00
|
|
|
check cc_plus_one_c_asm cc_plus_one_c_asm.checks
|
2020-03-27 05:24:17 -05:00
|
|
|
check cc_plus_one_cxx cc_plus_one_cxx.checks
|
|
|
|
check cc_plus_one_cxx_asm cc_plus_one_cxx_asm.checks
|
2023-02-22 06:29:12 -06:00
|
|
|
check cc_plus_one_asm cc_plus_one_asm.checks
|
2020-03-27 08:19:07 -05:00
|
|
|
|
|
|
|
check cmake_plus_one_c cmake_plus_one_c.checks
|
|
|
|
check cmake_plus_one_c_asm cmake_plus_one_c_asm.checks
|
2023-02-22 06:29:12 -06:00
|
|
|
check cmake_plus_one_c_global_asm cmake_plus_one_c_global_asm.checks
|
2020-03-27 08:19:07 -05:00
|
|
|
check cmake_plus_one_cxx cmake_plus_one_cxx.checks
|
|
|
|
check cmake_plus_one_cxx_asm cmake_plus_one_cxx_asm.checks
|
2023-02-22 06:29:12 -06:00
|
|
|
check cmake_plus_one_cxx_global_asm cmake_plus_one_cxx_global_asm.checks
|
2020-03-27 09:48:10 -05:00
|
|
|
check cmake_plus_one_asm cmake_plus_one_asm.checks
|