← ALL ADVISORIES

LOW BYTERAY-2026-0496Disclosed

wolfSSL — Out-of-Bounds Write in IoT-Safe AT Command TLV Builder

The IoT-Safe port builds AT commands in a 512-byte static buffer. The capacity check in iotsafe_cmd_add_tlv_ex does not count the TLV it is about to append, so a value of 243 to 253 bytes is hex-encoded up to about 22 bytes past the end of the buffer. Library call sites pass small fixed sizes; the overflow needs an oversized length from the embedding application.

Advisory
BYTERAY-2026-0496
CWE
CWE-787
CVSS
3.6 (CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/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 with the IoT-Safe port (WOLFSSL_IOTSAFE, --enable-iotsafe)
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

The IoT-Safe port composes the AT commands it sends to the SIM in one static buffer, csim_cmd, of 512 bytes. iotsafe_cmd_add_tlv_ex() appends a tag-length-value element to the command, writing the value as two hexadecimal characters per byte.

The function checks capacity before it writes, but the check compares two lengths taken from the command string that is already in the buffer. It does not include the element being appended. The only limit on the new value is the one-byte command length cap, which allows up to 253 bytes. A value of 243 bytes or more passes both checks, and its hexadecimal form is written past the end of the buffer by up to about 22 bytes.

No call site inside the library passes a value that large, so a TLS peer does not control any TLV length. The overflow is reached when the embedding application passes an oversized length to a public API of the port. Default builds do not compile the IoT-Safe port.

Affected Products and Versions

  • Component: wolfcrypt/src/port/iotsafe/iotsafe.c, iotsafe_cmd_add_tlv_ex().
  • Required build: the IoT-Safe port, WOLFSSL_IOTSAFE (--enable-iotsafe, disabled by default).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • A default ./configure build does not include this code.
  • Other releases were not checked.

Technical Details

The command buffer is csim_cmd[IOTSAFE_CMDSIZE_MAX] (wolfcrypt/src/port/iotsafe/iotsafe.c:77), with the size set to 512 in wolfssl/wolfcrypt/port/iotsafe/iotsafe.h:149. The capacity check is at wolfcrypt/src/port/iotsafe/iotsafe.c:318:

    if ((cmdlen + cur_csim_len + CSIM_CMD_ENDSTR_SIZE) > IOTSAFE_CMDSIZE_MAX) {
        return MEMORY_E;
    }

cmdlen is the length of the string already built. cur_csim_len is the decimal length field parsed back out of that same string (wolfcrypt/src/port/iotsafe/iotsafe.c:309-316). Neither term depends on len, the size of the value about to be appended.

What happens to a large value:

  1. A fresh command has cmdlen 23 and cur_csim_len 10. The check evaluates 23 + 10 + 4 = 37, far below 512, for any len.
  2. The remaining limit on len is the command length cap at wolfcrypt/src/port/iotsafe/iotsafe.c:329. With the initial length of 0 set by iotsafe_cmd_start() (wolfcrypt/src/port/iotsafe/iotsafe.c:267), it admits len up to 253 for a one-byte TLV length.
  3. The append at wolfcrypt/src/port/iotsafe/iotsafe.c:341-359 writes two characters for the tag, two or four for the length field, 2 * len hexadecimal characters and a terminating NUL, starting at the end of the existing string.
  4. For len 253 the write ends at offset 534 of the 512-byte buffer. The overflow begins at len 243.

The accumulated command length grows with each queued element, so the cap shrinks as the string grows. The end of the write stays near offsets 524 to 534 however many small elements come first. The maximum overflow is about 22 bytes into whatever static objects follow the buffer. A second defect is in iotsafe_cmd_complete() (wolfcrypt/src/port/iotsafe/iotsafe.c:385-391). When the terminator does not fit, it returns without appending it and without an error, so an oversized command can be sent in a malformed state.

Reachability and Preconditions

  • Build with the IoT-Safe port.
  • Internal call sites pass small fixed sizes: one-byte identifiers, algorithm ids of one or two bytes, digests of at most 64 bytes, and signatures normalised to 64 bytes. A remote TLS peer controls none of these lengths.
  • Two public entry points forward a caller-supplied length into a TLV. wc_iotsafe_ecc_sign_hash() and its _ex form pass the hash length (wolfcrypt/src/port/iotsafe/iotsafe.c:1684-1689, TLV appended at wolfcrypt/src/port/iotsafe/iotsafe.c:1023). wolfIoTSafe_GetCert_ex() passes its 16-bit id_sz (wolfcrypt/src/port/iotsafe/iotsafe.c:1758-1763).
  • The embedding application must pass a length of 243 to 253 bytes through one of those APIs. The in-tree example passes an id size of 1 (IDE/iotsafe/memory-tls.c:259).
  • A future call site that queues a larger value, such as an RSA modulus, into the same buffer would reach the same write.

Impact

A write of up to about 22 bytes past a static buffer, with hexadecimal characters derived from the value the application supplied. Adjacent static data can be corrupted, with effects on the integrity and availability of the device firmware. Under the port's trust model the oversized argument comes from the embedding application itself. This is a missing bound in the command builder, not a path an outside party can drive in the code as tested.

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 a capacity check that models the append: the current string length, plus the tag, the length field, 2 * len characters and the terminator, compared with IOTSAFE_CMDSIZE_MAX. Tracking a write cursor or remaining capacity in the builder state is more robust than re-parsing lengths from the buffer. iotsafe_cmd_complete() should return an error when the terminator does not fit. The public entry points should reject lengths the protocol cannot carry. Until then, applications should keep hash lengths and certificate id sizes passed to the IoT-Safe APIs within the sizes the port documents.

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