wolfSSL — Removable Memory Wipe in ForceZero on Builds Without GNU Inline Assembly
ForceZero, the helper wolfSSL uses to wipe secrets, depends on the WC_BARRIER_DATA macro to stop the compiler from deleting its stores. Without GNU inline assembly that macro only evaluates the pointer and touches an unrelated volatile local, so the wipe can legally be removed and secrets can remain in memory.
- Advisory
- BYTERAY-2026-0523
- CWE
- CWE-733
- CVSS
- 2.5 (CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:L/I:N/A:N)
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-28
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 (tested at master commit d95483f), builds compiled without GNU inline assembly: MSVC, IAR, Keil, and any build with WOLFSSL_NO_ASM
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
Almost every wipe of secret material in wolfSSL goes through one helper, ForceZero(): handshake key blocks, pre-master and master secrets, session state, DRBG state, private scalars and post-quantum private keys. The helper writes zeros with ordinary stores and relies on a barrier macro, WC_BARRIER_DATA, to keep the compiler from treating those stores as dead.
With GNU inline assembly the barrier is an empty assembly statement with a memory clobber, and it holds. On other toolchains, and on any build with WOLFSSL_NO_ASM, the barrier falls back to a construct that reads only the pointer and writes a volatile local that has nothing to do with the buffer. Under the C rules a compiler may then delete the zeroing stores. The affected configurations include the default MSVC x86/x64 Windows build, IAR and Keil.
Where the stores are removed, the secret stays in stack or heap memory after the code has apparently cleared it. Reading it takes a separate memory disclosure. Whether a given compiler removes the stores depends on its version and options. Builds with GCC or Clang and inline assembly keep the strong barrier.
Affected Products and Versions
- Component:
wolfcrypt/src/misc.c,ForceZero(), exported aswc_ForceZero()(wolfcrypt/src/memory.c:1719-1725), and the barrier macros inwolfssl/wolfcrypt/wc_port.h. - Affected configurations: compilers without GNU inline assembly (MSVC, IAR, Keil) and builds that define
WOLFSSL_NO_ASM. Some shipped IDE settings define it, for exampleIDE/C2000/user_settings.h:26. - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild with GCC or Clang uses the inline-assembly barrier and is not affected. The default MSVC x86/x64 build takes the fallback. - Other releases were not checked.
Technical Details
ForceZero() (wolfcrypt/src/misc.c:789-824) zeroes the buffer through plain byte * and unsigned long * stores, with WC_BARRIER_DATA(mem) before and after (wolfcrypt/src/misc.c:796, wolfcrypt/src/misc.c:823). The macro has two forms (wolfssl/wolfcrypt/wc_port.h:2138-2145):
#elif defined(__GNUC__) && !defined(WOLFSSL_NO_ASM)
#define WC_BARRIER_DATA(ptr) \
__asm__ __volatile__("" : : "r"(ptr) : "memory")
#else
#define WC_BARRIER_DATA(ptr) do { (void)(ptr); WC_BARRIER(); } while (0)
#endif
In the fallback:
(void)(ptr)evaluates the pointer. It does not read the bytes that were wiped.- The fallback
WC_BARRIER()writes a volatile local,_xfence, and callsXFENCE()(wolfssl/wolfcrypt/wc_port.h:2122-2132). The local is unrelated to the buffer. XFENCE()expands to nothing on MSVC x86/x64 (wolfssl/wolfcrypt/wc_port.h:2115-2116) and onWOLFSSL_NO_ASMbuilds (wolfssl/wolfcrypt/wc_port.h:2085-2086). MSVC on ARM64 gets an__isbfence (wolfssl/wolfcrypt/wc_port.h:2091-2094).
The zeroing stores are then non-volatile stores to memory that is not read again, with no opaque code between them and the end of the buffer's life. A conforming compiler may remove them. ForceZero() is declared WC_INLINE, which is __inline on MSVC (wolfssl/wolfcrypt/wc_port.h:116), so with optimization it is inlined into callers where the buffer is dead on return.
The source comments describe the intent: the fallback is called an "additional (but weak) portable barrier", and the comment above the final barrier in ForceZero() says the compiler may drop the stores and that the barrier makes the buffer look read by opaque code. The fallback form does not do that. Both macros can be overridden by the user; no override is defined in the tree. Callers include TLS 1.3 and TLS 1.2 key derivation (src/tls13.c:1908, src/tls.c:591), pre-master secret teardown (src/internal.c:9104-9108) and the wipe of big-integer digits (wolfcrypt/src/sp_int.c:5419).
Reachability and Preconditions
- The library is compiled with a toolchain or setting that selects the fallback barrier.
- The compiler, at the chosen optimization level, actually removes the stores. This varies by compiler, version and flags and was not measured.
- To recover a secret, an attacker needs a separate way to read process memory, such as a heap over-read, a core dump or physical memory capture. This issue does not provide one.
Impact
On affected builds the library cannot guarantee that key material is erased after use. Secrets that should have been wiped can remain in freed heap memory or on the stack, where an independent memory-disclosure issue could expose them. The gap in the guarantee is present in every affected configuration; actual retention depends on the compiler.
ByteRay did not build a proof of concept for this issue. The analysis is from source review.
Remediation and Mitigation
ByteRay has not confirmed a fixed wolfSSL release for this issue as of 2026-12-03, and has not checked it against wolfSSL changes made after the tested commit.
The fix direction is to make the wipe non-removable on every toolchain: use SecureZeroMemory, memset_s, explicit_bzero or memset_explicit where the platform has one; make the fallback barrier perform a volatile read of the wiped buffer after the stores; and give XFENCE() a real implementation on MSVC, IAR and Keil. A build-time or startup self-test and compiler coverage for MSVC and WOLFSSL_NO_ASM would catch a regression. Integrators on affected toolchains can supply their own WC_BARRIER_DATA definition that reads the buffer through a volatile pointer.
Timeline
- 2026-09-28 — Reported to wolfSSL.
- 2026-12-03 — Public disclosure.
Credits
Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.