← ALL ADVISORIES

MEDIUM BYTERAY-2026-0356Disclosed

wolfSSL — Pre-Existing Shared Memory Object Trusted Without Validation as the MAXQ10xx Hardware Lock

MAXQ10xx builds keep the hardware crypto lock in a POSIX shared memory object with the fixed name /maxq-mutex and use an existing object without checking its owner, mode or contents. A local user who creates the object first can make wolfCrypt_Init() fail or make hardware operations block in every process that uses the secure element.

Advisory
BYTERAY-2026-0356
CWE
CWE-412
CVSS
5.5 (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H)
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-28
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 through 5.9.4, builds with --with-maxq10xx and pthreads (MAXQ10XX_MUTEX), on hosts with untrusted local users
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

In MAXQ1065 and MAXQ1080 builds with pthreads, all processes on a host serialize access to the secure element through one process-shared mutex. The mutex lives in a POSIX shared memory object that wc_InitMutex() opens under the fixed name /maxq-mutex. If the object exists, the function maps it and uses it. It does not look at who owns it, what its permissions are, or whether its contents are an initialized mutex.

The shared memory namespace is writable by every local user. A user who creates an object with that name before the legitimate application does controls the lock. If the object's permissions deny access, wc_InitMutex() fails on every attempt and wolfCrypt_Init() returns an error. If the permissions allow access, the application adopts the object as its lock, and whoever else has it mapped can hold that lock for as long as they like. The lock is taken with an untimed pthread_mutex_lock().

The library never removes the object, so the condition lasts until someone with the right to delete it does so or the system restarts. The attacker needs a local account on the device and has to act before the object exists. wolfSSL master has reworked the function but still uses a fixed name and does not check ownership. A default ./configure build does not compile this code.

Affected Products and Versions

  • Component: wolfCrypt port layer, the MAXQ10XX_MUTEX variant of wc_InitMutex() in wolfcrypt/src/wc_port.c.
  • Required build: --with-maxq10xx=MAXQ1065 or --with-maxq10xx=MAXQ108x with pthreads, which defines WOLFSSL_CRYPT_HW_MUTEX and MAXQ10XX_MUTEX (wolfssl/wolfcrypt/settings.h:2536-2539) and selects this mutex implementation (wolfssl/wolfcrypt/wc_port.h:446-451).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • The v5.9.2-stable and v5.9.4-stable tags contain the same code.
  • Partly addressed on master by commit b2c719310556e6f491f99e652388bad4de4c457b (PR 12067). See Remediation.
  • A default ./configure build does not include this code. Earlier releases were not checked.

Technical Details

The open sequence, at wolfcrypt/src/wc_port.c:3295-3300:

        int shm_fd = shm_open("/maxq-mutex", O_RDWR, 0666);
        if (shm_fd < 0) {
            /* create mutex memory */
            shm_fd = shm_open("/maxq-mutex", O_RDWR | O_CREAT | O_EXCL, 0666);
            created = 1;
        }

If both opens fail the function returns BAD_MUTEX_E (wolfcrypt/src/wc_port.c:3302-3305). Otherwise it calls ftruncate() on the object, maps it and stores the mapping as the global lock (wolfcrypt/src/wc_port.c:3307-3320). It initializes the mutex only if created is set (wolfcrypt/src/wc_port.c:3327-3346). There is no fstat() and no check of size, owner or mode anywhere in the function.

Two outcomes follow from an object that someone else created first.

  1. The existing object does not grant this process read and write access. The first open fails. The second open fails because the name exists. The function returns BAD_MUTEX_E. wolfSSL_CryptHwMutexInit() leaves its flag clear on failure (wolfcrypt/src/wc_port.c:2686-2698), so every later attempt repeats the same failure. wolfCrypt_Init() treats the failure as fatal and returns the error (wolfcrypt/src/wc_port.c:877-884).
  2. The existing object grants access. The first open succeeds, created stays 0, and the contents are used as a pthread_mutex_t as they are. Every hardware operation then goes through maxq_LockMutex(), which calls pthread_mutex_trylock() or a blocking pthread_mutex_lock() on that memory (wolfcrypt/src/wc_port.c:3420-3425). Another party with the object mapped can keep the mutex locked, or leave contents that are not a valid mutex.

