-
Notifications
You must be signed in to change notification settings - Fork 724
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 fd status before using urandom #4352
Conversation
d70f190
to
282ee87
Compare
282ee87
to
a7091ad
Compare
While you're doing performance benchmarks... I would be curious what it would look like if we opened and closed |
I updated the performance data table with data for this. It looks like opening and closing the file descriptor on every call is about 3x slower than opening once and using fstat to verify. The average latency increase for opening on every call is 1.23% vs 0.40% for fstat. The code is definitely cleaner without the global file descriptor though. |
1c64da5
to
bfe9080
Compare
bfe9080
to
e1077f9
Compare
tests/unit/s2n_handshake_test.c
Outdated
/* Ensure that a handshake can be performed after all non-standard file descriptors are closed */ | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice test :)
f1559c6
to
7245fdf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good! nice work
Resolved issues:
Resolves #4324.
Description of changes:
When s2n-tls is initialized, /dev/urandom is opened, which is later used retrieve entropy when generating random bytes. However, if this file descriptor is closed after initialization but before it's actually used, s2n-tls will currently loop forever trying to read from the closed file descriptor:
s2n-tls/utils/s2n_random.c
Lines 344 to 347 in edebdae
This PR implements a similar check to OpenSSL, where information about /dev/urandom is cached on initialization to be checked before actually retrieving entropy. If the current status of the file descriptor is different from when it was opened, /dev/urandom is re-opened.
Call-outs:
The fstat syscall is used to cache and check information about the file descriptor, which adds latency when generating random data. I ran performance tests with 500k handshakes on common cipher suites to determine the impact, and found that this change adds an average of 0.40% of latency to handshakes. The maximum latency added was 0.72% for AES128-GCM-SHA256. See the following performance data for details:
Performance data
Testing:
I added a new random test that closes the urandom file descriptor before generating random data. Without the fix, this test loops forever in
s2n_rand_urandom_impl()
. I also added a test that swaps the file descriptor to ensure that /dev/urandom is re-opened.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.