-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose EGETKEY/EREPORT #15
Comments
@gnzlbg @alexcrichton I'd like your input on the design for additions to The Intel SGX instruction set extension adds a bunch of instructions. See Intel SDM, Volume 3, Chapter 40. There are 3 new opcodes for instructions
There might also be platform-dependent ways to call these leafs. Leafs that may be called from SGX applications:
I want to expose at least the There are no LLVM intrinsics for these instructions. Option 1. Add
|
I think the RFC for A couple of things. Automatic verification: all Testing: all stable I also have a question. Can fn main() {
if in_sgx_enclave() {
sgx_main()
} else {
non_sgx_main()
}
} ? And for example, compile it against If the answer is yes, then we are going to need |
@gnzlbg Thanks for your input.
I didn't realize Intel specified an intrinsic here. After looking at it, I have several concerns:
I don't think Travis supports VMs with Intel SGX enabled.
I'm not sure which of two different questions you're asking here. I've copied your first question here and rephrased your second question below. Question 1: "Can x86/x86_64 binaries that are not compiled for SGX contain code that uses encl{u,v,s} in the same binary ?"Yes, non-SGX applications can call SGX instructions. Ring0 code is by definition not an SGX application and can call all ENCLS and ENCLV leafs. As mentioned above, ring3 user code can call You would never do this: if is_x86_feature_detected!("sgx") {
enclu(...)
} You will always do something like this: if let Ok(dev) = File::open("/dev/sgx") {
enclu(...)
} Or more likely yet (Linux example): if let Ok(dev) = File::open("/dev/sgx") {
__vdso_sgx_enter_enclave(...)
} Question 2: Can the same application binary be run in both SGX and non-SGX mode?No. You have to compile to different targets and would use conditional compilation to distinguish. For example: fn main() {
#[cfg(target_env="sgx")] {
sgx_main()
}
#[cfg(not(target_env="sgx"))]{
non_sgx_main()
}
} |
I see, so I think we need a
This makes sense. Thank you for the answers. So I think you can send a PR to |
LLVM has an |
We can add multiple target features for this - the mapping from Rust to LLVM target features is customizable. In particular, we don't have to map a Rust target feature to any LLVM target feature if LLVM does not have one yet, but it might be worth it to open an LLVM issue in their bugzilla to ask about what their plans here are, and maybe for feedback about what should we do. In the mean time, the initial implementation would be unstable and feature gated, so we can feature gate the features as well, and revise this topic before stabilization once we have more experience, and maybe some feedback from LLVM upstream. |
In #15 (comment) I was proposing three different options, not 3 steps that would all be implemented. Sorry if this wasn't clear initially, I've edited it for clarity. |
I don't have much to add over @gnzlbg except to echo that if we can stick to the spec that'd be great because that's what we're trying to do for all other platforms and intrinsics! |
Ok, if you both feel strongly about adding the documented intrinsic regardless of the usability disadvantages that has we can go for it. |
@jethrogb we have exceptionally minimally changed the API of some intrinsics in the past that had a buggy API and the bug was acknowledge by Intel - these changes have been very minimal, e.g., an unsigned integer where the spec said a signed integer had to be used, etc. If you feel strongly about the Intel APIs being inadequate for your purposes, you might want to report the "bug" here: https://software.intel.com/en-us/forums/intel-isa-extensions/topic/363747 @alexcrichton point is that the rule is that we only expose the vendor APIs "as they designed", therefore, we are not designing anything, and adding stuff here doesn't really need an RFC, which speeds up the process a lot. So if exposing the Intel intrinsics in You have hinted that they might not really allow you to do that. And arguably, these are only three intrinsics that we can verify manually, and also arguably, your project is going to be its main user, so if they don't enable you to do what you need to do, then what's the point? If Intel acknowledges this in the bug report page, or if any other C compiler also deviates from the spec, then I'd say you'd have a pretty good case to deviate from the spec as well. This only matters when thinking about stabilization though, as long as this is unstable, we can tune the API of these intrinsics as they get used. |
I think I'll just go with option 3 for now while we coalesce on a design for intrinsics. I really don't think the 3 Intel-defined intrinsics are appropriate, because the leafs are so different and should really be considered different instructions. No other instructions that have defined intrinsics have this issue.
Features
Main instructions
Leaf instructionsNote regarding the register usage: pointer alignment requirements differ a lot based on the actual leaf instruction.
|
FWIW I think it should be possible for stable Rust code to use these intrinsics someday without having to use |
Add `io` and `arch` modules to `std::os::fortanix_sgx` This PR adds two more (unstable) modules to `std::os::fortanix_sgx` for the `x86_64-fortanix-unknown-sgx` target. ### io `io` allows conversion between raw file descriptors and Rust types, similar to `std::os::unix::io`. ### arch `arch` exposes the `ENCLU[EREPORT]` and `ENCLU[EGETKEY]` instructions. The current functions are very likely not going to be the final form of these functions (see also fortanix/rust-sgx#15), but this should be sufficient to enable experimentation in libraries. I tried using the actual types (from the [`sgx-isa` crate](https://crates.io/crates/sgx-isa)) instead of byte arrays, but that would make `std` dependent on the `bitflags` crate which I didn't want to do at this time.
These could be in
std::arch
orstd::os::sgx
.The text was updated successfully, but these errors were encountered: