Marlin Firmware M421 G-code Handler Out-of-Bounds Write — CVE-2026-56111
by Christ Bouchuen (github.com/Christbowel) · 2026-07-05
- Severity
- High
- CVE
- CVE-2026-56111
- Category
- hardware
- Affected product
- Marlin Firmware (3D printer firmware), builds compiled with MESH_BED_LEVELING
- Affected versions
- <= 2.1.2.7 (fixed in commit 1f255d1)
- Disclosed
- 2026-07-05
- Patch status
- patched
Tags
References
Archive entry
intelseclab/poc-archiveMetadata
| Field | Value |
|---|---|
| Date Added | 2026-07-05 |
| Last Updated | Unknown |
| Author / Researcher | Christ Bouchuen (github.com/Christbowel) |
| CVE / Advisory | CVE-2026-56111 |
| Category | hardware |
| Severity | High |
| CVSS Score | 8.3 |
| Status | PoC |
| Tags | marlin, 3d-printer, firmware, g-code, out-of-bounds-write, mesh-bed-leveling, denial-of-service, embedded |
| Related | N/A |
Affected Target
| Field | Value |
|---|---|
| Software / System | Marlin Firmware (3D printer firmware), builds compiled with MESH_BED_LEVELING |
| Versions Affected | <= 2.1.2.7 (fixed in commit 1f255d1) |
| Language / Platform | Embedded C/C++ firmware (AVR/ARM microcontrollers); PoC written in C |
| Authentication Required | No (G-code interfaces on serial/telnet typically have no authentication) |
| Network Access Required | No — reachable via USB serial connection or, for network-exposed printers, TCP/telnet G-code interface |
Summary
Marlin’s M421 G-code handler, used to set Mesh Bed Leveling (MBL) grid points, validates only that the supplied I/J grid indices are non-negative and never checks the upper bound against the actual mesh grid size. The underlying set_z() function then writes the supplied Z float value directly to z_values[ix][iy] with no bounds check, allowing an out-of-range index to write a controlled 32-bit float value to memory beyond the z_values array — into adjacent firmware state such as z_offset or the G-code parser object. The included PoC sends raw M421 commands over serial or TCP to demonstrate both a targeted, constrained write (e.g. corrupting the bed Z offset) and a reliable denial-of-service crash via a NaN value.
Vulnerability Details
Root Cause
The M421 MBL handler checks only that the I/J indices are non-negative (int8_t, so bounded to 0-127) but never validates them against the actual configured grid dimensions (e.g. a 3x3 grid). set_z() then performs an unchecked write z_values[ix][iy] = z, allowing writes up to roughly 2KB past the z_values array. The write’s value (the Z float) and offset (via the index) are attacker-controlled, but not an arbitrary absolute address — it is a constrained, not fully arbitrary, out-of-bounds write.
Attack Vector
- Attacker obtains a G-code channel to the target printer — a direct USB serial connection, or a network-exposed telnet/TCP G-code interface.
- Attacker sends an
M421command with grid indices exceeding the configured mesh dimensions (e.g.I3 J0on a 3x3 grid) and a chosen Z float value. - The firmware writes that value past the intended
z_valuesarray boundary into adjacent structures (e.g.z_offset, the parser object, orGcodeSuitestate), corrupting firmware behavior. - Alternatively, sending an out-of-range index with a NaN Z value propagates the NaN into motion-planning math, reliably crashing or hanging the firmware (denial of service).
Impact
Denial of service (firmware crash/hang) or corruption of firmware state such as the bed Z offset via a constrained out-of-bounds write, on any Marlin build with MESH_BED_LEVELING enabled. No demonstrated arbitrary code execution — the reachable memory window is limited to roughly 2KB past the target array.
Environment / Lab Setup
Target: 3D printer running Marlin Firmware <= 2.1.2.7 built with MESH_BED_LEVELING,
reachable via USB serial (e.g. /dev/ttyUSB0, /dev/ttyACM0) or network G-code/telnet (e.g. host:23)
Attacker: gcc (C99), Linux host with a serial or TCP connection to the target
Proof of Concept
PoC Script
See
exploit.cin this folder. Build withgcc -O2 -o exp exploit.c.
| |
The tool only sends the crafted M421 G-code line over the selected channel (serial or TCP); the out-of-bounds write itself happens inside the firmware. write mode lets the operator pick the index/value to corrupt a specific offset (e.g. the bed Z offset), while dos mode sends an out-of-range index with a NaN Z value that reliably crashes or hangs the printer’s motion firmware.
Detection & IOCs
Signs of compromise:
M421G-code commands observed withI/Jindex values outside the printer’s configured mesh grid bounds- Unexpected changes to the bed Z offset or erratic print quality with no corresponding user action
- Printer firmware crashes, hangs, or unexpected reboots correlating with received G-code traffic
Remediation
| Action | Detail |
|---|---|
| Primary fix | Update Marlin Firmware to a build including commit 1f255d1, which adds the missing upper-bound index checks to the M421 handler (matching the existing ABL/UBL handlers) |
| Interim mitigation | Restrict access to the printer’s G-code interface (physical USB access only, or firewall/isolate network-exposed telnet/TCP G-code ports); avoid exposing 3D printer control interfaces directly to untrusted networks |
References
Notes
Mirrored from https://github.com/Christbowel/CVE-2026-56111 on 2026-07-05.
| |