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

Reference s2n_crypto_parameters via pointers #3469

Merged
merged 4 commits into from
Aug 26, 2022
Merged

Conversation

lrstewart
Copy link
Contributor

@lrstewart lrstewart commented Aug 26, 2022

Description of changes:

This is a stepping stone towards allocating the s2n_crypto_parameters separately from s2n_connection so that we can free conn->initial after the handshake: lrstewart@0754e5c

We reference conn->secure quite a lot in our code, often to access the cipher suite (conn->secure.cipher_suite). That means that if we make it a pointer, we have to update a lot of references to conn->secure. with conn->secure->. Apparently 93 files worth.

To avoid drowning the upcoming actually interesting changes, I'm splitting the uninteresting changes of just finding and replacing "." with "->" into this PR. To do that, I just point the new conn->initial and conn->secure pointers at memory still allocated on the s2n_connection structure.

conn->secure should never be null (we'll never free it) but I added ENSURE_REF(conn->secure) everywhere outside of the tests where we dereferenced it just in case. This was manual, and involved a lot of files, so you may need to just take my word for it and accept that if I missed one it's not a huge risk.

The only non-find/replace changes:
tls/s2n_connection.c
tests/saw/spec/handshake/handshake_io_lowlevel.saw

Callouts

  • Why also make conn->secure a pointer if we never free it? To keep the code simple. If we need to manage conn->initial and conn->secure differently, it could get complicated and open us up to bugs. Just look at the current logic for managing s2n_crypto_parameters :(

Testing:

Existing unit test pass. I didn't make any changes to the tests beyond fixing all the references to conn->initial and conn->secure.
I unfortunately had to fix the SAW test: https://github.com/aws/s2n-tls/pull/3469/files#diff-1fded1e92cdd5ab7f968a9154528b59efbd04a25de8f004cd431abb10477630d

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

Switching conn->secure to a pointer results in many,
mostly automated, changes. To avoid hiding substantial changes
in this mess, let's first JUST make the type switch without
actually changing the memory management.
@github-actions github-actions bot added the s2n-core team label Aug 26, 2022
@lrstewart lrstewart force-pushed the mem_1 branch 2 times, most recently from e53ffe4 to ae85bf2 Compare August 26, 2022 03:55
@lrstewart lrstewart marked this pull request as ready for review August 26, 2022 04:55
@lrstewart lrstewart requested a review from a team as a code owner August 26, 2022 04:55
@lrstewart lrstewart requested a review from camshaft August 26, 2022 04:55
Copy link
Contributor

@camshaft camshaft left a comment

Choose a reason for hiding this comment

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

Despite the length, this was actually pretty straightforward to review

@lrstewart lrstewart requested a review from goatgoose August 26, 2022 16:33
@@ -111,7 +112,7 @@ int s2n_tls13_default_sig_scheme(struct s2n_connection *conn, struct s2n_signatu
POSIX_GUARD(s2n_connection_get_signature_preferences(conn, &signature_preferences));
POSIX_ENSURE_REF(signature_preferences);

struct s2n_cipher_suite *cipher_suite = conn->secure.cipher_suite;
struct s2n_cipher_suite *cipher_suite = conn->secure->cipher_suite;
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want a POSIX_ENSURE_REF here at some point.

@lrstewart lrstewart enabled auto-merge (squash) August 26, 2022 20:42
@lrstewart lrstewart merged commit 56cd2c8 into aws:main Aug 26, 2022
@lrstewart lrstewart deleted the mem_1 branch August 26, 2022 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants