-
Notifications
You must be signed in to change notification settings - Fork 722
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
Allocate s2n_crypto_parameters separately #3470
Conversation
} else { | ||
POSIX_GUARD_RESULT(s2n_crypto_parameters_wipe(conn->secure)); | ||
} | ||
struct s2n_crypto_parameters *secure = conn->secure; |
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.
What's happening here exactly? Why save a pointer to conn->secure/conn->initial?
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.
The first half of s2n_connection_wipe is saving anything from the connection we want to keep, then we zero the connection structure, then we restore the things we saved. The stack pointers here are to save the conn->secure/conn->initial memory. Without them, the conn->secure and conn->initial pointers will be reset to zero/NULL and the memory they pointed to will be leaked.
@@ -554,10 +467,21 @@ int s2n_connection_wipe(struct s2n_connection *conn) | |||
} | |||
POSIX_GUARD_RESULT(s2n_prf_wipe(conn)); | |||
struct s2n_prf_working_space *prf_workspace = conn->prf_space; | |||
if (!conn->initial) { |
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.
Moving the initialization of the crypto params to s2n_connection_wipe means that there would be more frequent calls to allocate memory right? Do we need documentation for this kind of thing?
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.
Only if s2n_connection_free_handshake is called, which is the point of that API. Otherwise, we just reuse the memory allocated by s2n_connection_new.
Description of changes:
Move both s2n_crypto_parameters off of s2n_connection so that conn->initial can be freed after the handshake. conn->initial represents a plaintext context, and all data after the handshake should be encrypted and use conn->secure.
This has the nice side effect of cleaning up some of the worst s2n_connection setup code.
Memory information after this change:
Callouts
Testing:
I added a new test to verify we can send, recv, and wipe/reuse connections after both s2n_connection_free_handshake and s2n_connection_release_buffers. I couldn't find any existing test of that case. I can't imagine it's a common use case, but it should work.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.