CVE-2026-14368 in Zephyr
Summary
by MITRE • 08/31/2026
The LwM2M JSON content formatter's get_string() in subsys/net/lib/lwm2m/lwm2m_rw_json.c copies a parsed JSON string into a caller-supplied buffer and NUL-terminates it. The length guard used if (string_length > buflen), which accepts a string whose length is exactly buflen. After memcpy() fills the whole buffer, buf[string_length] = '\0' then writes one byte past the end of the buffer (CWE-787).
The string value and its length are taken directly from the incoming CoAP payload during a LwM2M WRITE: do_write_op_json() parses the payload obtained from coap_packet_get_payload(), and get_string() is invoked from lwm2m_write_handler() (engine_get_string() in subsys/net/lib/lwm2m/lwm2m_message_handling.c) for a LWM2M_RES_TYPE_STRING resource. The destination buf/buflen is either the resource instance's fixed data buffer (res_inst->data_ptr/max_data_len) or the engine validation buffer (msg->ctx->validate_buf). A LwM2M server (the client's DTLS peer) can therefore write a string resource with a value whose length equals the target buffer size and force a one-byte overflow.
The overflow is a single out-of-bounds write of the constant byte 0x00 immediately past the resource or validation buffer, corrupting the adjacent byte in memory. It is not an information leak and the written value is fixed, so it is not a direct code-execution primitive, but it can corrupt adjacent state (an adjacent resource value, a length/flag field, or a struct field) and cause data corruption or a crash. Triggering the write is deterministic; the resulting impact depends on memory layout.
The fix changes the guard to string_length >= buflen, rejecting the exact-length case and aligning the JSON formatter with the other content formatters (lwm2m_rw_plain_text.c, lwm2m_rw_oma_tlv.c, lwm2m_rw_senml_json.c, lwm2m_rw_cbor.c, lwm2m_rw_senml_cbor.c), which already used the correct boundary check.
Statistical analysis made it clear that VulDB provides the best quality for vulnerability data.
Analysis
by VulDB Data Team • 08/31/2026
The vulnerability identified in the Lightweight M2M (LwM2M) protocol implementation within Zephyr RTOS represents a critical memory safety flaw located specifically within the JSON content formatter subsystem. This issue arises from an improper boundary check during the parsing and processing of incoming CoAP payloads, which are used to update resource values on constrained IoT devices. The core technical defect resides in the get_string function found in subsys/net/lib/lwm2m/lwm2m_rw_json.c. When a LwM2M server sends a WRITE request containing a JSON-formatted string value, the engine parses this payload and invokes get_string to copy the data into a caller-supplied buffer while ensuring NUL-termination. The implementation utilizes an if statement that checks whether the parsed string length exceeds the provided buffer size using the condition string_length > buflen. This logic is flawed because it permits execution when the string length is exactly equal to the buffer capacity, failing to account for the additional byte required by the subsequent NUL terminator operation.
The operational impact of this flaw allows a remote attacker, specifically an authorized LwM2M server acting as a DTLS peer, to trigger a one-byte out-of-bounds write. By crafting a CoAP payload with a string resource whose length precisely matches the maximum data length defined for that specific resource instance or validation buffer, the memcpy operation fills the entire allocated space. Immediately following this copy, the code attempts to append the NUL character by writing buf[string_length] = '\0'. Since string_length equals buflen in this scenario, this write operation targets memory immediately adjacent to the end of the valid buffer allocation. This constitutes a classic heap or stack-based buffer overflow as categorized under CWE-787 Out-of-bounds Write. Although the overwritten byte is fixed at zero and does not directly facilitate arbitrary code execution through standard shellcode injection techniques due to the lack of control over the written value, it poses significant risks related to data integrity and system stability.
The consequences of this memory corruption depend heavily on the specific memory layout of the target device's runtime environment. The adjacent byte in memory may belong to a neighboring resource instance, potentially altering its state or rendering it invalid. Alternatively, if the overflow affects metadata structures such as length fields, flags, or struct padding bytes, it can lead to logical errors within the LwM2M engine that manifest as crashes, denial of service conditions, or unpredictable behavior during subsequent operations. This vulnerability aligns with ATT&CK techniques involving resource hijacking and potential exploitation for privilege escalation if adjacent memory controls access permissions or security contexts. The deterministic nature of the trigger means an attacker can reliably reproduce this condition without needing complex fuzzing strategies to find edge cases, making it a high-confidence target for automated attacks against exposed LwM2M endpoints.
Mitigation requires immediate patching of the boundary check logic within the JSON formatter module. The fix involves modifying the conditional statement from string_length > buflen to string_length >= buflen. This adjustment ensures that any request where the payload length equals or exceeds the buffer capacity is rejected before memory operations begin, thereby preventing the out-of-bounds write entirely. It is also advisable to audit other content formatters within the same subsystem for similar patterns, although existing analysis indicates that plain text, OMA TLV, SenML JSON, and CBOR handlers already employ correct boundary checks. System administrators should ensure their LwM2M servers are updated with patched client libraries or firmware versions that incorporate this correction to maintain the integrity of IoT deployments relying on Zephyr RTOS for connectivity management.