Skip to content

Commit cfd8105

Browse files
authored
Rollup merge of #108986 - fortanix:raoul/sync_lvi_patches, r=cuviper
sync LVI tests The LVI tests for the `x86_64-fortanix-unknown-sgx` target have gotten out of sync. LVI is still mitigated correctly, but the LVI tests need minor modifications. Other (non LVI-related) tests fail when the target applies LVI mitigations as they assume the generated code contains forbidden instructions such as `retq`. These tests are ignored for the sgx environment. cc: `@jethrogb`
2 parents eb82a5a + d69ebf7 commit cfd8105

11 files changed

+48
-39
lines changed

tests/assembly/is_aligned.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// assembly-output: emit-asm
22
// min-llvm-version: 15.0
33
// only-x86_64
4+
// ignore-sgx
45
// revisions: opt-speed opt-size
56
// [opt-speed] compile-flags: -Copt-level=1
67
// [opt-size] compile-flags: -Copt-level=s

tests/assembly/strict_provenance.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// assembly-output: emit-asm
22
// compile-flags: -Copt-level=1
33
// only-x86_64
4+
// ignore-sgx
45
// min-llvm-version: 15.0
56
#![crate_type = "rlib"]
67

tests/assembly/x86_64-floating-point-clamp.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// assembly-output: emit-asm
55
// compile-flags: --crate-type=lib -O -C llvm-args=-x86-asm-syntax=intel
66
// only-x86_64
7+
// ignore-sgx
78

89
// CHECK-LABEL: clamp_demo:
910
#[no_mangle]

