Skip to content

Add missing ForceZero calls#9885

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

Add missing ForceZero calls#9885
Frauschi wants to merge 1 commit intowolfSSL:masterfrom
Frauschi:missing_force_zero

Conversation

@Frauschi
Copy link
Contributor

@Frauschi Frauschi commented Mar 5, 2026

F-13, F-14, F-197, F-198, F-199, and F-200. All at once as these are very similar.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds explicit zeroization of sensitive buffers (ForceZero + optional wc_MemZero_Check) to address several missing wipe sites across TLS 1.2/1.3 key derivation paths.

Changes:

  • Ensure temporary key material in TLS 1.3 secret derivation is wiped before returning.
  • Wipe PRF/key-derivation intermediate buffers in TLS 1.2/legacy paths before freeing.
  • Introduce misc include plumbing in keys.c to make ForceZero available.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/tls13.c Adds cleanup path to wipe derived key buffer(s) in TLS 1.3 secret derivation.
src/tls.c Wipes PRF digest buffer before freeing in TLS key derivation.
src/keys.c Wipes multiple TLS 1.0–1.2 derivation intermediates; replaces manual loops with ForceZero; adds ForceZero include wiring.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

ForceZero(shaInput, KEY_PREFIX + SECRET_LEN + 2 * RAN_LEN);
ForceZero(keyData, KEY_PREFIX * WC_MD5_DIGEST_SIZE);
#ifdef WOLFSSL_CHECK_MEM_ZERO
wc_MemZero_Check(shaOutput, WC_SHA_DIGEST_SIZE);
Copy link
Contributor

@SparkiDev SparkiDev Mar 5, 2026

Choose a reason for hiding this comment

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

Change this to wc_MemZero_Add at the top.
That way all code paths will be checked.
Check will then happen in free.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the missing wc_MemZero_Add() calls at the top (TIL that these are required to make wc_MemZero_Check() actually check something...).

However, we cannot remove the manual wc_MemZero_Check() calls here, as XFREE is only called for WOLFSSL_SMALL_STACK builds. Hence, the check would be missing for stack allocations.

@Frauschi Frauschi force-pushed the missing_force_zero branch from e615773 to 001eae7 Compare March 6, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For This Release Release version 5.9.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants