[RTE-513] Bugfix: Ensure sleep takes long enough on SGX platform #144357
+61
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
The
thread::sleep
function documentation states:And for
thread::sleep_until
:These did not hold for the
x86_64-fortanix-unknown-sgx
platform. This PR fixes this issue.More details
The attack model on Intel SGX states that enclaves should not rely on timing to be accurate within an enclave. To ensure that users do not rely on the accuracy of the
wait
usercall (see the ABI), we randomized the specified timeout with +/-10%. This was causing issues when the timeout was reduced. This PR fixes the issue by picking a random duration of up to +10% (i.e., the duration will never be reduced).The issue was caught when #141829 added a test for
sleep_until
. There wasn't a test in the standard library to verify thatthread::sleep
sleeps for at least the specified amount of time. Such a test is added as well.cc: @jethrogb @aditijannu