wolfSSL — Missing Zeroization of Saved SRP Password in CTX SRP API
When the SRP password is set before the username, wolfSSL_CTX_set_srp_password keeps a cleartext copy on the heap in the WOLFSSL_CTX. All three paths that release that copy free it without overwriting it, so the password stays in freed memory.
- Advisory
- BYTERAY-2026-0544
- CWE
- CWE-316
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-28
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 (tested at master commit d95483f), builds with OPENSSL_EXTRA and WOLFCRYPT_HAVE_SRP (the OpenSSL compatibility layer with SRP enabled)
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
An application that uses TLS-SRP through the OpenSSL compatibility layer can set the password before the username. In that case wolfSSL_CTX_set_srp_password() keeps a copy of the cleartext password in a heap buffer attached to the WOLFSSL_CTX, to use once the username arrives.
Three code paths release that copy: after the password has been passed to the SRP object, when the application replaces a saved password, and when the context is freed. Each one calls XFREE without overwriting the buffer first. The cleartext stays in freed heap memory.
It can then be recovered from a core dump, a swap image, a crash artifact or through another bug that discloses process memory. No network input is involved. The code is compiled only with OPENSSL_EXTRA and SRP support, and SRP is off by default.
Affected Products and Versions
- Component:
src/ssl_api_pk.c,wolfSSL_CTX_set_srp_password(), and the context teardown inFreeSSL_Ctx(src/internal.c). - Required build:
OPENSSL_EXTRAandWOLFCRYPT_HAVE_SRP. The second is set by--enable-srp, by--enable-libest, and by the Apple HomeKit and Espressif settings blocks inwolfssl/wolfcrypt/settings.h. - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild does not include this code, because SRP is off by default. - Other releases were not checked.
Technical Details
wolfSSL_CTX_set_srp_password() (src/ssl_api_pk.c:2920) checks its arguments for NULL (src/ssl_api_pk.c:2926). When no username is set, it allocates a buffer and copies the password, including its terminator, into ctx->srp_password (src/ssl_api_pk.c:2960-2966). wolfSSL_CTX_set_srp_username() later passes that saved copy back into the setter (src/ssl_api_pk.c:2898-2902).
The copy is released in three places, none of which wipes it:
- After
wc_SrpSetPasswordhas consumed the password (src/ssl_api_pk.c:2954-2955). - When a new password is saved before a username, replacing the old copy (
src/ssl_api_pk.c:2958). - In
FreeSSL_Ctx, when the context is freed (src/internal.c:3336).
XFREE(ctx->srp_password, ctx->heap, DYNAMIC_TYPE_SRP);
ctx->srp_password = NULL;
XFREE resolves to wolfSSL_Free or free in a default memory configuration (wolfssl/wolfcrypt/types.h:885-891), which does not overwrite the buffer. There is no zeroization of srp_password anywhere in its lifetime.
The line after the teardown free calls wc_SrpTerm (src/internal.c:3338). That function clears the salt, user and key with ForceZero and the auth and priv values with mp_forcezero before freeing them (wolfcrypt/src/srp.c:300-322). The raw password buffer is the one SRP secret that the teardown does not wipe.
Reachability and Preconditions
- Build with
OPENSSL_EXTRAandWOLFCRYPT_HAVE_SRP. - The application uses client-side TLS-SRP and calls
wolfSSL_CTX_set_srp_passwordbefore it sets the username. - The attacker can read the process's memory after the buffer is released: a core dump, a swap or page file, a crash artifact, a forensic image or a separate memory disclosure bug in the same process. This is local access, not a network path.
- The freed chunk has not yet been overwritten by later allocations.
Impact
Recovery of the cleartext SRP password from memory artifacts. The password is a long-lived credential and can be reused. The flaw gives no code execution or privilege change by itself; it increases what a separate memory disclosure reveals.
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 wipe the buffer with ForceZero, over its string length, immediately before each of the three frees. A plain memset before free is not sufficient, because the compiler may remove it. The retention window can also be narrowed, by wiping the saved copy as soon as it has been consumed, or by requiring the application to supply the password again after it sets the username.
Workaround: in the application, call wolfSSL_CTX_set_srp_username before wolfSSL_CTX_set_srp_password. The password is then passed to the SRP object directly and the saved copy is never created.
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.