Skip to content

Commit 72a8e6b

Browse files
committed
Adding checks for module level assembly
1 parent d8a7904 commit 72a8e6b

13 files changed

+115
-9
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CHECK: cc_plus_one_asm
2+
CHECK-NEXT: movl
3+
CHECK-NEXT: lfence
4+
CHECK-NEXT: inc
5+
CHECK-NEXT: notq (%rsp)
6+
CHECK-NEXT: notq (%rsp)
7+
CHECK-NEXT: lfence
8+
CHECK-NEXT: retq
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHECK: cmake_plus_one_asm
2+
CHECK-NEXT: movl
3+
CHECK-NEXT: lfence
4+
CHECK-NEXT: incl
5+
CHECK-NEXT: shlq $0, (%rsp)
6+
CHECK-NEXT: lfence
7+
CHECK-NEXT: retq
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CHECK: cmake_plus_one_c_global_asm
2+
CHECK: lfence
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CHECK: cmake_plus_one_cxx_global_asm
2+
CHECK: lfence

src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ fn main() {
33
.file("foo.c")
44
.compile("foo_c");
55

6+
cc::Build::new()
7+
.file("foo_asm.s")
8+
.compile("foo_asm");
9+
610
cc::Build::new()
711
.cpp(true)
812
.cpp_set_stdlib(None)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.text
2+
.global cc_plus_one_asm
3+
.type cc_plus_one_asm, @function
4+
cc_plus_one_asm:
5+
movl (%rdi), %eax
6+
inc %eax
7+
retq
Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,33 @@
1-
add_library(cmake_foo STATIC
1+
enable_language(C CXX ASM)
2+
3+
set(C_SOURCES
24
src/foo.c
5+
)
6+
7+
set_source_files_properties(${C_SOURCES}
8+
PROPERTIES
9+
LANGUAGE C)
10+
11+
set(CXX_SOURCES
312
src/foo_cxx.cpp
4-
)
13+
)
14+
15+
set_source_files_properties(${CXX_SOURCES}
16+
PROPERTIES
17+
LANGUAGE CXX)
18+
19+
set(ASM_SOURCES
20+
src/foo_asm.s
21+
)
22+
23+
set_source_files_properties(${ASM_SOURCES}
24+
PROPERTIES
25+
LANGUAGE ASM)
26+
27+
set(SOURCES
28+
${C_SOURCES}
29+
${CXX_SOURCES}
30+
${ASM_SOURCES})
31+
32+
add_library(cmake_foo STATIC
33+
${SOURCES})

src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave/libcmake_foo/src/foo.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ int cmake_plus_one_c_asm(int *arg) {
1515

1616
return value;
1717
}
18+
19+
asm(".text\n"
20+
" .global cmake_plus_one_c_global_asm\n"
21+
" .type cmake_plus_one_c_global_asm, @function\n"
22+
"cmake_plus_one_c_global_asm:\n"
23+
" movl (%rdi), %eax\n"
24+
" inc %eax\n"
25+
" retq\n" );
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.text
2+
.global cmake_plus_one_asm
3+
.type cmake_plus_one_asm, @function
4+
cmake_plus_one_asm:
5+
movl (%rdi), %eax
6+
inc %eax
7+
retq

src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave/libcmake_foo/src/foo_cxx.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ int cmake_plus_one_cxx_asm(int *arg) {
1818

1919
return value;
2020
}
21+
22+
asm(".text\n"
23+
" .global cmake_plus_one_cxx_global_asm\n"
24+
" .type cmake_plus_one_cxx_global_asm, @function\n"
25+
"cmake_plus_one_cxx_global_asm:\n"
26+
" movl (%rdi), %eax\n"
27+
" inc %eax\n"
28+
" retq\n" );
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,47 @@
1+
#![feature(global_asm)]
2+
3+
global_asm!( r#"
4+
.text
5+
.global rust_plus_one_global_asm
6+
.type rust_plus_one_global_asm, @function
7+
rust_plus_one_global_asm:
8+
movl (%rdi), %eax
9+
inc %eax
10+
retq
11+
"# );
12+
113
extern {
214
fn cc_plus_one_c(arg : &u32) -> u32;
315
fn cc_plus_one_c_asm(arg : &u32) -> u32;
416
fn cc_plus_one_cxx(arg : &u32) -> u32;
517
fn cc_plus_one_cxx_asm(arg : &u32) -> u32;
18+
fn cc_plus_one_asm(arg : &u32) -> u32;
619
fn cmake_plus_one_c(arg : &u32) -> u32;
720
fn cmake_plus_one_c_asm(arg : &u32) -> u32;
821
fn cmake_plus_one_cxx(arg : &u32) -> u32;
922
fn cmake_plus_one_cxx_asm(arg : &u32) -> u32;
23+
fn cmake_plus_one_c_global_asm(arg : &u32) -> u32;
24+
fn cmake_plus_one_cxx_global_asm(arg : &u32) -> u32;
25+
fn cmake_plus_one_asm(arg : &u32) -> u32;
26+
fn rust_plus_one_global_asm(arg : &u32) -> u32;
1027
}
1128

1229
fn main() {
1330
let value : u32 = 41;
1431

1532
unsafe{
33+
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", rust_plus_one_global_asm(&value));
1634
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cc_plus_one_c(&value));
1735
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cc_plus_one_c_asm(&value));
1836
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cc_plus_one_cxx(&value));
1937
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cc_plus_one_cxx_asm(&value));
20-
38+
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cc_plus_one_asm(&value));
2139
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cmake_plus_one_c(&value));
2240
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cmake_plus_one_c_asm(&value));
2341
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cmake_plus_one_cxx(&value));
2442
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cmake_plus_one_cxx_asm(&value));
43+
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cmake_plus_one_c_global_asm(&value));
44+
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cmake_plus_one_cxx_global_asm(&value));
45+
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cmake_plus_one_asm(&value));
2546
}
2647
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CHECK: rust_plus_one_global_asm
2+
CHECK: lfence

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ function build {
99
cp -a $TEST_DIR/enclave .
1010
pushd $CRATE
1111
echo ${WORK_DIR}
12-
hardening_flags="-mlvi-hardening -mllvm -x86-lvi-load-inline-asm"
1312
# HACK(eddyb) sets `RUSTC_BOOTSTRAP=1` so Cargo can accept nightly features.
1413
# These come from the top-level Rust workspace, that this crate is not a
1514
# member of, but Cargo tries to load the workspace `Cargo.toml` anyway.
@@ -39,17 +38,19 @@ build
3938
#check "libunwind::Registers_x86_64::jumpto()" jumpto.checks
4039

4140
check "std::io::stdio::_print::h87f0c238421c45bc" print.checks
42-
#TODO: the current passes cannot handle module level assembly!
43-
# No checks are implemented
41+
check rust_plus_one_global_asm rust_plus_one_global_asm.checks || echo "warning: module level assembly currently not hardened"
42+
4443
check cc_plus_one_c cc_plus_one_c.checks
4544
check cc_plus_one_c_asm cc_plus_one_c_asm.checks
4645
check cc_plus_one_cxx cc_plus_one_cxx.checks
4746
check cc_plus_one_cxx_asm cc_plus_one_cxx_asm.checks
47+
check cc_plus_one_asm cc_plus_one_asm.checks || echo "warning: the cc crate forwards assembly files to the CC compiler.\
48+
Clang uses its own intergrated assembler, which does not include the LVI passes."
4849

4950
check cmake_plus_one_c cmake_plus_one_c.checks
5051
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 || echo "warning: module level assembly currently not hardened"
5153
check cmake_plus_one_cxx cmake_plus_one_cxx.checks
5254
check cmake_plus_one_cxx_asm cmake_plus_one_cxx_asm.checks
53-
54-
#WARNING clang/clang++ use an integrated assembler when given an assembly file.
55-
# LVI patches are *not* applied
55+
check cmake_plus_one_cxx_global_asm cmake_plus_one_cxx_global_asm.checks || echo "warning: module level assembly currently not hardened"
56+
check cmake_plus_one_asm cmake_plus_one_asm.checks

0 commit comments

Comments
 (0)