fix: add bound check for Yc_length against server DH params#5737
Merged
CarolYeh910 merged 6 commits intoaws:mainfrom Feb 18, 2026
Merged
fix: add bound check for Yc_length against server DH params#5737CarolYeh910 merged 6 commits intoaws:mainfrom
CarolYeh910 merged 6 commits intoaws:mainfrom
Conversation
maddeleine
reviewed
Feb 17, 2026
maddeleine
reviewed
Feb 17, 2026
jouho
reviewed
Feb 17, 2026
jouho
approved these changes
Feb 18, 2026
maddeleine
approved these changes
Feb 18, 2026
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.
Goal
Bound the length of
Yc_inbuffer against the size of server DH parametersWhy
s2n_dh_compute_shared_secret_as_server()reads a peer-suppliedYc_inbuffer without validating its length against the server DH group size. This allows clients to send oversizedYc_lengthvalues (up to 65535 bytes) and cause unnecessary memory allocation and CPU workload.How
Validate
Yc_lengthdoes not exceedserver_dh_params_sizebefore invokingBN_bin2bn()orDH_compute_key().Callouts
We would like to thank Joshua Rogers (https://joshua.hu/) of AISLE Research Team (https://aisle.com/) for reporting this issue.
Testing
I added a unit test to verify that s2n server will fail for
S2N_ERR_DH_SHARED_SECRETwhen a client sends an oversizedYc_inbuffer. One thing to note is that the selected parameters in this test may causes2n_pkcs3_to_dh_params()to fail on certain libcryptos due to different behaviors ofDH_check()across versions. The purpose is not testingDH_check(), thus skipping the test whens2n_pkcs3_to_dh_params()fails.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.