← ALL ADVISORIES

LOW BYTERAY-2026-0497Disclosed

wolfSSL — Out-of-Bounds Read in IoT-Safe Public Key Response Parsing

iotsafe_parse_public_key searches a modem response for nested TLV fields using fixed 69-byte and 67-byte windows instead of the bytes remaining in the response. A crafted response whose first field ends at the end of the 1024-byte static line buffer makes the nested searches read a few bytes past it.

Advisory
BYTERAY-2026-0497
CWE
CWE-125
CVSS
2.9 (CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:U/C:N/I:N/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

With the IoT-Safe port, operations such as ECC key generation and ECDH ask the SIM for a public key and parse the modem's text response in iotsafe_parse_public_key(). The parser finds one TLV field in the response, then searches for the next field starting four characters after the first match.

The follow-up searches are given fixed window sizes of 69 and 67 bytes. These are protocol constants, not the number of bytes left in the response. The first search can return a match at the very end of the response string, which sits in a 1024-byte static buffer. The nested searches then read past the end of the string into adjacent static memory.

The scan stops at the first byte that is not a hexadecimal character, and a later length check rejects any match found outside the response before key bytes are copied. The practical worst case is a crash in an unfavourable memory layout, not disclosure. The input comes from the SIM applet or modem, not from a network peer. Default builds do not compile the IoT-Safe port.

Affected Products and Versions

  • Component: wolfcrypt/src/port/iotsafe/iotsafe.c, iotsafe_parse_public_key() and its helper search_tlv().
  • 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 first search, at wolfcrypt/src/port/iotsafe/iotsafe.c:664, is bounded by the response length len. The two nested searches are at wolfcrypt/src/port/iotsafe/iotsafe.c:669-676:

    ktype = search_tlv(rkey + 4, IOTSAFE_TAG_ECC_KEY_FIELD_SZ,
            IOTSAFE_TAG_ECC_KEY_TYPE);
    ...
    payload_str = search_tlv(ktype + 4, IOTSAFE_TAG_ECC_KEY_TYPE_SZ,
            IOTSAFE_TAG_ECC_KEY_XY);

They pass IOTSAFE_TAG_ECC_KEY_FIELD_SZ (0x45) and IOTSAFE_TAG_ECC_KEY_TYPE_SZ (0x43) as the window. Neither is derived from the response length.

How the read leaves the response:

  1. The response is held in the static parser_line buffer of 1024 bytes (wolfcrypt/src/port/iotsafe/iotsafe.c:178), filled from modem reads with a truncating copy (wolfcrypt/src/port/iotsafe/iotsafe.c:190-199). A reply line of 1023 characters or more places the terminator at index 1023.
  2. search_tlv() loops while i <= size - 4 and returns &haystack[i] on a tag match (wolfcrypt/src/port/iotsafe/iotsafe.c:245-263). The first search can therefore return rkey up to four characters before the end of the response.
  3. The second search starts at rkey + 4 with a 69-byte window (wolfcrypt/src/port/iotsafe/iotsafe.c:669). The third starts at ktype + 4 with a 67-byte window (wolfcrypt/src/port/iotsafe/iotsafe.c:675). Both windows can extend beyond resp + len.
  4. search_tlv() decodes each TLV header with hex_to_bytes() (wolfcrypt/src/port/iotsafe/iotsafe.c:150-164), which fails at the first non-hexadecimal byte. A header at the last in-string offset with a small length byte steps the index past the terminator while still inside the window.

The entry check at wolfcrypt/src/port/iotsafe/iotsafe.c:660 and the guard at wolfcrypt/src/port/iotsafe/iotsafe.c:688 bound the final copies of the two coordinates (wolfcrypt/src/port/iotsafe/iotsafe.c:693-694). They do not constrain the two scans.

Reachability and Preconditions

  • Build with the IoT-Safe port, on a device that uses it for ECC keys.
  • The parser is reached from iotsafe_gen_keypair_locked() (wolfcrypt/src/port/iotsafe/iotsafe.c:725) and iotsafe_get_public_key_locked() (wolfcrypt/src/port/iotsafe/iotsafe.c:773), and through them from the key generation, public key import and shared secret callbacks.
  • The attacker controls the response of the SIM applet or modem. This is an adjacent component, not a remote network peer.
  • The response is about one kilobyte long, with its TLV chain ending at the buffer boundary.

Impact

A read of a few bytes past a static buffer. In practice the scan stops within the first two to five bytes of adjacent memory, at the first byte that is not a hexadecimal character. No data read out of bounds reaches the returned key. A tag match found beyond the response is rejected with BAD_STATE_E by the guard at wolfcrypt/src/port/iotsafe/iotsafe.c:688 before the copies. The remaining effect is the over-read itself, which can fault the process if the buffer ends at a page boundary followed by unmapped memory.

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 bound each nested search by the bytes that remain in the response: compute the offset of the previous match and pass len minus that offset minus the four header characters as the window. As a second measure, search_tlv() can stop at the terminator of the string and treat reaching it without a complete key as a parse failure. There is no configuration workaround other than building without the IoT-Safe port.

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