wolfSSL — Radix Alphabet Pointer Left Exported and Writable in Heap Math but Static in Fast Math
The heap math backend keeps its radix alphabet behind mp_s_rmap, a non-const global pointer exported by a public header. mp_read_radix and mp_toradix index it up to 64 entries without a length check, so in-process code that repoints it causes wrong conversions and reads past the replacement string. The fast math backend already keeps its copy of the table static.
- Advisory
- BYTERAY-2026-0487
- CWE
- CWE-500
- CVSS
- 3.9 (CVSS:3.1/AV:L/AC:H/PR:H/UI:N/S:U/C:L/I:L/A:L)
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-28
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 (tested at master commit d95483f), builds that use the heap math backend (USE_INTEGER_HEAP_MATH, --enable-heapmath)
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
The heap math big-integer backend in wolfcrypt/src/integer.c converts numbers to and from text with a 64-character alphabet. The alphabet sits behind a global pointer, mp_s_rmap. The characters are const. The pointer is not, and a public header declares it extern.
mp_read_radix() and mp_toradix() index the table with a fixed bound of 64 and never check the length of the string the pointer refers to. Code in the same process that points mp_s_rmap at a shorter string makes both functions read past the end of that string and return wrong conversions.
The fast math backend holds the same alphabet in a file-local static object, and the SP math backend has no such global. The heap math backend is the only one that still exports a writable pointer. It is not part of a default build, and the pointer cannot be changed from outside the process.
Affected Products and Versions
- Component:
wolfcrypt/src/integer.c, globalmp_s_rmap, consumed bymp_read_radix()andmp_toradix(). - Required build: the heap math backend,
USE_INTEGER_HEAP_MATHwithoutUSE_FAST_MATH(wolfcrypt/src/integer.c:31).--enable-heapmathsets it (configure.ac:1337-1343). - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild uses SP math and does not compile this code. - Other releases were not checked.
Technical Details
The table is defined at wolfcrypt/src/integer.c:5289-5290:
const char *mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz+/";
The const qualifier covers the characters only. The pointer variable is writable data with external linkage. wolfssl/wolfcrypt/integer.h:311 declares it as extern const char *mp_s_rmap;, so any program that includes the header can assign to it.
The consumers assume the table always has 64 entries:
mp_read_radix()compares each input character againstmp_s_rmap[y]foryfrom 0 to 63 (wolfcrypt/src/integer.c:5328-5332).mp_toradix()writesmp_s_rmap[d]for each output digit (wolfcrypt/src/integer.c:5485).mp_toradix()writesmp_s_rmap[0]as zero padding for hexadecimal output with an odd digit count (wolfcrypt/src/integer.c:5491).
Neither function looks at the length of the string behind the pointer. If the pointer refers to a string shorter than 64 characters, the scan in step 1 continues past its terminator, and the digit values it returns no longer match the intended alphabet.
The fast math backend shows the intended shape. Its table is static wcchar fp_s_rmap (wolfcrypt/src/tfm.c:5660-5661), which keeps it out of the external symbol table. The heap math table was not given the same treatment. BYTERAY-2026-0486 describes the exported pointer itself.
Reachability and Preconditions
- The library is built with the heap math backend. The header declaration is present when ECC, key generation, compressed keys or math debugging is enabled (
wolfssl/wolfcrypt/integer.h:309-312). - The attacker already runs code inside the process, or holds a separate memory-write primitive that reaches the pointer.
- There is no remote path to the pointer. No input to the library changes it.
- No authentication state is involved.
Impact
After the pointer has been changed, radix parsing and printing in that process return wrong values, and both functions read up to 64 bytes from wherever the pointer leads. This adds to what an in-process attacker can already do. It does not give a remote party a way in.
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 the one already used in the fast math backend: give the table internal linkage and make the pointer itself const, and remove the extern declaration from the public header. If replacing the alphabet at run time is meant to be supported, a setter that accepts only a 64-character table is the safer interface. A length clamp in mp_read_radix() and mp_toradix() is a further safeguard. Builds that use SP math or fast math are not affected. Moving off the heap math backend removes the exported 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.