Skip to content

Out-of-bounds heap write in Zephyr recvmsg() ancillary-data path (insert_pktinfo undersizes the control-buffer capacity check)

High
d3zd3z published GHSA-pvf7-7mrp-35w7 Jun 27, 2026

Software

zephyr

Affected versions

>= 3.6.0, <= 4.4.0

Patched versions

4.5.0

Description

Zephyr's IP socket recvmsg() implementation (subsys/net/lib/sockets/sockets_inet.c, insert_pktinfo()) validated the user-supplied ancillary (msg_control) buffer using only the payload length (msg->msg_controllen < pktinfo_len) before writing a full control message consisting of an aligned cmsg header plus the payload. Because the check omitted the cmsg header size, a control buffer whose length falls in the under-checked window (e.g. 16-27 bytes for IPv4 IP_PKTINFO on a 64-bit target, where a single element actually occupies 28 bytes) passes the guard yet causes a fixed-size out-of-bounds write of up to one cmsg header (~12 bytes) past the end of the buffer.

Under CONFIG_USERSPACE the recvmsg verifier allocates a kernel-heap copy of the control buffer sized to msg_controllen and runs the implementation against it, so the overflow corrupts kernel heap memory and is triggerable from an unprivileged userspace thread; in supervisor mode it corrupts the caller's buffer.

The path is reachable on a UDP/IP socket with IP_PKTINFO/IPV6_RECVPKTINFO (or hoplimit/timestamping) enabled when the application calls recvmsg() with an undersized control buffer and a datagram is received; part of the overwritten bytes (the destination IP in ipi_addr) is influenced by the received packet.

The fix makes the capacity check use NET_CMSG_SPACE(pktinfo_len) (aligned header + aligned data) and returns -ENOMEM when the buffer is too small. Affected: v3.6.0 through v4.4.0.

Affected components

  • subsys/net/lib/sockets

Affected versions

v3.6.0 through v4.4.0 (present in latest release; CONFIG_NET_CONTEXT_RECV_PKTINFO / RECV_HOPLIMIT / NET_CONTEXT_TIMESTAMPING with the matching socket option enabled)

Fix

Fixed (silently, merged) in 01fe77b

Projected fixed version: 4.5.0 (the fix is merged on main but not yet released; this forecast should be confirmed against the actual release).

Introduced by: 5488e76 net: socket: Add support for filling receive pktinfo data (2023-11-27; later relocated by 404e9c7)

Evidence

  • subsys/net/lib/sockets/sockets_inet.c:1019-1023 (post-fix) — capacity check now NET_CMSG_SPACE(pktinfo_len); parent rev only checked msg_controllen < pktinfo_len, omitting the cmsg header
  • subsys/net/lib/sockets/sockets_inet.c:1035-1039 — writes NET_CMSG_LEN header then memcpy of pktinfo_len into NET_CMSG_DATA, spanning aligned-header + payload (28 bytes for IPv4 PKTINFO)
  • include/zephyr/net/net_ip.h:332-368 — NET_CMSG_FIRSTHDR requires msg_controllen >= sizeof(net_cmsghdr) (16); NET_CMSG_SPACE = aligned header + aligned data; NET_CMSG_LEN = aligned header + data — establishes the [16,27] overflow window
  • subsys/net/lib/sockets/sockets.c:626-639,654-660 — z_vrfy_zsock_recvmsg allocates kernel-heap msg_control via k_usermode_alloc_from_copy(.., msg_controllen) and runs the impl on it, so the OOB write hits kernel heap; copy-back is bounded by msg_controllen (no copy-back overflow)
  • subsys/net/lib/sockets/sockets_inet.c:1308-1338 — recv_dgram only checks msg_control!=NULL and msg_controllen>0 before insert_pktinfo; no outer full-space guard; add_pktinfo gated on net_context_is_recv_pktinfo_set
  • git tag --contains 5488e76 and git show v4.4.0:...sockets_inet.c — vulnerable check shipped in v3.6.0..v4.4.0, still present in latest release (reportable)

Patches

Fix 1 — #106464

Branch Pull request Status
main #106464 merged
v4.4-branch #110668 merged
v4.3-branch #110669 merged
v3.7-branch not affected

Fix 2 — #110780

Branch Pull request Status
main #110780 merged
v4.4-branch #112207 merged
v4.3-branch #112209 merged
v3.7-branch #112208 merged

For more information

If you have any questions or comments about this advisory:

embargo: 2026-06-19

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Local
Attack complexity
Low
Privileges required
Low
User interaction
None
Scope
Changed
Confidentiality
Low
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:L/I:H/A:H

CVE ID

CVE-2026-10643

Weaknesses

Out-of-bounds Write

The product writes data past the end, or before the beginning, of the intended buffer. Learn more on MITRE.