Out-of-bounds Write vulnerability in the external term format decoder in Erlang OTP erts allows an attacker who controls the input to binary_to_term/1,2 to abort the Erlang VM via a NEWER_REFERENCE_EXT term with a zero-length ID. decoded_size in erts/emulator/beam/external.c accepts a reference whose 16-bit Len field is zero, but dec_term always reads one ID word. dec_term then runs 4 bytes ahead of the position that decoded_size validated. It decodes the bytes that follow as terms that were never sized, and writes past the reserved process heap.
The abort takes down every process on the node. Supervision, try/catch and the safe option do not prevent it. enif_binary_to_term() and the distribution protocol reach the same decoder, and distribution is assumed to run on trusted networks only. NEW_REFERENCE_EXT also accepts a zero length, but its range check on the first ID word rejects the shifted input. On 32-bit builds, a zero-length reference of either type at the end of the input, followed by trailing bytes, can write one word past the reserved heap.
This issue affects OTP from OTP 17.0 before OTP 27.3.4.20, OTP 28.5.0.9, and OTP 29.1.3, corresponding to erts from 6.0 before 15.2.7.15, 16.4.0.8, and 17.1.2. Whether OTP before OTP 17.0, corresponding to erts before 6.0, is affected is unknown.
1. Size pass. binary_to_term_int first calls decoded_size to reserve the process heap. For NEWER_REFERENCE_EXT, decoded_size rejects an ID-word count above ERTS_MAX_REF_NUMBERS but not a count of zero. With Len 0 it skips the tag, the length, the node atom and the 4-byte creation, and no ID bytes.
2. Decode pass. dec_term reads Len, the node atom and the creation, then reads the first ID word r0 without checking Len. From here dec_term is 4 bytes ahead of the position decoded_size validated.
3. Heap overrun. In the reported input, the reference is followed by a BINARY_EXT. decoded_size treats the binary payload as opaque bytes. The shifted dec_term consumes the binary tag and the top three length bytes as r0, reads the low length byte (105, LARGE_TUPLE_EXT) as the next tag, and builds a tuple from the payload. The tuple-build loop stores past the heap that was reserved for a reference and a binary.
4. Abort. After dec_term returns, binary_to_term_int compares the heap pointer with the reserved end and calls erts_exit with heap overrun. That check runs after the out-of-bounds stores. Larger inputs can fault with SIGSEGV first.
NEW_REFERENCE_EXT. Tag 114 also accepts Len 0, but dec_term rejects r0 >= MAX_REFERENCE for that tag. A shifted r0 begins with a term tag byte, so the input fails with badarg.
NEWER_REFERENCE_EXT (tag 90) with Len 0, the node atom nonode@nohost as SMALL_ATOM_UTF8_EXT, and a 4-byte creation for another node, for example 1.BINARY_EXT (tag 109) whose payload starts with a 32-bit arity N, followed by N SMALL_INTEGER_EXT elements. Pad the payload so that the low byte of the 32-bit binary length is 105 (LARGE_TUPLE_EXT).SMALL_TUPLE_EXT after the version byte 131. With N = 40 the input is 391 bytes.binary_to_term/1, or binary_to_term/2 with [safe], on the input. The VM aborts with heap overrun by 33 words(s) instead of raising badarg.An attacker who can supply bytes to binary_to_term/1,2 or enif_binary_to_term() can abort the Erlang VM and stop every application on the node.
binary_to_term/1,2 on data from untrusted sources. The OTP Secure Coding Guidelines (DSG-011) recommend avoiding these functions altogether on untrusted data.[safe] option to binary_to_term/2 does NOT protect against this crash. It only restricts atom creation, not structural validation of binary encodings.{
"capec_ids": [
"CAPEC-100"
],
"cpe_ids": [
"cpe:2.3:a:erlang:erlang\\/otp:*:*:*:*:*:*:*:*"
],
"cwe_ids": [
"CWE-1284",
"CWE-787",
"CWE-125"
]
}