Skip to content

Prevent ECC tmp key leak and UB#10346

Open
Frauschi wants to merge 1 commit intowolfSSL:masterfrom
Frauschi:ecc_leak_fix
Open

Prevent ECC tmp key leak and UB#10346
Frauschi wants to merge 1 commit intowolfSSL:masterfrom
Frauschi:ecc_leak_fix

Conversation

@Frauschi
Copy link
Copy Markdown
Contributor

@Frauschi Frauschi commented Apr 29, 2026

ecc_key_tmp_final was guarded by if (err == MP_OKAY), leaking key->t1/t2 (and x/y/z under ALT_ECC_SIZE) whenever an allocation or mulmod step after ecc_key_tmp_init failed.

Simply removing the guard is unsafe however: unlike wc_ecc_mulmod_ex2 (whose arg checks return directly), this function XMALLOC'd key before the arg checks and used goto exit, so a bad-arg call would hand uninitialized memory to ecc_key_tmp_final and XFREE garbage pointers.

Defer the XMALLOC until after the arg/range checks so key is NULL on the early-error paths, then call ecc_key_tmp_final unconditionally to plug the leak on the late-error paths.

Identified by Srikanth Patchava srikanth.patchava@outlook.com

ecc_key_tmp_final was guarded by `if (err == MP_OKAY)`, leaking
key->t1/t2 (and x/y/z under ALT_ECC_SIZE) whenever an allocation or
mulmod step after ecc_key_tmp_init failed.

Simply removing the guard is unsafe here: unlike wc_ecc_mulmod_ex2
(whose arg checks `return` directly), this function XMALLOC'd `key`
before the arg checks and used `goto exit`, so a bad-arg call would
hand uninitialized memory to ecc_key_tmp_final and XFREE garbage
pointers.

Defer the XMALLOC until after the arg/range checks so `key` is NULL
on the early-error paths, then call ecc_key_tmp_final unconditionally
to plug the leak on the late-error paths.
@github-actions
Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

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.

2 participants