Latent memory leaks in KEM_KEY setter functions#3041
Merged
Conversation
dkostic
approved these changes
Feb 24, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3041 +/- ##
==========================================
- Coverage 78.37% 78.36% -0.01%
==========================================
Files 689 689
Lines 121078 121082 +4
Branches 16966 16965 -1
==========================================
- Hits 94889 94887 -2
- Misses 25294 25299 +5
- Partials 895 896 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
nebeid
approved these changes
Feb 27, 2026
WillChilds-Klein
pushed a commit
to WillChilds-Klein/aws-lc
that referenced
this pull request
Mar 11, 2026
### Description of changes: `KEM_KEY_set_raw_public_key`, `KEM_KEY_set_raw_secret_key`, and `KEM_KEY_set_raw_key` overwrite `key->public_key` and/or `key->secret_key` without first freeing any existing allocation. If these functions were ever called on a `KEM_KEY` that already had key material set, the previous buffers would be leaked. * Current call sites are not affected because they always operate on freshly zero-allocated keys (via `KEM_KEY_new`), but the functions themselves are unsafe if reused in other contexts. This change adds `OPENSSL_free` calls before each pointer is overwritten, consistent with how `KEM_KEY_init` already calls `KEM_KEY_clear` before re-initializing. ### Call-outs: This is a hardening fix. The added `OPENSSL_free` calls are no-ops in all current call sites (the pointers are always NULL), so there is no change in observable behavior today. ### Testing: Existing tests cover these code paths. No new tests required since the fix does not alter behavior for current callers. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.
nebeid
pushed a commit
to nebeid/aws-lc
that referenced
this pull request
Mar 23, 2026
### Description of changes: `KEM_KEY_set_raw_public_key`, `KEM_KEY_set_raw_secret_key`, and `KEM_KEY_set_raw_key` overwrite `key->public_key` and/or `key->secret_key` without first freeing any existing allocation. If these functions were ever called on a `KEM_KEY` that already had key material set, the previous buffers would be leaked. * Current call sites are not affected because they always operate on freshly zero-allocated keys (via `KEM_KEY_new`), but the functions themselves are unsafe if reused in other contexts. This change adds `OPENSSL_free` calls before each pointer is overwritten, consistent with how `KEM_KEY_init` already calls `KEM_KEY_clear` before re-initializing. ### Call-outs: This is a hardening fix. The added `OPENSSL_free` calls are no-ops in all current call sites (the pointers are always NULL), so there is no change in observable behavior today. ### Testing: Existing tests cover these code paths. No new tests required since the fix does not alter behavior for current callers. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.
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.
Description of changes:
KEM_KEY_set_raw_public_key,KEM_KEY_set_raw_secret_key, andKEM_KEY_set_raw_keyoverwritekey->public_keyand/orkey->secret_keywithout first freeing any existing allocation. If these functions were ever called on aKEM_KEYthat already had key material set, the previous buffers would be leaked.KEM_KEY_new), but the functions themselves are unsafe if reused in other contexts.This change adds
OPENSSL_freecalls before each pointer is overwritten, consistent with howKEM_KEY_initalready callsKEM_KEY_clearbefore re-initializing.Call-outs:
This is a hardening fix. The added
OPENSSL_freecalls are no-ops in all current call sites (the pointers are always NULL), so there is no change in observable behavior today.Testing:
Existing tests cover these code paths. No new tests required since the fix does not alter behavior for current callers.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.