← ALL ADVISORIES

LOW BYTERAY-2026-0482Disclosed

wolfSSL — Missing Encapsulation of the AArch64 Barrier Flag Compared With CPUID Capability Flags

wolfSSL keeps its CPU capability flags in static atomic storage behind accessor functions, but the flag that selects the AArch64 speculation barrier for XFENCE(), aarch64_use_sb, is a plain exported int read without atomics. It did not receive the protection the library applies to its other capability-gating state.

Advisory
BYTERAY-2026-0482
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

wolfSSL detects CPU features at run time and uses the results to choose code paths. For the general capability flags the library has a consistent pattern: the value lives in a static atomic object inside one source file and other code reaches it only through API functions.

The flag that selects the AArch64 speculation barrier does not follow that pattern. aarch64_use_sb is a non-static, non-const, non-atomic int, declared extern in a public header and read directly by the XFENCE() macro on every use. The symbol is exported, so code linked into the same process can overwrite it.

BYTERAY-2026-0481 describes the exposure of the flag itself. This advisory covers the inconsistency: state that gates a defence is left outside the encapsulation the library already uses for comparable state. The flag exists only in opt-in AArch64 builds, and changing it needs code execution or a write primitive inside the process.

Affected Products and Versions

  • Component: wolfcrypt/src/wc_port.c and wolfssl/wolfcrypt/wc_port.h, the aarch64_use_sb flag and XFENCE().
  • Required build: __aarch64__ with WOLFSSL_ARMASM_BARRIER_DETECT, set by --enable-armasm=barrier-detect (configure.ac:4578-4579).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • A default build does not compile the flag.
  • Other releases were not checked.

Technical Details

The barrier flag:

  1. Defined as int aarch64_use_sb = 0; with no static, const or atomic type (wolfcrypt/src/wc_port.c:430).
  2. Declared extern int aarch64_use_sb; in a header shipped to all consumers (wolfssl/wolfcrypt/wc_port.h:2100).
  3. Written once, by wolfCrypt_Init() (wolfcrypt/src/wc_port.c:796). There is no accessor and no later re-validation.
  4. Read with a plain load inside XFENCE() to choose sb or isb (wolfssl/wolfcrypt/wc_port.h:2103).

The pattern used elsewhere:

  • The cpuid subsystem stores its flags as static cpuid_flags_atomic_t cpuid_flags (wolfcrypt/src/cpuid.c:29). Other code changes them only through cpuid_select_flags(), cpuid_set_flag() and cpuid_clear_flag() (wolfssl/wolfcrypt/cpuid.h:253-255), and reads use atomic loads.
  • Per-file copies of the capability flags follow the same discipline, for example in wolfcrypt/src/wc_slhdsa.c:80, wolfcrypt/src/wc_mlkem_poly.c:120, wolfcrypt/src/wc_mldsa.c:207, wolfcrypt/src/sha256.c:456 and wolfcrypt/src/sha512.c:1172.

The barrier flag is derived from the same cpuid data but is then published as a writable global. XFENCE() is invoked at wolfcrypt/src/asn.c:1920, wolfcrypt/src/asn.c:1948, wolfcrypt/src/asn.c:2018, src/ssl_sess.c:1822 and src/ssl_sess.c:1836; those are the sites whose barrier depends on the flag.

Reachability and Preconditions

  • AArch64 build with --enable-armasm=barrier-detect.
  • A writer inside the process: a linked or loaded module, an interposed symbol, or an arbitrary-write primitive.
  • No remote or unprivileged path reaches the flag.

Impact

A write of zero changes every fence from sb to isb, which weakens the transient-execution protection the option was enabled to provide. A non-zero write on a CPU without sb causes an illegal-instruction fault at the next fence. Both require the attacker to already execute code in the process, so the practical risk is limited to deployments that enable this hardening and load code they do not fully trust.

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 apply the cpuid pattern to this flag: remove the extern declaration from the public header, make the definition file-scope static with an atomic type, read it with an atomic load in XFENCE() or through a read-only getter, and provide no public way to change it after wolfCrypt_Init().

There is no run-time workaround. Builds for a target known to support sb can select the barrier at compile time and avoid 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.

References