Skip to content

Fix entropy_mutex ownership tracking & re-init race - #11645

Open
stenslae wants to merge 3 commits into
wolfSSL:masterfrom
stenslae:audit-entropy-mutex
Open

stenslae wants to merge 3 commits into
wolfSSL:masterfrom
stenslae:audit-entropy-mutex

Conversation

@stenslae

@stenslae stenslae commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Description

Fixed fenrir findings for F-7091, F-7419, and F-8169.

Added boolean tracking on the mutex lock, and made it so mutex locking and stop thread are only called when the current thread successfully acquired the lock. Also changed wc_InitMutex() in Entropy_Init() with wc_local_InitMutexOnce() to prevent re-initalization of an active mutex, and added resetting the atomic entropy flag in Entropy_Final().

Checklist

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

@stenslae stenslae self-assigned this Oct 5, 2026
Copilot AI balanced review requested due to automatic review settings October 5, 2026 18:35
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

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

🔵 Needs a closer look

Entropy-source synchronization changes need platform-aware human review and stronger concurrency regression coverage.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
What changed in this PR

Hardens wolfCrypt’s memory-based entropy source against mutex ownership and re-initialization errors.

Changes:

  • Guards mutex release and counter-thread shutdown with ownership tracking.
  • Uses one-time mutex initialization and resets its flag during finalization.
  • Adds whitebox lifecycle and failure-path tests.
File Description
wolfcrypt/​src/​wolfentropy.c Updates mutex ownership, initialization, and cleanup handling.
tests/​unit-mcdc/​test_wolfentropy_whitebox.c Adds re-initialization, lock-refusal, and held-mutex cleanup checks.

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

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

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

@stenslae
stenslae force-pushed the audit-entropy-mutex branch from 3479616 to 9c11a59 Compare October 5, 2026 19:39
@stenslae
stenslae requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot October 5, 2026 19:39

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

Scan targets checked: wolfssl-bugs
Unchanged since last review (not re-run): wolfcrypt-src, wolfcrypt-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

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

The new on-demand test baseline can falsely report a regression when the threaded entropy counter is stopped.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (2)

@stenslae
stenslae force-pushed the audit-entropy-mutex branch from 9c11a59 to 1b65c7a Compare October 5, 2026 20:02
@stenslae
stenslae requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot October 5, 2026 20:02

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

Scan targets checked: wolfssl-bugs
Unchanged since last review (not re-run): wolfcrypt-src, wolfcrypt-bugs
Coverage: 1 of 1 in-scope changed file(s) opened by the reviewer

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.

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.

@stenslae
stenslae force-pushed the audit-entropy-mutex branch from 1b65c7a to eb4b2dd Compare October 7, 2026 21:32
@stenslae
stenslae requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot October 7, 2026 21:35

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.

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

Scan targets checked: wolfssl-bugs
Unchanged since last review (not re-run): wolfcrypt-src, wolfcrypt-bugs
Coverage: 1 of 1 in-scope changed file(s) opened by the reviewer

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.

Review tier: Lite

@stenslae
stenslae force-pushed the audit-entropy-mutex branch from eb4b2dd to 52173d9 Compare October 9, 2026 19:59
@stenslae
stenslae requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot October 9, 2026 20:00

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

Initialization readiness can be published before startup completes, allowing a concurrent caller to return success prematurely.

2 open findings

🧠 Review effort: Balanced

Comment thread wolfcrypt/src/wolfentropy.c Resolved

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

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

@stenslae
stenslae requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot October 28, 2026 22:10
@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 concurrency- and FIPS-sensitive entropy and mutex lifecycle changes need maintainer runtime validation, since comment-only test updates do not verify concurrent first use, cleanup/reinitialization without static mutex initializers, or counter-thread builds.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@claude claude 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.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Comment thread wolfcrypt/src/wolfentropy.c Resolved

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

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/wolfentropy.h
Coverage: 2 of 2 in-scope changed file(s) opened by the reviewer

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.

Review tier: Lite

@stenslae
stenslae requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot October 28, 2026 22:47
@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.

🟢 Approval recommended

No active review issues are reported for the wolfEntropy mutex-ownership and initialization-race changes.

No open issues 🎉

Review effort: Balanced

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

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/wolfentropy.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 their stale review October 28, 2026 22:51

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

@claude claude 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.

Code review found no issues

No high-confidence issues detected in this change.

@stenslae stenslae assigned lealem47 and unassigned stenslae Oct 28, 2026

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

Entropy bootstrap changes require maintainer validation with a FIPS source bundle and dynamic-mutex/counter-thread configurations to verify pre-init KATs and concurrent first use beyond this source-only review.

No open issues 🎉

Review effort: Balanced

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

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/wolfentropy.h
Coverage: 3 of 3 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

* builds. The startup health test runs below, under the mutex.
*/
if (!entropy_memuse_initialized) {
ret = Entropy_Init();

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.

Why delete the Lazy Init path for FIPS builds?


#ifdef HAVE_FIPS
if (!entropy_memuse_initialized) {
ret = Entropy_Init();

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.

Why delete the Lazy Init path for FIPS builds?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Lazy init was moved rather than being deleted. It's in the new Entropy_SetupAndLock(), which every entry point calls, so the lazy init runs in all builds, not only HAVE_FIPS. The old FIPS block was the race this commit fixes. It checked entropy_memuse_initialized without the lock and then re-ran wc_InitMutex(). Now the mutex is created once with wc_local_InitMutexOnce(), and the SHA-3 setup runs under the lock.

@lealem47 lealem47 assigned stenslae and unassigned lealem47 Oct 30, 2026
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.

7 participants