refactor: zero static s2n_configs on cleanup #4416
Merged
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.
Resolved issues:
Test failures in #4407
Description of changes:
4407 introduces a change which causes internal validation to be triggered on the config whenever the security policy is set. This caused two different test failures
s2n_init
s2n-init was failing in the following sequence of events
S2N_ERR_NULL
because the map was null.My knee jerk reaction was to have
s2n_config_validate_loaded_certificates
returnS2N_RESULT_OK
when the map was null. (note that I don't think the is the long term correct course) However this resulted in an odder series of failuresThe
immutability
error is happening because the map was previously zero'd, so the boolean field of the struct is interpretated as false, but in fact this is a use-after-free. The map pointer is dangling. This was confirmed with ASAN.To avoid these kinds of errors we should also wipe the configs when we call cleanup.
s2n_cipher_suite_match_test.c
This test experienced failures because there were cases where we'd
After this, the
conn->config
pointer is a dangling pointer towards garbage, free'd memory. This was causing a crash inThe first RESULT_ENSURE_REF didn't trigger because the pointer wasn't null, it was dangling. Once again this was confirmed with ASAN.
This can be fixed by associating valid configs with the connections before using them in tests.
Call-outs:
For non static configs, the configs are zero'd when they are freed. This means that there is a "double zeroing" happening for configs, but I thought that this implementation (adding a POSIX_CHECKED_MEMSET) was the most readable way of solving this.
Also, the zeroing of static configs on wiping isn't technically necessary as long as you initialize all of the config fields in the correct order. However this creates a very sharp edge and could lead to nondeterministic failures and crashes, so I'd prefer to zero them.
Testing:
All tests/CI runs should pass.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.