Skip to content

Fix/ecc make pub heapmath leak - #12151

Merged
philljj merged 5 commits into
wolfSSL:masterfrom
kaleb-himes:fix/ecc-make-pub-heapmath-leak
Nov 17, 2026
Merged

philljj merged 5 commits into
wolfSSL:masterfrom
kaleb-himes:fix/ecc-make-pub-heapmath-leak

Conversation

@kaleb-himes

@kaleb-himes kaleb-himes commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Fenrir:

Item Title Status Project Fixed by
F-10917 ECC key generation reinitializes already initialized multiprecision values assigned wolfCrypt FIPS Cert Snapshots 1ab2b82385 (key->pubkey in ecc_make_pub_ex), 6cda2cfe05 (key->k in _ecc_make_key_ex), d681148f52 (also wipes the BLIND_K mask)
F-12026 wc_ecc_import_raw_private reinitializes already initialized bignums open wolfCrypt FIPS Cert Snapshots 251a0e828f (_ecc_import_raw_private via ecc_free_key_ints)
F-7806 wc_MakeRsaKey re-initializes RsaKey mp_ints that wc_InitRsaKey already initialized open wolfCrypt FIPS Cert Snapshots 251a0e828f (RsaForceZeroPriv plus clearing n and e)
F-9567 wc_DhSetKey_ex re-runs mp_init on p, g and q that wc_InitDhKey_ex already initialised open wolfCrypt FIPS Cert Snapshots 251a0e828f (_DhSetKey)
F-12175 wc_MakeDsaKey and wc_MakeDsaParameters reinitialize live DsaKey integers open wolfCrypt 251a0e828f (both functions)

Description:

If you generated a key, or rebuilt its public key, more than once on the same ecc_key, the memory from the earlier run was never freed. The old private key was also left in that memory without being erased. This only happened with heap math (--enable-heapmath).

Fix: free the old public key before reusing it, and erase and free the old private key. test_wc_ecc_make_key now generates a key twice on the same object.

Tested:

Built with heap math and a memory-leak checker. Before the fix, three ECC tests leaked memory, which matches the CI failure. After the fix, the full API test suite passes with no leaks.
Built with the default math on macOS; the three tests pass.
Skoll review found nothing that needs a change.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

Copilot AI balanced review requested due to automatic review settings November 16, 2026 23:19
@kaleb-himes
kaleb-himes marked this pull request as ready for review November 16, 2026 23:19
@github-actions

Copy link
Copy Markdown

retest this please

This comment was marked as resolved.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m0plus

  • FLASH: .text +64 B (+0.1%, 71,355 B / 262,144 B, total: 27% used)

gcc-arm-cortex-m3

  • FLASH: .text +76 B (+0.1%, 132,349 B / 262,144 B, total: 50% used)

gcc-arm-cortex-m4

  • FLASH: .text +64 B (+0.0%, 209,704 B / 262,144 B, total: 80% used)

gcc-arm-cortex-m4-baremetal

  • FLASH: .text +64 B (+0.1%, 74,159 B / 262,144 B, total: 28% used)

gcc-arm-cortex-m4-crypto-only

  • FLASH: .text +192 B (+0.1%, 182,987 B / 262,144 B, total: 70% used)

gcc-arm-cortex-m4-dtls13

  • FLASH: .text +128 B (+0.1%, 197,408 B / 1,048,576 B, total: 19% used)

gcc-arm-cortex-m4-min-ecc

  • FLASH: .text +128 B (+0.2%, 68,625 B / 262,144 B, total: 26% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .text +256 B (+0.0%, 805,636 B / 1,048,576 B, total: 77% used)

gcc-arm-cortex-m4-pkcs7

  • FLASH: .text +128 B (+0.1%, 224,204 B / 262,144 B, total: 86% used)

gcc-arm-cortex-m4-pq

  • FLASH: .text +128 B (+0.0%, 315,376 B / 1,048,576 B, total: 30% used)

gcc-arm-cortex-m4-rsa-only

  • FLASH: .text +128 B (+0.0%, 345,576 B / 1,048,576 B, total: 33% used)

gcc-arm-cortex-m4-sp-math

  • FLASH: .text +128 B (+0.2%, 68,625 B / 262,144 B, total: 26% used)

gcc-arm-cortex-m4-tls12

  • FLASH: .text +128 B (+0.1%, 133,129 B / 262,144 B, total: 51% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .text +128 B (+0.1%, 252,034 B / 262,144 B, total: 96% used)

gcc-arm-cortex-m7

  • FLASH: .text +64 B (+0.0%, 209,704 B / 262,144 B, total: 80% used)

gcc-arm-cortex-m7-pq

  • FLASH: .text +128 B (+0.0%, 316,208 B / 1,048,576 B, total: 30% used)

gcc-arm-cortex-m7-tls13

  • FLASH: .text +128 B (+0.1%, 252,034 B / 262,144 B, total: 96% used)

stm32-sim-stm32h753

  • FLASH: .text -64 B (-0.0%, 207,908 B / 2,097,152 B, total: 10% used)

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata +104 B, text +12,192 B (+4.4%, 294,768 B / 67,108,864 B, total: 0% used)
  • RAM: bss +49 B, datas +16 B (+0.1%, 58,423 B / 983,040 B, total: 6% used)

Catch memory regressions in CI with MemBrowse. Free for open source.

wolfSSL-Fenrir-bot

This comment was marked as resolved.

This comment was marked as outdated.

wolfSSL-Fenrir-bot

This comment was marked as resolved.

@kaleb-himes
kaleb-himes force-pushed the fix/ecc-make-pub-heapmath-leak branch from d681148 to 2d7f1dd Compare November 17, 2026 02:00
@kaleb-himes
kaleb-himes requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 17, 2026 02:03

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #12151

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs
Unchanged since last review (not re-run): wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/asn_public.h, doc/dox_comments/header_files/dh.h
Coverage: 1 of 1 in-scope changed file(s) opened by the reviewer

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed stale reviews from themself November 17, 2026 02:07

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the changes addressing memory leaks when cryptographic key objects are reused.

No open issues 🎉

Review effort: Balanced

@philljj

philljj commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Retest this please.

(fipsv2 PRB git fetch failure)

@philljj

philljj commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

confirmed fixed with intmath-sanitizer.

tests good with all-gcc-c89, c89-clang-tidy, no-malloc, sp-asm, etc.

@philljj
philljj merged commit 0662f2f into wolfSSL:master Nov 17, 2026
448 of 449 checks passed
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.

6 participants