Skip to content
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

Integrate ube for rand engine #1897

Conversation

torben-hansen
Copy link
Contributor

@torben-hansen torben-hansen commented Oct 1, 2024

Description of changes:

This PR integrates protection of the thread-local state into the new randomness generation implementation. rand_ensure_ctr_drbg_uniquness() is the function that determines whether a randomization of the thread-local state is necessary. rand_ensure_ctr_drbg_uniquness() is called inline in the core randomness generation code path (in RAND_bytes_core() and invoked on every entry.

The only mechanism currently implemented that can force a randomization is the UBE mechanism implemented in bc7aeff. Note that if UBE is "unavailable" then a randomization is forced every time.

Testing:

Some additional support code is implemented to mock the UBE detection and determine if correct behaviour occurred.

The failing tests are because the target branch is randomness_generation that haven't been rebased on main branch with fixes.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@codecov-commenter
Copy link

codecov-commenter commented Oct 1, 2024

Codecov Report

Attention: Patch coverage is 91.11111% with 4 lines in your changes missing coverage. Please review.

Project coverage is 78.46%. Comparing base (a11fc48) to head (3d49bac).

Files with missing lines Patch % Lines
crypto/fipsmodule/rand/new_rand.c 85.71% 4 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                    @@
##           randomness_generation    #1897      +/-   ##
=========================================================
+ Coverage                  78.42%   78.46%   +0.04%     
=========================================================
  Files                        585      585              
  Lines                      97020    97060      +40     
  Branches                   13903    13919      +16     
=========================================================
+ Hits                       76090    76162      +72     
+ Misses                     20311    20282      -29     
+ Partials                     619      616       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

crypto/fipsmodule/rand/new_rand.c Outdated Show resolved Hide resolved
crypto/fipsmodule/rand/new_rand.c Outdated Show resolved Hide resolved
@torben-hansen torben-hansen marked this pull request as ready for review October 10, 2024 21:58
@torben-hansen torben-hansen requested a review from a team as a code owner October 10, 2024 21:58
crypto/fipsmodule/rand/new_rand.c Outdated Show resolved Hide resolved
crypto/fipsmodule/rand/new_rand.c Outdated Show resolved Hide resolved
crypto/fipsmodule/rand/new_rand.c Outdated Show resolved Hide resolved
@torben-hansen torben-hansen requested a review from dkostic October 11, 2024 13:38
@torben-hansen torben-hansen enabled auto-merge (squash) October 11, 2024 13:46
@@ -252,7 +293,7 @@ static void RAND_bytes_core(

OPENSSL_cleanse(pred_resistance, RAND_PRED_RESISTANCE_LEN);

if (rand_ensure_valid_state() != 1) {
if (rand_ensure_valid_state(state) != 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NP: in a future PR can you add a comment here explaining why we need to abort. I get that it means a UBE occurred and if that happened after line 235 and before line 242 you could end up with duplicate state, we might just forget/think this looks weird in the future.

@torben-hansen torben-hansen merged commit ccb97ef into aws:randomness_generation Oct 11, 2024
101 of 106 checks passed
torben-hansen added a commit to torben-hansen/aws-lc that referenced this pull request Nov 1, 2024
This PR integrates protection of the thread-local state into the new randomness generation implementation. rand_ensure_ctr_drbg_uniquness() is the function that determines whether a randomization of the thread-local state is necessary. rand_ensure_ctr_drbg_uniquness() is called inline in the core randomness generation code path (in RAND_bytes_core() and invoked on every entry.

The only mechanism currently implemented that can force a randomization is the UBE mechanism implemented in bc7aeff. Note that if UBE is "unavailable" then a randomization is forced every time.
torben-hansen added a commit to torben-hansen/aws-lc that referenced this pull request Dec 13, 2024
This PR integrates protection of the thread-local state into the new randomness generation implementation. rand_ensure_ctr_drbg_uniquness() is the function that determines whether a randomization of the thread-local state is necessary. rand_ensure_ctr_drbg_uniquness() is called inline in the core randomness generation code path (in RAND_bytes_core() and invoked on every entry.

The only mechanism currently implemented that can force a randomization is the UBE mechanism implemented in bc7aeff. Note that if UBE is "unavailable" then a randomization is forced every time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants