Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bca8e07

Browse files
committedSep 25, 2020
rust inline assembly lvi hardening test
1 parent cd31f40 commit bca8e07

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
 
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Test LVI load hardening on SGX inline assembly code
2+
3+
// assembly-output: emit-asm
4+
// compile-flags: --crate-type staticlib
5+
// only-x86_64-fortanix-unknown-sgx
6+
7+
#![feature(asm)]
8+
9+
#[no_mangle]
10+
pub extern fn get(ptr: *const u64) -> u64 {
11+
let value : u64;
12+
unsafe {
13+
asm!(".start_inline_asm:",
14+
"mov {}, [{}]",
15+
".end_inline_asm:",
16+
out(reg) value,
17+
in(reg) ptr);
18+
}
19+
value
20+
}
21+
22+
// CHECK: get
23+
// CHECK: .start_inline_asm
24+
// CHECK-NEXT: movq
25+
// CHECK-NEXT: lfence
26+
// CHECK-NEXT: .end_inline_asm
27+
28+
#[no_mangle]
29+
pub extern fn myret() {
30+
unsafe {
31+
asm!(".start_myret_inline_asm:
32+
ret
33+
.end_myret_inline_asm:");
34+
}
35+
}
36+
37+
// CHECK: myret
38+
// CHECK: .start_myret_inline_asm
39+
// CHECK-NEXT: shlq $0, (%rsp)
40+
// CHECK-NEXT: lfence
41+
// CHECK-NEXT: retq

0 commit comments

Comments
 (0)
Please sign in to comment.