tests/assembly/x86_64-fortanix-unknown-sgx-lvi-generic-load.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub extern fn plus_one(r: &mut u64) {
1111

1212
// CHECK: plus_one
1313
// CHECK: lfence
14-
// CHECK-NEXT: addq
14+
// CHECK-NEXT: incq
1515
// CHECK: popq [[REGISTER:%[a-z]+]]
1616
// CHECK-NEXT: lfence
1717
// CHECK-NEXT: jmpq *[[REGISTER]]

tests/assembly/x86_64-fortanix-unknown-sgx-lvi-inline-assembly.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,25 @@ use std::arch::asm;
1010
pub extern "C" fn get(ptr: *const u64) -> u64 {
1111
let value: u64;
1212
unsafe {
13-
asm!(".start_inline_asm:",
14-
"mov {}, [{}]",
15-
".end_inline_asm:",
13+
asm!("mov {}, [{}]",
1614
out(reg) value,
1715
in(reg) ptr);
1816
}
1917
value
2018
}
2119

2220
// CHECK: get
23-
// CHECK: .start_inline_asm
24-
// CHECK-NEXT: movq
21+
// CHECK: movq
2522
// CHECK-NEXT: lfence
26-
// CHECK-NEXT: .end_inline_asm
2723

2824
#[no_mangle]
2925
pub extern "C" fn myret() {
3026
unsafe {
31-
asm!(
32-
".start_myret_inline_asm:",
33-
"ret",
34-
".end_myret_inline_asm:",
35-
);
27+
asm!("ret");
3628
}
3729
}
3830

3931
// CHECK: myret
40-
// CHECK: .start_myret_inline_asm
41-
// CHECK-NEXT: shlq $0, (%rsp)
32+
// CHECK: shlq $0, (%rsp)
4233
// CHECK-NEXT: lfence
4334
// CHECK-NEXT: retq

tests/assembly/x86_64-no-jump-tables.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// compile-flags: -O
77
// [set] compile-flags: -Zno-jump-tables
88
// only-x86_64
9+
// ignore-sgx
910

1011
#![crate_type = "lib"]
1112

tests/run-make/issue-36710/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# ignore-nvptx64-nvidia-cuda FIXME: can't find crate for `std`
55
# ignore-musl FIXME: this makefile needs teaching how to use a musl toolchain
66
# (see dist-i586-gnu-i586-i686-musl Dockerfile)
7+
# ignore-sgx
78

89
include ../../run-make-fulldeps/tools.mk
910

Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
CHECK: cc_plus_one_asm
22
CHECK-NEXT: movl
33
CHECK-NEXT: lfence
4-
CHECK-NEXT: inc
5-
CHECK-NEXT: notq (%rsp)
6-
CHECK-NEXT: notq (%rsp)
4+
CHECK-NEXT: incl
5+
CHECK-NEXT: shlq $0, (%rsp)
76
CHECK-NEXT: lfence
87
CHECK-NEXT: retq
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1-
CHECK: libunwind::Registers_x86_64::jumpto
1+
CHECK: __libunwind_Registers_x86_64_jumpto
22
CHECK: lfence
33
CHECK: lfence
44
CHECK: lfence
55
CHECK: lfence
6-
CHECK: shlq $0, (%rsp)
6+
CHECK: lfence
7+
CHECK: lfence
8+
CHECK: lfence
9+
CHECK: lfence
10+
CHECK: lfence
11+
CHECK: lfence
12+
CHECK: lfence
13+
CHECK: lfence
14+
CHECK: lfence
15+
CHECK: lfence
16+
CHECK: lfence
17+
CHECK: lfence
18+
CHECK: lfence
19+
CHECK: lfence
20+
CHECK-NEXT: popq [[REGISTER:%[a-z]+]]
21+
CHECK-NEXT: lfence
22+
CHECK-NEXT: popq [[REGISTER:%[a-z]+]]
723
CHECK-NEXT: lfence
8-
CHECK-NEXT: retq
24+
CHECK-NEXT: jmpq *[[REGISTER]]

tests/run-make/x86_64-fortanix-unknown-sgx-lvi/print.checks

-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ CHECK: print
22
CHECK: lfence
33
CHECK: lfence
44
CHECK: lfence
5-
CHECK: popq
65
CHECK: callq 0x{{[[:xdigit:]]*}} <_Unwind_Resume>
76
CHECK-NEXT: ud2

tests/run-make/x86_64-fortanix-unknown-sgx-lvi/script.sh

+17-18
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,38 @@ function build {
2020
}
2121

2222
function check {
23-
local func=$1
23+
local func_re="$1"
2424
local checks="${TEST_DIR}/$2"
2525
local asm=$(mktemp)
26-
local objdump="${BUILD_DIR}/x86_64-unknown-linux-gnu/llvm/build/bin/llvm-objdump"
27-
local filecheck="${BUILD_DIR}/x86_64-unknown-linux-gnu/llvm/build/bin/FileCheck"
28-
29-
${objdump} --disassemble-symbols=${func} --demangle \
30-
${WORK_DIR}/enclave/target/x86_64-fortanix-unknown-sgx/debug/enclave > ${asm}
26+
local objdump="${LLVM_BIN_DIR}/llvm-objdump"
27+
local filecheck="${LLVM_BIN_DIR}/FileCheck"
28+
local enclave=${WORK_DIR}/enclave/target/x86_64-fortanix-unknown-sgx/debug/enclave
29+
30+
func="$(${objdump} --syms --demangle ${enclave} | \
31+
grep --only-matching -E "[[:blank:]]+${func_re}\$" | \
32+
sed -e 's/^[[:space:]]*//' )"
33+
${objdump} --disassemble-symbols="${func}" --demangle \
34+
${enclave} > ${asm}
3135
${filecheck} --input-file ${asm} ${checks}
3236
}
3337

3438
build
3539

36-
check unw_getcontext unw_getcontext.checks
37-
check "libunwind::Registers_x86_64::jumpto()" jumpto.checks
38-
check "std::io::stdio::_print::h87f0c238421c45bc" print.checks
39-
check rust_plus_one_global_asm rust_plus_one_global_asm.checks \
40-
|| echo "warning: module level assembly currently not hardened"
40+
check "unw_getcontext" unw_getcontext.checks
41+
check "__libunwind_Registers_x86_64_jumpto" jumpto.checks
42+
check 'std::io::stdio::_print::[[:alnum:]]+' print.checks
43+
check rust_plus_one_global_asm rust_plus_one_global_asm.checks
4144

4245
check cc_plus_one_c cc_plus_one_c.checks
4346
check cc_plus_one_c_asm cc_plus_one_c_asm.checks
4447
check cc_plus_one_cxx cc_plus_one_cxx.checks
4548
check cc_plus_one_cxx_asm cc_plus_one_cxx_asm.checks
46-
check cc_plus_one_asm cc_plus_one_asm.checks \
47-
|| echo "warning: the cc crate forwards assembly files to the CC compiler." \
48-
"Clang uses its own integrated assembler, which does not include the LVI passes."
49+
check cc_plus_one_asm cc_plus_one_asm.checks
4950

5051
check cmake_plus_one_c cmake_plus_one_c.checks
5152
check cmake_plus_one_c_asm cmake_plus_one_c_asm.checks
52-
check cmake_plus_one_c_global_asm cmake_plus_one_c_global_asm.checks \
53-
|| echo "warning: module level assembly currently not hardened"
53+
check cmake_plus_one_c_global_asm cmake_plus_one_c_global_asm.checks
5454
check cmake_plus_one_cxx cmake_plus_one_cxx.checks
5555
check cmake_plus_one_cxx_asm cmake_plus_one_cxx_asm.checks
56-
check cmake_plus_one_cxx_global_asm cmake_plus_one_cxx_global_asm.checks \
57-
|| echo "warning: module level assembly currently not hardened"
56+
check cmake_plus_one_cxx_global_asm cmake_plus_one_cxx_global_asm.checks
5857
check cmake_plus_one_asm cmake_plus_one_asm.checks

0 commit comments

Comments
 (0)