Repository navigation
Conversation
s2n_init_drbgs allocates, via s2n_drbg_instantiate, dynamic memory to fields of a static, thread-local struct. For this reason, the de-allocation/clean-up of these fields can only happen through the same thread that created them. Else the allocations will leak. Hence track these allocations as thread-specific data, using an allocation key and a destructor function that gets called at thread exit. This resolves aws#3525 (tested via LSAN sanitizer).
Contributor
|
Thanks for the submission, we'll take a look. |
lrstewart
suggested changes
Oct 3, 2022
lrstewart
left a comment
Contributor
There was a problem hiding this comment.
Can you include a test the reproduces and then fixes the memory leak that you're describing?
Contributor
Author
|
@lrstewart - I added an --- a/utils/s2n_random.c
+++ b/utils/s2n_random.c
@@ -136,7 +136,7 @@ S2N_RESULT s2n_get_mix_entropy(struct s2n_blob *blob)
static void s2n_drbg_destructor(void *_unused_argument) {
(void)_unused_argument;
- s2n_result_ignore(s2n_rand_cleanup_thread());
+ //s2n_result_ignore(s2n_rand_cleanup_thread());
}
static void s2n_drbg_make_alloc_key(void) |
Contributor
Author
Condition can be fixed in
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
s2n_init_drbgsallocates, vias2n_drbg_instantiate, dynamic memory to fields of a static, thread-local struct. For this reason, the de-allocation of these fields should be done by the same thread that created them. Else the allocations will leak.Hence track these allocations as thread-specific data, using an allocation key and a destructor function called at thread exit.
Resolved issues: Resolves #3525.
Description of changes:
Ensure that the same thread that dynamically allocates memory to fields of the thread-local storage allocated by
s2n_drbg_instantiate (and the functions it calls) is de-allocated by the same thread.
Currently the de-allocation happens from another thread, which does not help.
Call-outs:
Please revise the use of
s2n_rand_cleanup_threadwith regard tos2n_drbg_wipe. Thedrbgde-allocation couldhappen entirely in the destructor. That would render
s2n_rand_cleanup_threadeither empty, or it could be usedfor other clean-up tasks.
Testing:
Ran the test suite. Ran tests with LSAN (before/after) to ensure that the leaks have been fixed.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.