Skip to content

Commit 0323704

Browse files
author
Jethro Beekman
committed
Manually patch ret instruction for LVI
1 parent 156fcf1 commit 0323704

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/probestack.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,16 @@ macro_rules! define_rust_probestack {
109109
//
110110
// The ABI here is that the stack frame size is located in `%rax`. Upon
111111
// return we're not supposed to modify `%rsp` or `%rax`.
112+
#[cfg(all(target_arch = "x86_64", not(all(target_env = "sgx", target_vendor = "fortanix"))))]
113+
macro_rules! ret ( () => ( "ret" ) );
114+
#[cfg(all(target_arch = "x86_64", all(target_env = "sgx", target_vendor = "fortanix")))]
115+
macro_rules! ret ( () => ( "
116+
pop %r11
117+
lfence
118+
jmp *%r11
119+
" ) );
112120
#[cfg(target_arch = "x86_64")]
113-
global_asm!(define_rust_probestack!(
121+
global_asm!(define_rust_probestack!(concat!(
114122
"
115123
.cfi_startproc
116124
pushq %rbp
@@ -158,10 +166,12 @@ global_asm!(define_rust_probestack!(
158166
leave
159167
.cfi_def_cfa_register %rsp
160168
.cfi_adjust_cfa_offset -8
161-
ret
169+
",
170+
ret!(),
171+
"
162172
.cfi_endproc
163173
"
164-
));
174+
)));
165175

166176
#[cfg(target_arch = "x86")]
167177
// This is the same as x86_64 above, only translated for 32-bit sizes. Note

0 commit comments

Comments
 (0)