-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Check if TCS is a null pointer on SGX #101442
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @thomcc (rust-highfive has picked a reviewer for you, use r? to override) |
I don't think this check is necessary. You mention well-defined runners, but that doesn't really matter. The question is about well-defined enclaves, and those will never have a TCS at 0. |
I don't know whether or not it's needed, but this changes us from assuming an external C function returns a Whether or not it's possible might matter for prioritization (since it's not actually a soundness fix if it was impossible), but I'm in favor either way. @bors r+ |
📌 Commit 4f157dac10506393e806c25eb951f83a381598a4 has been approved by It is now in the queue for this repository. |
@thomcc have you verified it's safe to panic in this context? If not, please r-. In general, perhaps defer to platform maintainers on platform-specific code. |
Fair enough. @bors r- |
Actually, the panic can only happen in the case we returned a NonNull that was actually null, which would be UB as well, so I think a panic is very easily justified. |
AFAICT it should be fine to panic in the places where this is called, and if the call truly cannot return null then it doesn't matter if we panic. Note that we'd prefer to panic over UB even if it's only possible due to a buggy or incorrectly configured system -- on other targets this sort of caution this has caught issues that show up in emulation, for example. |
Ok, I've now gone through a bit of the SGX tooling. IIUC (this is just me taking notes), each enclave is fitted with a fixed number of TCS structures upon conversion of the output ELF to SGXS (sort of like ELF, but for SGX), which are never placed at address zero in the enclave. This layout is part of the enclave signature, so misbehaving runners that try to change this will change the enclave signature and will thus be caught. Therefore, this is not unsound (sorry for jumping to wrong conclusions here). Still, as @thomcc mentioned, the check is cheap and perhaps this will catch some issues in the future... @rustbot label -I-unsound -I-prioritise [ahem!] |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
I think it may be ok to unwind, but it's being called next to code that definitely shouldn't unwind. Perhaps use rtunwrap to be safe. Also reword the error message. |
@rustbot author |
4f157da
to
2fa5808
Compare
@rustbot label +S-waiting-on-review -S-waiting-on-author |
Seems good to me. @bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (98e1f04): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Footnotes |
This is fine, but not sure why you used rtabort instead of rtunwrap as requested. |
Because rtabort allows setting custom abort messages instead of just printing the generic "unwrap failed". |
The
EENTER
instruction only checks if the TCS is aligned, not if it zero. Saying the address returned is aNonNull<u8>
(for whichTcs
is a type alias) is unsound. As well-behaved runners will not put the TCS at address zero, so the definition ofTcs
is correct. However,std
should check the address before casting it to aNonNull
.ping @jethrogb @raoulstrackx
@rustbot label I-unsound