← ALL ADVISORIES

LOW BYTERAY-2026-0524Disclosed

wolfSSL — Removable Memory Wipe in Fastmath fp_clear on Non-FIPS Builds

In the fastmath backend, fp_clear wipes an integer's digits with the hardened force-zero routine only in FIPS builds. Other builds use a plain memset with no barrier, which an optimizing compiler is allowed to remove. The main key-free paths wipe their secrets separately, so the exposure is limited.

Advisory
BYTERAY-2026-0524
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), non-FIPS builds that use the fastmath big-integer backend (USE_FAST_MATH, --enable-fastmath)
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

In wolfSSL's fastmath big-integer backend, every integer is released through fp_clear(), which is meant to scrub the digit array first. In a FIPS build it calls fp_forcezero(), whose wipe is protected against removal by the compiler. In every other build it runs a plain XMEMSET over the digits. Nothing reads the digits afterwards and no barrier follows, so a compiler may delete the zeroing as a dead store.

The practical reach is narrow. Fastmath is not the default backend. The routines that free RSA, ECC and DH keys, and the key-agreement code, wipe their secret values with the hardened routine before they release the integers. Removing the XMEMSET needs whole-program optimization, because fp_clear() is an exported, non-inline function. Reading leftover bytes needs a separate memory disclosure.

The gap is a hardening defect in a non-default configuration: the zeroization guarantee of fp_clear() holds in one build configuration only.

Affected Products and Versions

  • Component: wolfcrypt/src/tfm.c, fp_clear(). mp_clear() in the same file delegates to it (wolfcrypt/src/tfm.c:4432-4437).
  • Required build: USE_FAST_MATH without HAVE_FIPS. --enable-fastmath is off by default (configure.ac:474-477).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • A default ./configure build uses the SP math backend, where mp_clear maps to sp_clear (wolfssl/wolfcrypt/sp_int.h:1384), and does not compile this function.
  • Other releases were not checked.

Technical Details

The body of fp_clear() splits on the build (wolfcrypt/src/tfm.c:4377-4393):

#ifdef HAVE_FIPS
    fp_forcezero(a);
#else
    ...
    XMEMSET(a->dp, 0, size * sizeof(fp_digit));
    fp_free(a);
#endif
  1. Under HAVE_FIPS, fp_forcezero() wipes the digits through ForceZero(), which carries the library's dead-store barrier.
  2. Otherwise the digits are cleared with XMEMSET (wolfcrypt/src/tfm.c:4390) and fp_free() follows (wolfcrypt/src/tfm.c:4421-4428). fp_free() does nothing unless HAVE_WOLF_BIGINT is defined.
  3. The stores are non-volatile and the caller then abandons the object. There is no volatile access, no memset_s or explicit_bzero, and no assembly barrier. A compiler that can see the whole flow may remove the stores.

Two things limit the effect. First, the callers that hold secrets do not depend on this wipe. wc_FreeRsaKey() force-zeroes the private components and uses mp_clear() for the public ones (wolfcrypt/src/rsa.c:689-700). wc_ecc_free() force-zeroes the private scalar and its blinding values (wolfcrypt/src/ecc.c:8660-8669). wc_FreeDhKey() force-zeroes the private value (wolfcrypt/src/dh.c:1043), and the DH agreement code force-zeroes its secret temporaries (wolfcrypt/src/dh.c:2354-2356). Second, at ordinary per-file optimization the compiler cannot prove the stores dead through the pointer argument of an exported function. Link-time optimization or cross-module inlining is needed.

Reachability and Preconditions

  • Non-FIPS build with the fastmath backend.
  • A build that uses link-time optimization or equivalent, and a compiler that then removes the XMEMSET.
  • An integer holding sensitive data that is released with mp_clear() or fp_clear() without an earlier mp_forcezero().
  • A separate way for an attacker to read process memory, such as a heap over-read, a core dump or physical memory capture.

Impact

Digits of a big integer can remain in memory after fp_clear() returns. For the private keys and shared secrets that the library's own key-free and agreement paths handle, the hardened wipe has already run, so the remaining exposure is to values freed without it. This is a missing hardening guarantee in a non-default build, not a directly reachable leak of secrets.

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 call fp_forcezero() in fp_clear() in all configurations and drop the plain XMEMSET branch, so FIPS and non-FIPS builds share one wipe that resists removal. The existing mp_forcezero() calls at the key-free and agreement sites should stay. Builds on the default SP math backend do not compile this function. Note that the hardened wipe itself has a weaker barrier on some toolchains; see BYTERAY-2026-0523.

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.

References