wolfSSL — Writable Exported Global Selecting the AArch64 Speculation Barrier in XFENCE
On AArch64 builds with barrier detection, the choice between the sb and isb speculation barriers in XFENCE() is held in aarch64_use_sb, a non-const int declared extern in a public header. Code already running in the process can clear it to downgrade every barrier to isb, or set it on a CPU without sb to cause an illegal-instruction fault.
- Advisory
- BYTERAY-2026-0481
- 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), AArch64 builds configured with --enable-armasm=barrier-detect (WOLFSSL_ARMASM_BARRIER_DETECT)
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
On 64-bit ARM, wolfSSL can pick the speculation barrier used by its XFENCE() macro at run time. With barrier detection enabled, wolfCrypt_Init() reads the CPU feature flags once and stores the result in a global integer, aarch64_use_sb. XFENCE() emits the sb instruction when the flag is set and the weaker isb when it is not.
The flag is an ordinary writable int. It is declared extern in a shipped public header, so it is an exported symbol. Nothing checks it again after initialization. Any code in the same process can write to it and change the barrier used at every fence site for the rest of the process lifetime.
There is no remote path. The writer has to be code already running in the process, an interposed symbol, or an existing arbitrary-write primitive. Clearing the flag gives the behaviour of a default build. Default builds do not contain the flag.
Affected Products and Versions
- Component:
wolfcrypt/src/wc_port.c(definition and initialization) andwolfssl/wolfcrypt/wc_port.h(XFENCE()). - Required build:
__aarch64__withWOLFSSL_ARMASM_BARRIER_DETECT, set by--enable-armasm=barrier-detect(configure.ac:4382-4391,configure.ac:4578-4579). - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default build does not define the flag. Without the option,
XFENCE()on AArch64 is a plainisb. - Other releases were not checked.
Technical Details
The flag is defined at wolfcrypt/src/wc_port.c:430 as int aarch64_use_sb = 0;. Its only writer in the tree is wolfCrypt_Init(), which assigns IS_AARCH64_SB(cpuid_get_flags()) to it (wolfcrypt/src/wc_port.c:796). IS_AARCH64_SB tests the CPUID_SB bit (wolfssl/wolfcrypt/cpuid.h:168).
The public header declares it and reads it inside the macro (wolfssl/wolfcrypt/wc_port.h:2100-2107):
extern int aarch64_use_sb;
#define XFENCE() \
do { \
if (aarch64_use_sb) \
XASM_VOLATILE(".inst 0xd50330ff"); \
else \
XASM_VOLATILE("isb"); \
} while (0)
The flag has four touch points in the tree: the definition, the extern declaration, the writer and the read in XFENCE(). There is no accessor and no const qualifier. Because the symbol has external linkage and is in a public header, it is part of the library ABI.
Sequence:
wolfCrypt_Init()sets the flag from the CPU feature flags.- An in-process writer stores a different value in the exported symbol.
- Every later
XFENCE()uses the new value. The call sites arewolfcrypt/src/asn.c:1920,wolfcrypt/src/asn.c:1948,wolfcrypt/src/asn.c:2018,src/ssl_sess.c:1822andsrc/ssl_sess.c:1836. TheWC_BARRIERmacros in the same header do not read the flag and are not affected.
Reachability and Preconditions
- AArch64 build with
--enable-armasm=barrier-detect. - The attacker already runs code in the process (a malicious or compromised library or plugin), can interpose the exported symbol, or holds an arbitrary-write primitive. No remote or unprivileged path reaches the flag.
Impact
Clearing the flag replaces sb with isb at every fence. That is the behaviour of a build without barrier detection, so the loss is an optional hardening, not a baseline guarantee. Setting the flag on a CPU without the sb instruction raises an illegal-instruction fault at each fence site, which crashes the process.
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 take the flag off the writable exported surface: remove the extern declaration from the public header, give the definition internal linkage, and expose a read-only query function if other translation units need the value. Where the target CPU is known at build time, the barrier can be selected at compile time instead. Builds that know the target supports sb can use --enable-armasm=barrier-sb, which selects the instruction at compile time and does not use the flag.
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.