-
Notifications
You must be signed in to change notification settings - Fork 718
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
Implementation of fork generation number API #3191
Conversation
Benchmark report |
Benchmark report |
Benchmark report |
Benchmark report |
Benchmark report |
Benchmark report |
Benchmark report |
Benchmark report |
b12b894
to
779b1ed
Compare
Benchmark report |
Benchmark report |
Benchmark report |
Benchmark report |
098cf5b
to
bc6d1a5
Compare
Benchmark report |
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.
will review more; just a couple of things that stood out initially.
bc6d1a5
to
3e31b9f
Compare
Benchmark report |
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.
Also not done reviewing the full change, but here's some initial comments mostly about the codebase conventions.
a1eac9b
to
a87e532
Compare
This change implements a fork generation number (fgn). A fgn has the following properties: * Unsigned 64-bit integer. * Strictly-monotonic increasing. * If returned in a process, a subsequent return in a forked child process will result in a strictly greater value.
This change implements a fork generation number (fgn). A fgn has the following properties: * Unsigned 64-bit integer. * Strictly-monotonic increasing. * If returned in a process, a subsequent return in a forked child process will result in a strictly greater value.
Turns out that osx/apple defines both madvise() and minherit(). This invalidates an assumption I made in #3191. To remedy, remove the bad assumption and fix another osx/apple-specific thing: __WALL is not defined.
This change takes the fork detection backend implemented in #3191 and wires up the randomness generation frontend to it. In turn, replacing the existing fork detection mechanism. In addition, it implement two test cases that verifies more fork detection methods in isolation.
This change takes the fork detection backend implemented in aws#3191 and wires up the randomness generation frontend to it. In turn, replacing the existing fork detection mechanism. In addition, it implement two test cases that verifies more fork detection methods in isolation.
Resolved issues:
See CryptoAlg-892 and #3107
Description of changes:
This PR is the first out of two PRs that will implement the solution outlined in #3107:
This change implements a fork generation number (fgn). A fgn has the following properties:
To manage and expose this number to higher layers (and hide the implementation details to the rest of the code base) the fgn API
s2n_get_fork_generation_number(*generation_number)
is implemented. This function has the following properties:S2N_SUCCESS
if fork detection is supported,S2N_FAILURE
otherwise.To implement the second property, two independent fork detection mechanisms are re-implemented:
pthread_atfork
MADV_WIPEONFORK
The implementation of these follow the current implementation but fixes its issues. There is one fundamental difference compared to the existing implementation: the former method is required to be functional while the latter method is initialised with best-effort (on supported systems...).
Call-outs:
The reason for having
MADV_WIPEONFORK
best-effort is documented in the code, but is repeated here for completeness:Given this, it might be useful, in the future, to add a public API that consuming application can use to assert whether
MADV_WIPEONFORK
has been enabled.In theory the state variable
current_fork_generation_number
can overflow. But it has ~2^64 possible values, which should be plenty to outlive even wildest long-lived process and forking.Testing:
A new test suite has been written containing 4 different type of tests running over a combination of active fork detection methods. The 4 different types of tests are:
s2n_get_fork_generation_number()
after lazy initialisation (and no fork events, or after a fork event). I also call this "stability".s2n_get_fork_generation_number()
under afork()
.s2n_get_fork_generation_number()
under aclone()
(only ifMADV_WIPEONFORK
orMIN_INHERIT_ZERO
is expected to be supported).Darwin/OSX
Verified locally:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.