Skip to content

Commit e4e032a

Browse files
committed
Auto merge of #60027 - jethrogb:jb/sgx-reentry-abort, r=cramertj
SGX target: change re-entry abort logic Even though re-entry after exit is generally not acceptable, there is a race condition where the enclave thinks it's exited but userspace doesn't know that yet. An entry during that time will currently result in an enclave panic (see #59997 (comment), #60003 (comment)). Instead of panicking, just do a regular exit on re-entry. cc @jseyfried
2 parents 258e3b3 + d0a1c2d commit e4e032a

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

src/libstd/sys/sgx/abi/entry.S

+3-11
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ IMAGE_BASE:
6565
/* The size in bytes of enclacve EH_FRM_HDR section */
6666
globvar EH_FRM_HDR_SIZE 8
6767

68-
.Lreentry_panic_msg:
69-
.asciz "Re-entered aborted enclave!"
70-
.Lreentry_panic_msg_end:
71-
7268
.org .Lxsave_clear+512
7369
.Lxsave_header:
7470
.int 0, 0 /* XSTATE_BV */
@@ -210,10 +206,8 @@ sgx_entry:
210206
/* end sgx_entry */
211207

212208
.Lreentry_panic:
213-
lea .Lreentry_panic_msg(%rip),%rdi
214-
mov $.Lreentry_panic_msg_end-.Lreentry_panic_msg,%esi
215209
orq $8,%rsp
216-
jmp panic_msg
210+
jmp abort_reentry
217211

218212
/* This *MUST* be called with 6 parameters, otherwise register information */
219213
/* might leak! */
@@ -279,10 +273,8 @@ usercall:
279273
/*
280274
The following functions need to be defined externally:
281275
```
282-
// Called by entry code when it needs to panic
283-
extern "C" fn panic_msg(msg: &'static str) -> ! {
284-
panic!(msg)
285-
}
276+
// Called by entry code on re-entry after exit
277+
extern "C" fn abort_reentry() -> !;
286278
287279
// Called once when a TCS is first entered
288280
extern "C" fn tcs_init(secondary: bool);

src/libstd/sys/sgx/abi/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ unsafe extern "C" fn tcs_init(secondary: bool) {
2929
static RELOC_STATE: AtomicUsize = AtomicUsize::new(UNINIT);
3030

3131
if secondary && RELOC_STATE.load(Ordering::Relaxed) != DONE {
32-
panic::panic_msg("Entered secondary TCS before main TCS!")
32+
rtabort!("Entered secondary TCS before main TCS!")
3333
}
3434

3535
// Try to atomically swap UNINIT with BUSY. The returned state can be:
@@ -92,3 +92,9 @@ pub(super) fn exit_with_code(code: isize) -> ! {
9292
}
9393
usercalls::exit(code != 0);
9494
}
95+
96+
#[cfg(not(test))]
97+
#[no_mangle]
98+
extern "C" fn abort_reentry() -> ! {
99+
usercalls::exit(false)
100+
}

src/libstd/sys/sgx/abi/panic.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::usercalls::{alloc::UserRef, self};
1+
use super::usercalls::alloc::UserRef;
22
use crate::cmp;
33
use crate::io::{self, Write};
44
use crate::mem;
@@ -48,9 +48,3 @@ impl Write for SgxPanicOutput {
4848
Ok(())
4949
}
5050
}
51-
52-
#[cfg_attr(not(test), no_mangle)]
53-
pub extern "C" fn panic_msg(msg: &str) -> ! {
54-
let _ = SgxPanicOutput::new().map(|mut out| out.write(msg.as_bytes()));
55-
usercalls::exit(true)
56-
}

0 commit comments

Comments
 (0)