Skip to content

Use-after-free race in SNTP async client when closing the socket while the socket service is still polling it

Moderate
d3zd3z published GHSA-34wr-cg29-c4mw Jun 30, 2026

Software

zephyr

Affected versions

>= 4.2.0, <= 4.4.0

Patched versions

4.5.0

Description

The asynchronous SNTP client in Zephyr (subsys/net/lib/sntp/sntp.c, sntp_close_async) closed the UDP socket file descriptor directly from the calling thread immediately after detaching it from the network socket service, without synchronizing with the socket-service poll thread.

The socket service thread polls each socket via zvfs_poll, which (in zsock_poll_prepare_ctx) registers a k_poll_event pointing into the socket's net_context (&ctx->recv_q) and then blocks in k_poll without holding a reference or lock. net_context objects are allocated from a fixed pool (contexts[CONFIG_NET_MAX_CONTEXTS]) and reused after close.

When sntp_close_async is invoked from a different thread than the poll thread (in the in-tree consumer subsys/net/lib/config/init_clock_sntp.c, the SNTP timeout handler runs on the system workqueue while the socket service thread is blocked in poll on the same fd), the close frees and may reuse the net_context while the poll thread still has a poller node linked into the freed object, resulting in a use-after-free / object confusion of kernel poll structures.

The SNTP timeout path is the normal no-response failure mode, so a network peer or off-path attacker who drops or delays the SNTP/NTP response can drive the racing close repeatedly (and periodically with NET_CONFIG_SNTP_INIT_RESYNC). The most likely consequence is a crash of the networking thread (denial of service), with potential memory corruption when the freed context slot is reallocated.

The fix defers the close to the socket service thread itself via net_socket_service_close (NET_SOCKET_SERVICE_CLOSE_SOCKETS), so the same thread that polls performs the close, eliminating the race. Affected releases: v4.2.0 through v4.4.0.

Affected components

  • subsys/net/lib/sntp
  • subsys/net/lib/config
  • subsys/net/lib/sockets

Affected versions

v4.2.0, v4.2.1, v4.2.2, v4.3.0, v4.4.0 (async SNTP API present since v4.2.0)

Fix

Fixed (merged) in ef47bdf

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: 7ab8e27 (net: lib: sntp: async query API, 2025-03-07)

Evidence

  • subsys/net/lib/sntp/sntp.c:344-348 — post-fix sntp_close_async defers close via net_socket_service_close; git show v4.4.0:... shows pre-fix caller-thread zsock_close(ctx->sock.fd)
  • subsys/net/lib/sockets/sockets_service.c:241-259 — poll thread snapshots fds under lock then zsock_poll()s without the lock; close now happens in-thread at restart: (lines 245-251)
  • lib/os/zvfs/zvfs_poll.c:48-109 — POLL_PREPARE then k_poll() blocks referencing per-fd objects without holding a refcount during the wait
  • subsys/net/lib/sockets/sockets_inet.c:1660-1674 — zsock_poll_prepare_ctx sets (*pev)->obj = &ctx->recv_q, a pointer into the net_context that a concurrent close frees
  • subsys/net/ip/net_context.c:80 — net_context objects live in a fixed reusable array contexts[NET_MAX_CONTEXT], so a freed context can be reallocated under the dangling poll registration
  • subsys/net/lib/config/init_clock_sntp.c:139-166 — sntp_async_timeout runs on the system workqueue and calls sntp_close_async, racing the socket service thread's poll; timeout is the normal no-response path an attacker can force
  • include/zephyr/net/socket_service.h:179-196 — net_socket_service_unregister (old) vs net_socket_service_close (new) showing the deferred-close mechanism
  • git tag --contains 7ab8e27 — vulnerable code present in v4.2.0/v4.3.0/v4.4.0; fix dated 2026-05-01 after v4.4.0

Patches

Branch Pull request Status
main #108180 merged
v4.4-branch #110860 merged
v4.3-branch #110858 merged

For more information

If you have any questions or comments about this advisory:

embargo: 2026-06-30

Severity

Moderate

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
Network
Attack complexity
High
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
None
Integrity
Low
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:N/AC:H/PR:N/UI:N/S:U/C:N/I:L/A:H

CVE ID

CVE-2026-10655

Weaknesses

Use After Free

The product reuses or references memory after it has been freed. At some point afterward, the memory may be allocated again and saved in another pointer, while the original pointer references a location somewhere within the new allocation. Any operations using the original pointer are no longer valid because the memory belongs to the code that operates on the new pointer. Learn more on MITRE.