Repository navigation
Conversation
|
There was a problem hiding this comment.
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
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
left a comment
There was a problem hiding this comment.
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
3479616 to
9c11a59
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
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
9c11a59 to
1b65c7a
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
Copilot review overview
Review effort: Lite
Findings: 5
Open (5)
wb_regressis used as the “real failure” indicator, but the name is ambiguous (it reads like… · Newwb_entropy_get_mutex()reports a skip viaWB_NOTE(...)but doesn’t set any flag that affects… · New In production code,Entropy_StartThread()/Entropy_StopThread()are invoked while holding… · New Same issue as inwb_entropy_get_mutex(): this early-return “skip” path is not reflected in the… · Newwb_regressis used as the “real failure” indicator, but the name is ambiguous (it reads like… · New
Resolved since last review (1)
1b65c7a to
eb4b2dd
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Entropy-source synchronization needs platform-specific maintainer validation, and assertion-failure reporting remains unresolved.
1 open finding
5 resolved since last review
wb_regressis used as the “real failure” indicator, but the name is ambiguous (it reads like… Same issue as inwb_entropy_get_mutex(): this early-return “skip” path is not reflected in the… In production code,Entropy_StartThread()/Entropy_StopThread()are invoked while holding…wb_entropy_get_mutex()reports a skip viaWB_NOTE(...)but doesn’t set any flag that affects…wb_regressis used as the “real failure” indicator, but the name is ambiguous (it reads like…
🧠 Review effort: Balanced
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
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
eb4b2dd to
52173d9
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
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
| /* Dispose of the SHA3-356 hash object. */ | ||
| wc_Sha3_256_Free(&entropyHash); | ||
| #if !defined(SINGLE_THREADED) && !defined(WOLFSSL_MUTEX_INITIALIZER) | ||
| wc_FreeMutex(&entropy_mutex); |
There was a problem hiding this comment.
Can we free this mutex based on entropy_mutex_init instead of basing it on entropy_memuse_initialized to avoid leaking in the case where the mutex is successfully created but Entropy_Init() ultimately fails?
There was a problem hiding this comment.
Sure, changed it so Entropy_Final() now frees the mutex whenever entropy_mutex_init == 2, whether or not init succeeded, and resets the flag to 0 so a later Entropy_Init() re-creates it.
There was a problem hiding this comment.
Okay that sounds good. Can you move define ENTROPY_MUTEX_READY 2U to wc_port.h? And use that in wc_local_InitMutexOnce instead of the hard coded 2? Then we can use the same macro in Entropy_Final()
#define WC_MUTEX_READY_ONCE 2U might be a better name if we're making it global
| /* MemUse entropy global state initialized. Published with a release store | ||
| * after all startup work succeeds; checked with an acquire load on the | ||
| * fast-path so a reader seeing 1 is guaranteed to see a complete init. */ | ||
| static wolfSSL_Atomic_Int entropy_memuse_initialized = WOLFSSL_ATOMIC_INITIALIZER(0); |
There was a problem hiding this comment.
MEDIUM-2: Switching entropy_memuse_initialized from `volatile int` to wolfSSL_Atomic_Int drops volatile in threaded WOLFSSL_NO_ATOMICS builds [SUGGEST] (bug)
File: wolfcrypt/src/wolfentropy.c:69-72
Function: (file scope)
Confidence: Medium
The flag changes from `static volatile int` to `static wolfSSL_Atomic_Int`. In every config where `WOLFSSL_ATOMIC_OPS` gets defined this is a strict improvement (seq_cst load/store, which subsumes the acquire/release the new comments describe). But when no atomic backend matches, `wolfssl/wolfcrypt/wc_port.h:645-653` falls back to `typedef int wolfSSL_Atomic_Int;` with `WOLFSSL_ATOMIC_LOAD(x) (x)` / `WOLFSSL_ATOMIC_STORE(x, val) (x) = (val)` — and that header comment is explicit that it is *not* volatile: "_NO_ATOMICS configs promise no concurrent mutation (single-threaded, or externally serialized)".
That promise does not hold here: `HAVE_ENTROPY_MEMUSE` with `!SINGLE_THREADED` is genuinely multi-threaded and the flag is the subject of the double-checked lock in `Entropy_Init()`. Such a build is narrow but real — a threaded target whose compiler matches none of the atomic arms (no `WOLFSSL_USER_DEFINED_ATOMICS`, not BSDKM, no C11 `<stdatomic.h>`, not GNUC `__ATOMIC_SEQ_CST`, not MSVC/Windows — e.g. older IAR/Keil/CC-RX with an RTOS), or any user who sets `WOLFSSL_NO_ATOMICS` in `user_settings.h`. There, the compiler is free to collapse the two `WOLFSSL_ATOMIC_LOAD(entropy_memuse_initialized)` reads in `Entropy_Init()` into one, defeating the re-check that the diff adds — something the old `volatile` prevented.
Related: the new comments say "Published with a release store ... checked with an acquire load" and "Release store: publish only after all startup work has succeeded." Those hold under `WOLFSSL_ATOMIC_OPS` but not in the fallback, where the macros carry no ordering at all.
Code:
-/* MemUse entropy global state initialized. */
-static volatile int entropy_memuse_initialized = 0;
+/* MemUse entropy global state initialized. Published with a release store
+ * after all startup work succeeds; checked with an acquire load on the
+ * fast-path so a reader seeing 1 is guaranteed to see a complete init. */
+static wolfSSL_Atomic_Int entropy_memuse_initialized = WOLFSSL_ATOMIC_INITIALIZER(0);
Recommendation: Either keep `volatile` for the `WOLFSSL_NO_ATOMICS && !SINGLE_THREADED` case, or qualify the new comments to say the acquire/release guarantee applies only when `WOLFSSL_ATOMIC_OPS` is defined (matching how `wc_local_InitMutexOnce()` in wc_port.c:3052 explicitly documents and branches on that distinction). Also note the line is 84 characters, over the project's 80-column convention — wrap the initializer.
There was a problem hiding this comment.
Returned that back to using volatile.
… the counter thread or unlocking
5eb688f to
00e748a
Compare
|
@claude review |
There was a problem hiding this comment.
🔵 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
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
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
|
@claude review |
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
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
Fenrir's latest completed scan found no issues; clearing the prior automated change request.



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