Skip to content

harden forcezero and compiler barriers - #10935

Open
stenslae wants to merge 6 commits into
wolfSSL:masterfrom
stenslae:fix/wcForceZero
Open

stenslae wants to merge 6 commits into
wolfSSL:masterfrom
stenslae:fix/wcForceZero

Conversation

@stenslae

@stenslae stenslae commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

Description

  • Moved wc_ForceZero() and wc_ConstantCompare() from memory.c into wc_port.c so they are always available across builds.
  • Updated blake2 to use ForceZero() instead of hand rolled volatile loop.
  • Fixed the portable fallback for WC_BARRIER_DATA() so it escapes the pointer to prevent DSE of stack variables when GNU inline asm isnt available.

A follow up PR will add DSE elimination coverage and regression tests for this PR.

Testing

Cross compiled architectures: x86_64, aarch64, arm32, and riscv64. Statically analyzed and passed forcezero testing.

Checklist

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

@stenslae stenslae self-assigned this Jul 16, 2026

@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 #10935

Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src

No new issues found in the changed files. ✅

@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 #10935

Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Findings are non-blocking.

Comment thread wolfssl/wolfcrypt/wc_port.h Outdated
Comment thread wolfssl/wolfcrypt/wc_port.h Outdated

@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 #10935

Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src

No new issues found in the changed files. ✅

@stenslae

Copy link
Copy Markdown
Member Author

jenkins retest this please

@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 #10935

Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src

No new issues found in the changed files. ✅

@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 #10935

Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src

No new issues found in the changed files. ✅

@stenslae
stenslae force-pushed the fix/wcForceZero branch 2 times, most recently from 1844d19 to 6bf96b1 Compare July 20, 2026 20:37
@stenslae

Copy link
Copy Markdown
Member Author

jenkins retest this please

@stenslae

Copy link
Copy Markdown
Member Author

jenkins retest this please

@stenslae
stenslae requested review from wolfSSL-Fenrir-bot and removed request for wolfSSL-Fenrir-bot July 23, 2026 17:50

@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 #10935

Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src

Fenrir result: Approved ✅

No new issues found in the changed files.

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

@stenslae

stenslae commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

Jenkins retest this please

@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 #10935

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Comment thread wolfcrypt/test/dse_probe.c Outdated
@stenslae

Copy link
Copy Markdown
Member Author

Moved the CI test configs and DSE coverage into a separate pr to keep this one focused on the actual fix

@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 #10935

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs

Fenrir result: Approved ✅

No new issues found in the changed files.

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

@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 #10935

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs

Fenrir result: Approved ✅

No new issues found in the changed files.

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

@stenslae

Copy link
Copy Markdown
Member Author

Jenkins retest this please

@stenslae

Copy link
Copy Markdown
Member Author

Rebased so changelog messages go into the right place.

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.

Copilot review overview

🟡 Changes recommended

Compiler-dependent wipe behavior lacks regression coverage, and changelog entries target an already released version.

Review effort: Balanced
Findings: 1 Medium severity · 2 Low severity

Open (3)
What changed in this PR

Hardens secure memory wiping and compiler barriers across supported builds and architectures.

Changes:

  • Relocates zeroing/comparison APIs into always-built port code.
  • Strengthens compiler barriers and fixes ForceZero alignment handling.
  • Migrates BLAKE2 key cleanup to ForceZero and updates configuration metadata.
File Description
.wolfssl_known_macro_extras Registers the new barrier compatibility macro.
ChangeLog.md Documents API and hardening changes.
wolfssl/​wolfcrypt/​wc_port.h Defines APIs, barriers, and architecture fences.
wolfssl/​wolfcrypt/​settings.h Preserves ForceZero for BLAKE2 and Argon2.
wolfssl/​wolfcrypt/​memory.h Removes relocated declarations.
wolfssl/​wolfcrypt/​blake2-impl.h Removes the custom zeroing helper.
wolfcrypt/​src/​wc_port.c Hosts exported APIs and portable barrier sink.
wolfcrypt/​src/​misc.c Fixes short-buffer alignment handling.
wolfcrypt/​src/​memory.c Removes relocated implementations.
wolfcrypt/​src/​blake2s.c Uses ForceZero for key cleanup.
wolfcrypt/​src/​blake2b.c Uses ForceZero for key cleanup.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread wolfssl/wolfcrypt/wc_port.h
Comment thread ChangeLog.md Outdated
Comment thread ChangeLog.md Outdated
@philljj

philljj commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

These two PRs are going to collide with same changes:

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.

🟡 Changes recommended

The Arm Compiler 5 path still permits dead-store elimination, and the security hardening lacks regression coverage.

2 open findings
3 resolved since last review

🧠 Review effort: Balanced

Comment thread wolfssl/wolfcrypt/wc_port.h Outdated
Comment thread wolfcrypt/src/wc_port.c

@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 #10935

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Coverage: 2 of 2 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

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.

🟡 Changes recommended

The security guarantee lacks permanent DSE/LTO regression coverage, and the changelog misdocuments armcc5 behavior.

2 open findings
2 resolved since last review

🧠 Review effort: Balanced

Comment thread wolfcrypt/src/wc_port.c
Comment thread ChangeLog.md Outdated

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.

🟡 Changes recommended

The security and build regressions being fixed need automated coverage in this pull request.

1 open finding
2 resolved since last review

🧠 Review effort: Balanced

Comment thread wolfcrypt/src/wc_port.c

@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 #10935

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
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 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 #10935

Scan targets checked: none
Unchanged since last review (not re-run): wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs

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

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.

🔵 Needs a closer look

Security-sensitive, compiler-specific barrier behavior lacks the planned regression and DSE coverage.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Comment thread wolfcrypt/src/misc.c

@julek-wolfssl julek-wolfssl Oct 21, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Once #11809 goes in the changes on this file will be redundant.

Emma Stensland added 6 commits October 23, 2026 13:17
Both compilers accept -std=c99, so a C99 build selected the WOLF_C99 arm
and expanded to __asm__, a keyword neither assembler dialect takes.
Without it the compiler may keep memory in registers across the
fence, so the fence ordered the CPU but not the code generator.
XFENCE() is a macro, so TUs outside the library expand it and need the
symbol linkable; WOLFSSL_TEST_VIS marks it internal without hiding it.
(void)(ptr) escaped nothing, so ForceZero() on a non-escaped stack local
was still dead-store eliminated on every build without GNU inline asm.
memory.c is excluded from some builds, which left the two exported
wrappers undefined; wc_port.c is always compiled.
The one-off byte-at-a-time helper bypassed the barrier-hardened wipe
path every other part of wolfCrypt goes through.
@stenslae

Copy link
Copy Markdown
Member Author

claude @review

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.

🔵 Needs a closer look

The short-buffer alignment correction remains missing, and security-critical compiler barrier behavior needs final cross-toolchain validation.

1 open issue

Review effort: Balanced

Comment thread wolfcrypt/src/wc_port.c

@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 #10935

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .wolfssl_known_macro_extras, ChangeLog.md
Coverage: 3 of 8 in-scope changed file(s) opened by the reviewer; not opened: wolfcrypt/src/blake2b.c, wolfcrypt/src/blake2s.c, wolfcrypt/src/memory.c, wolfssl/wolfcrypt/blake2-impl.h, wolfssl/wolfcrypt/memory.h

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

@stenslae

Copy link
Copy Markdown
Member Author

Removed xfence barriers to keep this pr more focused.

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.

10 participants