Am I affected?

type your erlang.org/otp version to check

Description

Classic buffer overflow in the Erlang/OTP megaco flex scanner C driver allows a remote unauthenticated attacker to corrupt the driver's memory (and potentially achieve remote code execution or a denial-of-service crash) by sending a single text-encoded H.248/Megaco message containing an oversized property parm name.

When tokenizing a Local/Remote descriptor, mfs_load_property_groups extracts the attacker-controlled property name (bounded only by the message length) and, when no value follows, formats it into a fixed 512-byte error_msg field of the MfsErlDrvData struct using an unchecked sprintf call. Names longer than roughly 452 bytes overflow into the immediately following struct fields (text_buf, text_ptr, term_spec, term_spec_size, term_spec_index), overwriting live pointers and counters with attacker-chosen bytes. Subsequent scanner code writes and frees through the corrupted pointers, producing arbitrary write and arbitrary free primitives inside the BEAM VM process, which can be leveraged for remote code execution. On builds compiled with _FORTIFY_SOURCE the overflow is detected at runtime and terminates the process with SIGABRT, resulting in denial of service.

The overflow occurs in the flex scanner before any grammar or Megaco-level authentication processing, so exploitation requires only network reachability to the megaco transport port on a node configured with {scanner, flex}.

This vulnerability is associated with program files lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src and program routines mfs_load_property_groups.

This issue affects OTP from OTP 17.0 before OTP 27.3.4.15, from OTP 28.0 before OTP 28.5.0.4, and from OTP 29.0 before OTP 29.0.4, corresponding to megaco from 3.17.1 before 4.7.2.2, from 4.8 before 4.8.3.1, and from 4.9 before 4.9.1. Whether OTP before OTP 17.0, corresponding to megaco before 3.17.1, is affected is unknown.

Weaknesses & attack patterns

Weakness

CWE-120 · Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') in catalog → MITRE ↗
CWE-787 · Out-of-bounds Write in catalog → MITRE ↗

Attack patterns

CAPEC-100 · Overflow Buffers MITRE ↗

Affected — Erlang

< 17.0 status unknown
17.0 < 27.3.4.15 affected
maint-28 28.0 < 28.5.0.4 affected
maint-29 29.0 < 29.0.4 affected
every other version: unaffected
cpe cpe:2.3:a:erlang:erlang/otp:*:*:*:*:*:*:*:*
modules · source files · routines
modules megaco_flex_scanner · megaco_flex_scanner_drv
source files lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src
routines mfs_load_property_groups · megaco_flex_scanner:scan/2

Affected — Erlang / megaco Repository ↗

< 3.17.1 status unknown
3.17.1 < 4.7.2.2 affected
4.8 < 4.8.3.1 affected
4.9 < 4.9.1 affected
every other version: unaffected
cpe cpe:2.3:a:erlang:erlang/otp:*:*:*:*:*:*:*:*
modules · source files · routines
modules megaco_flex_scanner · megaco_flex_scanner_drv
source files src/flex/megaco_flex_scanner_drv.flex.src
routines mfs_load_property_groups · megaco_flex_scanner:scan/2

Affected — GitHub / erlang/otp Repository ↗

84adefa < 8704c8f affected
every other version: unaffected
cpe cpe:2.3:a:erlang:erlang/otp:*:*:*:*:*:*:*:*
modules · source files · routines
modules megaco_flex_scanner · megaco_flex_scanner_drv
source files lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src
routines mfs_load_property_groups · megaco_flex_scanner:scan/2

Workarounds

Switch the megaco text codec to the default Erlang-based scanner by removing {scanner, flex} from the encoder configuration. The Erlang scanner is not affected by this C-level memory corruption, at the cost of reduced parsing throughput.

Configurations

The megaco text codec must be configured to use the flex scanner via the encoder option {scanner, flex} (the documented high-performance configuration). Deployments using the default Erlang-based scanner are not affected.

References

Credits

Jonatan Männchen / EEF Finder
Jakub Witczak Remediation developer
Micael Karlberg Remediation reviewer

CVSS breakdown

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