Closed mzohreva closed 10 months ago
Is there no way to automatically recover the base image address in this scenario?
Is there no way to automatically recover the base image address in this scenario?
No, due to ASLR the base address changes every time the enclave is loaded into memory.
Then how does std know? Apologies if this is an obvious/silly question, I am not familiar with the particulars of the SGX target, as opposed to my familiarity with x86.
Then how does std know? Apologies if this is an obvious/silly question, I am not familiar with the particulars of the SGX target, as opposed to my familiarity with x86.
The relevant code is here: https://github.com/rust-lang/rust/blob/1.72.1/library/std/src/sys/sgx/abi/mem.rs#L37 it's using inline assembly (that's why I don't think it's a good idea to duplicate that code in this crate or elsewhere)
I see.
// Do not remove inline: will result in relocation failure
That... seems like a compiler bug? Is there a bug tracking this concern?
Can you mark the exposed APIs #[doc(hidden)]
? I want to retain plausible deniability about whether this is a sanctioned usage of this crate, here.
I see.
// Do not remove inline: will result in relocation failure
That... seems like a compiler bug? Is there a bug tracking this concern?
I'm not aware. @jethrogb might know.
Can you mark the exposed APIs
#[doc(hidden)]
? I want to retain plausible deniability about whether this is a sanctioned usage of this crate, here.
Sure, I'll update the PR
With that, happy to merge this once the question about the relocation thing is settled. Maybe it's a bug but unfixable? Either way, I'd like to know so I'm sure there's no loose ends, or er... more like the loose ends are properly loosened? I don't know.
SGX doesn't have a dynamic loader, so the Rust entry code needs to do the relocations manually. Any code that's used to compute the relocations (which includes fn image_base()
) shouldn't itself contain relocations.
Oh, I see!
That's kinda wild.
@workingjubilee the CI failures seem unrelated to the changes, is there a separate effort to address those? How should we proceed with this PR?
Code size changes for a hello-world Rust program linked with libstd with backtrace:
On platform ubuntu-latest
:
The backtraces printed by
panic!
are broken in SGX, this PR is a prerequisite for fixing the issue in the standard library.The SGX-only API added in this PR (
backtrace::set_image_base
) enables the standard library to set the correct image base address before callingtrace_unsynchronized
here: https://github.com/rust-lang/rust/blob/1.72.1/library/std/src/sys_common/backtrace.rs#L65.cc @jethrogb