Am I affected?

type your erts version to check

Description

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.

Technical analysis

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.

Proof of concept

  1. Build a 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.
  2. Build a 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).
  3. Wrap both in a two-element SMALL_TUPLE_EXT after the version byte 131. With N = 40 the input is 391 bytes.
  4. Call 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.

Weaknesses & attack patterns

Weakness

CWE-1284 · Improper Validation of Specified Quantity in Input in catalog → MITRE ↗
CWE-787 · Out-of-bounds Write in catalog → MITRE ↗
CWE-125 · Out-of-bounds Read in catalog → MITRE ↗

Attack patterns

CAPEC-100 · Overflow Buffers MITRE ↗

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.

Affected — Erlang / erts Repository ↗

≥ 6.0 and up affected
→ 15.2.7.15 not affected
→ 16.4.0.8 not affected
→ 17.1.2 not affected
every other version: unknown
cpe cpe:2.3:a:erlang:erlang/otp:*:*:*:*:*:*:*:*
version type otp

Affected — Erlang

≥ 17.0 and up affected
→ 27.3.4.20 not affected
→ 28.5.0.9 not affected
→ 29.1.3 not affected
every other version: unknown
cpe cpe:2.3:a:erlang:erlang/otp:*:*:*:*:*:*:*:*
version type otp

Affected — GitHub / erlang/otp Repository ↗

≥ 84adefa < e5a9d3d affected
≥ e5a9d3d and up not affected
every other version: unknown
cpe cpe:2.3:a:erlang:erlang/otp:*:*:*:*:*:*:*:*
version type git

Workarounds

  • Do not call 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.
  • If distribution is exposed to untrusted networks, configure it to use TLS with client certificate verification.
  • Use alternative serialization formats (JSON, Protocol Buffers) for untrusted external input. Note: the [safe] option to binary_to_term/2 does NOT protect against this crash. It only restricts atom creation, not structural validation of binary encodings.

References

Credits

Sungho Park Finder Reporter
Ingela Anderton Andin Coordinator
Jonatan Männchen / EEF Coordinator
Sverker Eriksson Remediation developer

CVSS breakdown

CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:N/VC:L/VI:N/VA:H/SC:N/SI:N/SA:N

Exploitability

Attack Vector
Local
Attack Complexity
Low
Attack Requirements
None
Privileges Required
None
User Interaction
None

Vulnerable System

Confidentiality
Low
Integrity
None
Availability
High

Subsequent Systems

Confidentiality
None
Integrity
None
Availability
None
« All CVEs