CVE-2026-95821: zephyr Privilege Escalation

CVE-2026-95821

NVD

Vulnerability Summary

The SOCKS5 client in `subsys/net/lib/socks/socks.c` passes the addresses of two of `socks5_tcp_connect()`'s own stack variables, `method_rsp` and `cmd_rsp`, to `net_context_recv()` as the user data for the negotiation and CONNECT response callbacks. For a TCP context `net_context_recv()` reaches `net_tcp_recv()`, which only stores `context->recv_cb` and `conn->recv_user_data` and never removes them. On the success path `zsock_connect_ctx()` immediately replaces them with `zsock_received_cb()`, but on every error path nothing did, so the network context was left holding a pointer into a stack frame that had already been destroyed. Any remote peer acting as the proxy can arm this with a protocol-legal response: answering the method negotiation with NO ACCEPTABLE METHODS (`0xFF`), sending a bad version byte, returning a non-success `REP` in the CONNECT reply, or simply stalling until `CONFIG_NET_SOCKETS_CONNECT_TIMEOUT` expires all make `socks5_tcp_connect()` return an error while the callbacks stay installed. The dangling pointer is then dereferenced asynchronously from the networking threads: `tcp_conn_close()` in `subsys/net/ip/tcp.c` invokes `context->recv_cb()` on FIN, RST or timeout, and the callback `memset()`s through the stale pointer, while any further data on the socket reaches `net_context_packet_received()` and makes `net_pkt_read()` write peer-supplied bytes there. The result is a write of two to four bytes (zeroes on the teardown path, peer-chosen bytes on the data path) into a stack region of the thread that called `connect()`, at a moment when that thread may have reused the memory for a live frame. The write address is not attacker-controlled, so the practical impact is limited corruption or a crash rather than a directed memory-write primitive; the author observed it as a SEGV in `tcp_conn_close()` under `CONFIG_ASAN`. Only configurations with `CONFIG_SOCKS` enabled and a SOCKS5 proxy configured on the socket are affected. The fix routes the error returns through a common exit that calls `net_context_recv(ctx, NULL, K_NO_WAIT, NULL)`, uninstalling the callback and the user-data pointer before the stack frame goes away. Affected components - `subsys/net/lib/socks` Affected versions `>= 2.0.0, < 4.3.2; >= 4.4.0, < 4.5.0` Fix Fixed in 4.3.2, 4.5.0. Release lines that have not yet taken the backport remain affected — see the affected version range above. Introduced by: 39ed77e4387eb00ce3b799d2e24d46cb1af222f1 ("net: socks: Make SOCKS5 implementation transparent", Aug 2019, first released in v2.0.0), which moved the handshake from blocking socket recv() calls onto net_context_recv() callbacks with stack-local user data. The original ead249f2f951 implementation in v1.14.x is not affected Evidence - subsys/net/lib/socks/socks.c:69-193 — socks5_tcp_connect() declares method_rsp/cmd_rsp on its stack and passes their addresses to net_context_recv(); pre-fix every post-recv failure was a bare `return` - subsys/net/lib/socks/socks.c:29-32,53-57 — the callbacks memset() through the user_data pointer when pkt is NULL or status is non-zero, and net_pkt_read() into it otherwise - subsys/net/ip/tcp.c:4330-4344 — net_tcp_recv() only stores context->recv_cb and conn->recv_user_data; nothing removes them (passing NULL clears them, which is what the fix relies on) - subsys/net/ip/tcp.c:1005-1008 — tcp_conn_close() calls conn->context->recv_cb(..., conn->recv_user_data), the dereference of the dead stack pointer on FIN/RST/timeout - subsys/net/ip/tcp.c:2060,2072,2080,2097 — timeout paths that reach tcp_conn_close() asynchronously from the TCP work queue - subsys/net/ip/net_context.c:3947-3962 — net_context_packet_received() calls context->recv_cb with a packet, giving the peer a 2-4 byte write of chosen data into the dead frame - subsys/net/ip/net_context.c:763-769 — net_context_put() clears recv_cb before net_tcp_put(), so the application's own close() is safe; the damaging calls come from the network threads - subsys/net/lib/sockets/sockets_inet.c:405-423 — zsock_connect_ctx() re-installs zsock_received_cb() only on the success path; the error path returns -1 with the SOCKS callbacks still installed - subsys/net/lib/sockets/sockets_inet.c:293,339,1527 — SOCK_EOF is only set from the recv path, so the `if (!sock_is_eof(ctx))` guard cannot skip the success-path re-installation during the handshake - subsys/net/ip/Kconfig:584 — CONFIG_NET_CONTEXT_SYNC_RECV defaults to y, so the SOCKS handshake really does block and complete before the error return - subsys/net/lib/socks/socks.c:190-199 — post-fix `error:` label calls net_context_recv(ctx, NULL, K_NO_WAIT, NULL), clearing both the callback and the user data <!-- zepsec:original --> <details> <summary>Original report as submitted by the reporter</summary> Summary In Zephyr's native TCP SOCKS5 path, `socks5_tcp_connect()` registers a receive callback whose user data points to a stack-local response object. A finite synchronous receive timeout returns without cancelling that registration. If the socket descriptor remains open, a delayed response from the configured SOCKS5 proxy can invoke the callback after the function returns and write peer-chosen bytes into expired stack storage. The full v4.4.2 BSD-socket, SOCKS5, `net_context`, TCP, and Zephyr loopback path reproduced the two-byte method-response write in two of two runs. The analogous four-byte command-response write is established by the same source pattern but was not dynamically reproduced. The demonstrated issue is a stack-lifetime violation with plausible integrity and availability consequences; code execution, privilege escalation, a selected victim object, and a non-instrumented target crash were not demonstrated. Affected component and versions - Component: Zephyr core SOCKS5 negotiation in `subsys/net/lib/socks/socks.c`, together with the synchronous native-TCP receive registration and dispatch paths in `subsys/net/ip/net_context.c` and `subsys/net/ip/tcp.c`. - Introduced by commit `39ed77e4387eb00ce3b799d2e24d46cb1af222f1` (`net: socks: Make SOCKS5 implementation transparent`), whose parent `c8fa169294995fbac3d4abc5dee7908a1e867196` used blocking socket receives and closed the internally owned descriptor on failure. - First affected final release: Zephyr `v2.0.0`. - Structured affected range: `>= 2.0.0`. - Dynamically tested release: Zephyr `v4.4.2`, tag object `671f64aa79924606253238f801c494c84b02c2a0`, commit `dccb09599635bdff17633fa7e9dab014b91dce90`, tree `d85796cbdd37828b2e7e75ae4e66c817eee4e1da`, on `native_sim/native/64` with Clang 18.1.3 and AddressSanitizer. - Release comparison: the callback-to-stack-local pattern and synchronous timeout without cancellation are present in every checked numeric release tag from `v2.0.0` through `v4.4.2`; the same pattern is absent from the final `v1.14.0` through `v1.14.3` releases. - Current development: `main` at `f80761e49401497b5ee64ee9732dc2791055ec52` still contains the lifetime defect. No patched release or current-development fix was found as of 2026-08-30. Current `main` separately initializes `proxy_len`; that change does not cancel a timed-out receive or extend the response objects' lifetime. Required configuration and attacker preconditions - `CONFIG_SOCKS=y`, Zephyr's BSD socket layer, native TCP, `CONFIG_NET_CONTEXT_SYNC_RECV=y`, and a finite `CONFIG_NET_SOCKETS_CONNECT_TIMEOUT` are used. In v4.4.2, synchronous `net_context_recv()` support defaults to enabled and the socket connect timeout defaults to 3,000 ms; the test shortens the timeout to 200 ms. - The application configures a SOCKS5 proxy with `SO_SOCKS5` and calls `connect()` through that proxy. - The configured proxy is malicious or compromised, or an active on-path actor can delay and inject a valid response into the established TCP stream. The configured-proxy case was exercised; the on-path case was not and additionally requires valid TCP-stream injection, including sequence validation. - The response arrives after the finite SOCKS5 receive wait has timed out, and the caller-owned socket descriptor remains open with no intervening receive registration that replaces the stale callback. No sanitizer finding occurred in the tested close-before-response control; by source inspection the descriptor-close path clears the receive registration. Prompt close substantially narrows the demonstrated window, but it is not a synchronized library fix for an already in-flight callback. Root cause `socks5_tcp_connect()` declares both response objects on its stack and registers their addresses as persistent callback user data. The following is condensed from `subsys/net/lib/socks/socks.c`, with declarations at lines 78 and 80 and registrations at lines 102–104 and 163–165: ```c struct socks5_method_response method_rsp; struct socks5_command_response cmd_rsp; ret = net_context_recv(ctx, socks5_method_rsp_cb, K_MSEC(CONFIG_NET_SOCKETS_CONNECT_TIMEOUT), &method_rsp); ... ret = net_context_recv(ctx, socks5_cmd_rsp_cb, K_MSEC(CONFIG_NET_SOCKETS_CONNECT_TIMEOUT), &cmd_rsp); ``` The native TCP path stores the callback and its user-data pointer before the synchronous wait. If `k_sem_take(&context->recv_data_wait, timeout)` expires, `net_context_recv()` returns `-ETIMEDOUT` without unregistering them. The BSD SOCKS connect path then returns `ETIMEDOUT` without closing the caller-owned descriptor. Later TCP input reaches `net_context_packet_received()`, which invokes the retained callback after `socks5_tcp_connect()` has returned. The method callback copies two bytes into `method_rsp`. The command callback copies the four-byte common response header into `cmd_rsp`. This also contradicts the documented behavior in `include/zephyr/net/net_context.h:1340`: “The callback is not called if the timeout expires.” There is a related ordering concern on successful or boundary-time delivery: `net_context_packet_received()` gives the synchronous wait semaphore before invoking the callback. On a suitable SMP or preemptive configuration, the waiting thread may resume before the callback finishes. The primary delayed-response reproduction does not depend on that race because the response is released only after `connect()` has returned. Minimal reproduction The prepared source-only `ZEPHYR-2026-005-reproducer` ztest application uses Zephyr's public BSD socket API and in-process `127.0.0.1` loopback. It starts a synthetic SOCKS5 proxy thread and executes three controls before the positive case. It does not contact a host listener, public service, or external target. Build against the exact `v4.4.2` source in a Zephyr development environment with Clang and AddressSanitizer support: ```sh export ZEPHYR_BASE=/path/to/zephyr-v4.4.2 cmake -S ZEPHYR-2026-005-reproducer \ -B ZEPHYR-2026-005-reproducer/build \ -G "Unix Makefiles" \ -DBOARD=native_sim/native/64 \ -DZEPHYR_TOOLCHAIN_VARIANT=host/llvm \ -DBUILD_VERSION=dccb09599635bdff17633fa7e9dab014b91dce90 cmake --build ZEPHYR-2026-005-reproducer/build --parallel 1 ``` Zephyr v4.4.2 documents `host/llvm` as the host-Clang toolchain variant, and the confirmed build used this exact value. Set `LLVM_TOOLCHAIN_PATH` if Clang is not discoverable through the environment. Run in a network namespace when available: ```sh sudo -n unshare -n -- env \ ASAN_OPTIONS=detect_stack_use_after_return=1:halt_on_error=1:abort_on_error=1:disable_coredump=1:symbolize=1 \ ./ZEPHYR-2026-005-reproducer/build/zephyr/zephyr.exe ``` The namespace is defense in depth rather than a harness dependency. Without an available network namespace, run the same binary directly with the same `ASAN_OPTIONS`; no host socket is used by this configuration. The test sequence is: 1. Complete a timely SOCKS5 method and CONNECT handshake; expect success and no sanitizer finding. 2. Let the method wait time out, keep the descriptor open briefly, send no response, and then close; expect `ETIMEDOUT` and no sanitizer finding. 3. Let the method wait time out, close the descriptor, and then attempt the delayed response; expect no sanitizer finding. The proxy-side send status is printed for information only and may report either success or an error; the control's pass criterion is the absence of a sanitizer finding. 4. Let the method wait time out while keeping the descriptor open, confirm that `connect()` returned `ETIMEDOUT`, and then send method response bytes `05 00`; expect AddressSanitizer to abort on a two-byte stack-use-after-return write through `socks5_method_rsp_cb()`. Observed result and controls Both fresh positive executions terminated with status 134 and the same symbolized AddressSanitizer `stack-use-after-return` diagnostic. `net_pkt_read()` performed a write of size two through unmodified `socks5_method_rsp_cb()` at `subsys/net/lib/socks/socks.c:34`; AddressSanitizer identified `method_rsp` at line 78 in the already returned `socks5_tcp_connect()` frame. The timely-handshake, no-response, and close-before-response controls all passed before the positive case. A run counts as a reproduction only when this sanitizer diagnostic accompanies status 134; reaching the harness's final `zassert_unreachable()` means the discriminator did not fire. The test links the unmodified v4.4.2 BSD socket, SOCKS5, `net_context`, TCP, packet, and loopback source. The test configuration includes `CONFIG_NO_OPTIMIZATIONS=y`, `CONFIG_ASAN=y`, `CONFIG_ASAN_RECOVER=n`, `CONFIG_NET_TEST=y`, and a 200 ms connect timeout. It adds `-ftrivial-auto-var-init=pattern` solely to stabilize a separate v4.4.2 uninitialized-`proxy_len` prerequisite and adds `-fsanitize-address-use-after-return=always` as the detection oracle. Neither flag retains the callback, extends the response objects' lifetime, or supplies the delayed bytes. Current `main` fixes the separate `proxy_len` issue but retains the lifetime defect; current `main` was not dynamically tested for this report. Security impact and proposed severity The confirmed primitive is a peer-timed and peer-valued two-byte write into expired stack storage. Source review establishes a separate four-byte command-response window. Depending on subsequent stack reuse, the invalid write can plausibly corrupt live control or data state or cause a crash, affecting integrity or availability. The AddressSanitizer abort is the test oracle and is not claimed as proof that an ordinary hardware build will deterministically crash. Static review also found that an unprivileged Zephyr userspace caller can create and configure the socket, invoke `connect()`, and retain the descriptor while the connect syscall uses privileged stack storage. That makes a userspace-to-kernel memory-integrity boundary plausible, but userspace privilege escalation was not dynamically reproduced and is not claimed. Proposed severity: Medium. A conservative provisional CVSS v3.1 vector is `CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:L/A:L` (4.8). This vector scores the network proxy or on-path attacker; it does not score the source-only userspace-to-kernel boundary, which was not dynamically established. The configured-proxy requirement, delayed delivery, open-descriptor window, small fixed-offset write, and lack of a selected victim object limit severity. High severity, arbitrary-address write, code execution, confidentiality impact, and privilege escalation are not claimed. Primary CWE: CWE-825, Expired Pointer Dereference. Suggested remediation and mitigations Revoke the receive callback and its user-data registration on timeout before caller-owned storage can expire, and synchronize that revocation with any callback already in flight. Both the callback and associated user data must be cleared safely; nulling one pointer without synchronization is insufficient. Alternatively, place SOCKS response state in storage whose lifetime is tied to the socket or context and explicitly synchronize cleanup on every exit. The successful-receive ordering should also ensure that the synchronous waiter cannot resume and return before the callback finishes using caller-owned storage. Regression tests should cover method- and command-phase timely replies, timeout without delivery, timeout followed by close, delayed delivery while open, and timeout-boundary concurrency. Temporary mitigations are to disable `CONFIG_SOCKS` when unused, use only trusted proxies over protected paths, and close a descriptor immediately after a failed SOCKS `connect()` before performing other work. Increasing the timeout only changes the window and is not a fix. Current-development and duplicate review The defect remains in current `main` at the revision listed above. A bounded review of official Zephyr issues, pull requests, commit history, and advisories found no exact public report or fix for this callback-lifetime root cause. Related material concerning SOCKS behavior and the separate `proxy_len` initialization issue did not address timeout cancellation. Private, deleted, or unindexed prior art cannot be excluded. Evidence integrity and limitations The dynamic result was reproduced twice on `native_sim/native/64` with Clang 18.1.3 and AddressSanitizer using an in-process synthetic proxy. The packaged reproducer sources are byte-identical copies of the harness sources used for those runs, but the packaged copy itself was not rebuilt or re-executed after packaging. Dynamic current-main, command-response, hardware, optimized-build, userspace, selected-victim, and non-sanitized crash results are not claimed. No hardware, radio, live target, external module, public service, production data, or destructive payload was used. Coordination Please keep this report private while the Zephyr PSIRT evaluates and remediates it. A minimal source-only reproducer and integrity manifest are prepared and can be provided through an explicitly agreed private route. </details> <!-- zepsec:original --> <!-- zepsec:patch --> Patches | Branch | Pull request | Status | | --- | --- | --- | | `main` | #117987 — `5bf0cb3eef2f` | merged | | `main` | #126144 | open | | `v4.4-branch` | #119591 | merged | | `v4.3-branch` | #119945 | merged | | `v3.7-branch` | #119946 | merged | Incomplete fix. The patches above do not close the whole vulnerability: the error-path clear does not stop a response callback that is already running, and the success-path handover is not covered The remaining fix is tracked in #126144. <!-- zepsec:patch --> For more information If you have any questions or comments about this advisory: Open an issue in zephyr Email us at Zephyr-vulnerabilities embargo: 2026-11-28
Severity Level
MEDIUM(6.5)
Published Date
Nov 29, 2026
Last Modified
Nov 29, 2026
Exploitation Status
No confirmed exploitation yet
CVE Record Status
Reserved
This CVE ID is referenced in a public advisory, but the CVE Program has not published its official CVE Record yet. Full CVSS/CPE data from NVD will appear here once it does.
Root Weakness (CWE)
The product dereferences a pointer that contains a location for memory that was previously valid, but is no longer valid.
CVSS v3.1 Base Metrics — Score 6.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L
Attack VectorNetwork
Attack ComplexityLow
Privileges RequiredNone
User InteractionNone
ScopeUnchanged
ConfidentialityNone
IntegrityLow
AvailabilityLow

Affected & Patched Versions

Affected Versions
  • zephyr >= 2.0.0, < 4.3.2
  • zephyr >= 4.4.0, < 4.5.0
Patched Versions
  • zephyr 4.3.2
  • zephyr 4.5.0

What to do

Fix it during your normal patch cycle. No exploitation is confirmed yet.

  1. Check whether you run zephyr and which version.
  2. Update to a patched version listed above, then confirm the new version.

Timeline

  • Nov 29, 2026Published
  • Nov 29, 2026Record last modified

Score, severity and exploitation changes are tracked from the day Watchtower started logging them.

Get notified about new zephyr CVEsYou are reading CVE-2026-95821. Get an email when KEV listings, exploits or new CVEs match your stack.
Set up CVE alerts

Data last checked: Nov 29, 2026 20:01 UTC