Skip to content

fix: memory leak in hybrid key share generation + doc comment#10312

Open
srpatcha wants to merge 6 commits intowolfSSL:masterfrom
srpatcha:docs/add-session-cache-doc-comment
Open

fix: memory leak in hybrid key share generation + doc comment#10312
srpatcha wants to merge 6 commits intowolfSSL:masterfrom
srpatcha:docs/add-session-cache-doc-comment

Conversation

@srpatcha
Copy link
Copy Markdown

@srpatcha srpatcha commented Apr 25, 2026

Changes

1. Clarify session cache size comment in ssl_sess.c

Documentation improvement to clarify the session cache size comment.

2. Fix memory leak in hybrid key share generation (src/tls.c)

In the hybrid key share generation path, if the second XMALLOC() for pqc_kse fails after ecc_kse was successfully allocated, ecc_kse is leaked. Added explicit XFREE(ecc_kse) cleanup in the error path.

Replace ambiguous XXX placeholder in comment with descriptive text.
The XXX was not a TODO marker but looked like one, causing confusion
in code reviews and static analysis.
@wolfSSL-Bot
Copy link
Copy Markdown

Can one of the admins verify this patch?

Add explicit XFREE(ecc_kse) cleanup when the second XMALLOC for
pqc_kse fails in the hybrid key share generation path. Previously,
if the pqc_kse allocation failed after ecc_kse was successfully
allocated, ecc_kse would be leaked since it was only tracked as
a local variable.
@srpatcha srpatcha changed the title docs: clarify session cache size comment in ssl_sess.c fix: memory leak in hybrid key share generation + doc comment Apr 25, 2026
srpatcha and others added 4 commits April 24, 2026 22:23
ecc_key_tmp_final was guarded by if (err == MP_OKAY), skipping cleanup
on failure and leaking the temporary key. The sister function
wc_ecc_mulmod_ex2 correctly calls cleanup unconditionally. Removed the
conditional to match the correct pattern.

Signed-off-by: Srikanth Patchava <spatchava@meta.com>
Signed-off-by: Srikanth Patchava <srikanth.patchava@outlook.com>
Signed-off-by: Srikanth Patchava <spatchava@meta.com>
Signed-off-by: Srikanth Patchava <spatchava@meta.com>
Signed-off-by: Srikanth Patchava <spatchava@meta.com>
@dgarske
Copy link
Copy Markdown
Member

dgarske commented Apr 28, 2026

Hi @srpatcha ,

Thank you for this pull request submission. I don't see you on file as an approved contributor. We are going to review this and provide some feedback. Can you tell us more about your project , what region you are located and if you plan future submissions? Also what techniques did you use to locate these issues?

Thanks,
David Garske, wolfSSL

@srpatcha
Copy link
Copy Markdown
Author

Hi @dgarske, thank you for reviewing!

I'm Srikanth Patchava, a software engineer based in Sunnyvale, CA. I work on embedded systems and noticed this memory leak while studying the hybrid key share implementation. The fix ensures the allocated buffer is freed on error paths in TLSX_KeyShare_GenKey().

I'm interested in continuing to contribute to wolfSSL, particularly around memory safety and security hardening in the TLS implementation. Happy to provide any additional information needed for the contributor approval process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants