wolfSSL — Unvalidated DTLS Multicast Peer ID Index in ChangeCipherSpec Processing
In DTLS multicast builds, ChangeCipherSpec processing uses the peer ID byte from the record header as a direct index into the 100-entry per-peer sequence table. An enrolled ID of 100 to 255 makes the update write past the table, and an in-range ID updates the entry at that index, not the entry enrolled for the peer.
- Advisory
- BYTERAY-2026-0317
- CWE
- CWE-639
- CVSS
- 7.4 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:H/A:H)
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-27
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 (tested at master commit d95483f), DTLS 1.2 builds with WOLFSSL_MULTICAST (--enable-dtls --enable-mcast) and multicast enabled at run time
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
DTLS multicast in wolfSSL keeps per-peer receive state in a table inside the WOLFSSL object: epoch, sequence numbers and the replay window of each group member. The table has 100 entries. A member is enrolled with wolfSSL_mcast_peer_add(), which stores its peer ID in the first free entry. Record processing finds a member's entry by searching the table for the ID.
The ChangeCipherSpec handler does not search. It adds the peer ID from the record header to the table pointer and updates the entry it lands on. The ID is one byte taken from the datagram, and the enrolment function accepts IDs up to 255.
A ChangeCipherSpec record that carries an enrolled ID of 100 or more makes the handler read and write outside the table, up to about 5.6 KB past its end. With an ID below 100 the handler stays inside the table but updates the entry at position ID, which belongs to another member whenever enrolment order and ID order differ. Default builds do not include multicast and are not affected.
Affected Products and Versions
- Component:
src/internal.c,DoChangeCipherSpecTls12(). - Required build:
WOLFSSL_DTLSandWOLFSSL_MULTICAST(--enable-dtls --enable-mcast). Multicast is disabled by default (configure.ac:2930-2932). - Required configuration: multicast enabled on the context with
wolfSSL_CTX_mcast_set_member_id()(src/ssl_api_dtls.c:694). The out-of-bounds case also needs a peer enrolled with an ID from 100 to 255. The wrong-entry case needs only that some peer's table position differs from its ID. - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild does not include this code. - Other releases were not checked.
Technical Details
GetDtlsRecordHeader() stores the peer ID byte of each multicast record without a check (src/internal.c:13480):
ssl->keys.curPeerId = ssl->buffers.inputBuffer.buffer[*inOutIdx];
DoChangeCipherSpecTls12() uses it as an index (src/internal.c:25401-25409):
WOLFSSL_DTLS_PEERSEQ* peerSeq = ssl->keys.peerSeq;
#ifdef WOLFSSL_MULTICAST
if (ssl->options.haveMcast) {
peerSeq += ssl->keys.curPeerId;
peerSeq->highwaterMark = UpdateHighwaterMark(0,
ssl->ctx->mcastFirstSeq,
ssl->ctx->mcastSecondSeq,
ssl->ctx->mcastMaxSeq);
}
The lines that follow increment nextEpoch, copy the current sequence numbers to the previous ones, zero the current ones, copy window to prevWindow and clear window (src/internal.c:25411-25418). All of them act on the entry selected above.
The table is peerSeq[WOLFSSL_DTLS_PEERSEQ_SZ] in the key state (wolfssl/internal.h:3100), and the size is WOLFSSL_MULTICAST_PEERS, 100 by default (wolfssl/internal.h:1226-1228). The report gives the entry size as 36 bytes, so the table covers 3,600 bytes and an index of 255 lies 9,180 bytes from its start. The table is part of the heap-allocated WOLFSSL object.
- A datagram arrives on the multicast socket.
GetDtlsRecordHeader()copies its peer ID byte intocurPeerId. - The replay check
_DtlsCheckWindow()runs (src/internal.c:13561). It searches the table for an entry whosepeerIdequalscurPeerId(src/internal.c:21216-21219) and drops records from unknown IDs. It confirms that the ID is enrolled. It does not constrain the value. ProcessReply()dispatches achange_cipher_specrecord (src/internal.c:26386-26387), andDoProcessChangeCipherSpec()passes DTLS 1.2 records toDoChangeCipherSpecTls12()(src/internal.c:25465).- The handler indexes the table with the raw ID and updates that entry.
wolfSSL_mcast_peer_add() rejects an ID only when it is above 255 (src/ssl_api_dtls.c:877), so IDs 100 to 255 can be enrolled although the table has no such positions. _DtlsCheckWindow() and wolfSSL_DtlsUpdateWindow() (src/internal.c:21501-21504) both locate the entry by search. The ChangeCipherSpec handler is the only one of the three that indexes by value.
Reachability and Preconditions
- Build: DTLS with multicast. Not a default build.
- Runtime: a multicast session with peers enrolled through
wolfSSL_mcast_peer_add(). - Attacker position: a member of the multicast group, or any host able to send datagrams to the group address. The report states that a ChangeCipherSpec record is dispatched without an epoch or decryption gate, and that the group key does not authenticate which member sent a record.
- The ChangeCipherSpec is accepted only after the handshake message-order check passes. The report states that plaintext handshake messages sent to the group are enough to satisfy it.
- Out-of-bounds case: the operator has enrolled a peer ID from 100 to 255, and the attacker uses that ID in the record header.
- Wrong-entry case: any enrolment in which a peer's position in the table is not equal to its ID.
Impact
In the out-of-bounds case the handler writes several fields of a per-peer entry at an offset chosen through the peer ID, in 36-byte steps, up to about 5.6 KB past the table. That covers later fields of the WOLFSSL object and adjacent heap memory. The values written are counters, zeroes and copies of neighbouring bytes, not arbitrary attacker data. The result is corruption of connection state or a crash.
In the in-range case one group member, or an injecting host, resets the epoch, sequence numbers and replay window of another member's entry. According to the report this lets previously seen records from that member be accepted again, or causes that member's traffic to be dropped. No key material is disclosed.
ByteRay reproduced the out-of-bounds case on a multicast DTLS 1.2 client built with --enable-dtls --enable-mcast under AddressSanitizer. After unauthenticated handshake datagrams that satisfied the message-order check, a ChangeCipherSpec record with peer ID 255 in its header produced a heap-buffer-overflow write of 4 bytes in DoChangeCipherSpecTls12, at the highwaterMark assignment. A control run with benign input produced no report.
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 stop using the ID as an index. DoChangeCipherSpecTls12() should find the entry the way _DtlsCheckWindow() and wolfSSL_DtlsUpdateWindow() do, by searching ssl->keys.peerSeq[] for a matching peerId, and return SEQUENCE_ERROR when there is none. As a second layer, a curPeerId at or above WOLFSSL_DTLS_PEERSEQ_SZ should be rejected before any pointer arithmetic, and wolfSSL_mcast_peer_add() should refuse IDs at or above WOLFSSL_MULTICAST_PEERS.
Workaround for the out-of-bounds case: enrol only peer IDs below 100. This does not address the wrong-entry case. Enrolling each peer so that its table position equals its ID, which means adding IDs in ascending order from 0 with no gaps, avoids the mismatch, but ByteRay has not tested that as a complete mitigation.
Timeline
- 2026-09-27 — Reported to wolfSSL.
- 2026-12-03 — Public disclosure.
Credits
Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.