In the second case the result depends on the call site. maxq10xx_port_init() uses the try-lock; when it fails, the function logs that the device is busy and returns success without initializing the module (wolfcrypt/src/port/maxim/maxq10xx.c:2446-2452), so the process continues without the hardware. The port has 31 call sites of the blocking wolfSSL_CryptHwMutexLock(), for example wolfcrypt/src/port/maxim/maxq10xx.c:683. A caller there waits until the mutex is released.

wc_FreeMutex() only unmaps (wolfcrypt/src/wc_port.c:3366-3374). The tested tree contains no shm_unlink() call, so an object under this name stays until it is removed by other means.

There is also a window between the two opens: if the object appears after the first open fails, the exclusive create fails and the call returns an error. The next attempt then takes outcome 1 or 2. How the same function behaves when its own initialization fails part way is covered in BYTERAY-2026-0355. The flag that guards the call is covered in BYTERAY-2026-0357.

Reachability and Preconditions

  • The build is a MAXQ10xx build with pthreads, as listed above.
  • The attacker can run code as a local user on the same host and create objects in the POSIX shared memory namespace. No privileges beyond an ordinary account are needed.
  • The object does not exist when the attacker acts. A host where a legitimate process creates the object at boot, before any untrusted user can run, is exposed only when the object has been removed.
  • A victim process with the privilege to bypass file permissions is not stopped by outcome 1 and takes outcome 2 instead.
  • wolfCrypt_Init() reaches the function at start-up of every process that uses the library, with or without the secure element attached. No network input or user interaction is involved.

Impact

Confirmed from source: a pre-existing object with that name is either unusable, in which case library initialization fails in every affected process, or is adopted as the hardware lock without validation. In the first case an application that checks wolfCrypt_Init() or wolfSSL_Init() cannot start its TLS or crypto functions. In the second, the party that created the object decides whether the lock can be taken; processes either run without the secure element or wait in a blocking lock call. Both conditions persist across application restarts because the object is not removed.

Plausible but not verified: the behaviour of the C library when the object's contents are not a valid mutex. POSIX leaves that undefined.

The effect is loss of availability of the hardware-backed operations, and of the library where initialization fails. Hardware-held keys are not exposed. Devices with no untrusted local users are not at risk from this issue.

ByteRay did not build a proof of concept for this issue. The analysis is from source review.

Remediation and Mitigation

Not fixed on wolfSSL master as of commit e4b0841b32e7 (2026-12-03). Master has changed the function. Commit b2c719310556e6f491f99e652388bad4de4c457b (PR 12067, merged 2026-11-16) opens the object with a single create-or-open call, which removes the window between two opens. It serializes initialization with a record lock, uses the object's size to tell an initialized mutex from an empty or half-initialized one, rejects any other size, and makes the mutex robust so that a holder that exits no longer blocks the others. The name is still fixed, the owner and mode of an existing object are still not checked, an object of the expected size is still used as it is, an object the process cannot open still makes initialization fail, and the object is still never removed. The change is not in a release as of 2026-12-03.

The fix direction is to stop trusting a name in a namespace that other users can write to: check the owner and mode of an existing object and fail closed on a mismatch, or place the object where only the intended users can create it.

Mitigations for deployed systems:

  • Do not give untrusted users local accounts on devices that use the secure element.
  • Create the object from a trusted start-up step, before any untrusted code can run, and monitor its owner and mode.
  • Check the return value of wolfCrypt_Init() and wolfSSL_Init(), and treat the "device is busy" log message from the port as an error condition.

Timeline

  • 2026-09-28 — Reported to wolfSSL.
  • 2026-11-09 — Pull request 12067 opened upstream.
  • 2026-11-16 — Pull request 12067, which reworks the shared mutex initialization, merged to master.
  • 2026-12-03 — Public disclosure.

Credits

Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.

References