use minicore for fortanix assembly tests

This commit is contained in:
Folkert de Vries
2025-07-24 14:06:58 +02:00
parent d242a8bd5a
commit 91bccd6ba8
3 changed files with 46 additions and 27 deletions

View File

@@ -1,17 +1,24 @@
// Test LVI load hardening on SGX enclave code
// Test LVI load hardening on SGX enclave code, specifically that `ret` is rewritten.
//@ add-core-stubs
//@ assembly-output: emit-asm
//@ compile-flags: --crate-type staticlib
//@ only-x86_64-fortanix-unknown-sgx
//@ compile-flags: --target x86_64-fortanix-unknown-sgx -Copt-level=0
//@ needs-llvm-components: x86
#![feature(no_core, lang_items, f16)]
#![crate_type = "lib"]
#![no_core]
extern crate minicore;
use minicore::*;
#[no_mangle]
pub extern "C" fn plus_one(r: &mut u64) {
*r = *r + 1;
pub extern "C" fn dereference(a: &mut u64) -> u64 {
// CHECK-LABEL: dereference
// CHECK: lfence
// CHECK: mov
// CHECK: popq [[REGISTER:%[a-z]+]]
// CHECK-NEXT: lfence
// CHECK-NEXT: jmpq *[[REGISTER]]
*a
}
// CHECK: plus_one
// CHECK: lfence
// CHECK-NEXT: incq
// CHECK: popq [[REGISTER:%[a-z]+]]
// CHECK-NEXT: lfence
// CHECK-NEXT: jmpq *[[REGISTER]]

View File

@@ -1,12 +1,20 @@
// Test LVI ret hardening on generic rust code
//@ add-core-stubs
//@ assembly-output: emit-asm
//@ compile-flags: --crate-type staticlib
//@ only-x86_64-fortanix-unknown-sgx
//@ compile-flags: --target x86_64-fortanix-unknown-sgx
//@ needs-llvm-components: x86
#![feature(no_core, lang_items, f16)]
#![crate_type = "lib"]
#![no_core]
extern crate minicore;
use minicore::*;
#[no_mangle]
pub extern "C" fn myret() {}
// CHECK: myret:
// CHECK-LABEL: myret:
// CHECK: popq [[REGISTER:%[a-z]+]]
// CHECK-NEXT: lfence
// CHECK-NEXT: jmpq *[[REGISTER]]

View File

@@ -1,13 +1,22 @@
// Test LVI load hardening on SGX inline assembly code
//@ add-core-stubs
//@ assembly-output: emit-asm
//@ compile-flags: --crate-type staticlib
//@ only-x86_64-fortanix-unknown-sgx
//@ compile-flags: --target x86_64-fortanix-unknown-sgx
//@ needs-llvm-components: x86
use std::arch::asm;
#![feature(no_core, lang_items, f16)]
#![crate_type = "lib"]
#![no_core]
extern crate minicore;
use minicore::*;
#[no_mangle]
pub extern "C" fn get(ptr: *const u64) -> u64 {
// CHECK-LABEL: get
// CHECK: movq
// CHECK-NEXT: lfence
let value: u64;
unsafe {
asm!("mov {}, [{}]",
@@ -17,18 +26,13 @@ pub extern "C" fn get(ptr: *const u64) -> u64 {
value
}
// CHECK: get
// CHECK: movq
// CHECK-NEXT: lfence
#[no_mangle]
pub extern "C" fn myret() {
// CHECK-LABEL: myret
// CHECK: shlq $0, (%rsp)
// CHECK-NEXT: lfence
// CHECK-NEXT: retq
unsafe {
asm!("ret");
}
}
// CHECK: myret
// CHECK: shlq $0, (%rsp)
// CHECK-NEXT: lfence
// CHECK-NEXT: retq