CVE-2026-79981: DNS resolver reuses a single UDP source port for all queries, easing off-path answer spoofing
The DNS stub resolver in subsys/net/lib/dns/resolve.c binds one UDP socket per configured server when the resolver context is initialised (dnsresolveinitlocked() -> registerdispatcher() -> dnsdispatcherregister()), with the local port left at 0 so the stack picks an ephemeral port exactly once. dnswrite() then sends every subsequent query from that same socket without re-binding, so the source port is constant for the lifetime of the resolver context while only the 16-bit transaction identifier (ctx->queries[i].id, drawn with sysrand16get()) varies per query. RFC 5452 section 9.2 requires both to vary; with a fixed port, an off-path attacker has to guess only the identifier.
The stable port is cheap to learn. Any single observed query reveals it permanently, and it can also be found by probing the ephemeral UDP range: subsys/net/ip/connection.c answers unmatched unicast UDP with an ICMP port-unreachable, so the resolver's socket is the one port in that range that stays silent. Acceptance of a reply is decided solely by getslotbyid() matching the transaction identifier and a CRC-16 of the queried name — the reply's source address is never checked (dispatchercb() does ARGUNUSED(addr)), so forged answers need not even be spoofed to appear to come from the configured server; they only need to reach the resolver's port.
An attacker with UDP reachability to the device (same LAN, Wi-Fi or mesh segment, or a globally routable device address) can therefore flood answers for a predictable query name across the 16-bit identifier space during a query window and race the legitimate server. A win makes the application resolve an attacker-chosen address, and with CONFIGDNSRESOLVERCACHE enabled the forged record is retained for its attacker-chosen TTL. The attack still requires winning that race, and applications that validate TLS certificates for the resolved endpoint are largely protected.
The fix draws a fresh local port before each query to a server that has nothing outstanding: dnsrandomizesourceport() unregisters the dispatcher, closes and reopens the socket, and re-registers it bound to port 0 so the system selects a new port, raising the per-query guessing space from roughly 16 to roughly 31 bits. Multicast DNS and LLMNR are excluded because their ports are protocol-fixed. The behaviour is controlled by CONFIGDNSRESOLVERRANDOMIZESOURCEPORT (default y).
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Configuration
Enable source-port randomization for DNS resolver queries.
DNS stub resolver CONFIG_DNS_RESOLVER_RANDOMIZE_SOURCE_PORT = y
Event History
Frequently Asked Questions
Does exploitation require an on-path attacker or prior authentication?
No. The issue enables off-path answer spoofing, and the vector is network-accessible with no privileges or user interaction required. The attacker needs to predict the transaction identifier after learning the resolver's stable UDP source port.
How can an attacker determine the resolver's UDP source port?
A single observed DNS query reveals the port for the lifetime of that resolver context. It may also be discovered by probing the ephemeral UDP port range, because unmatched unicast UDP receives ICMP port-unreachable responses while the resolver's bound port remains silent.
Are spoofed replies restricted to the configured DNS server?
No. Reply acceptance is based on a matching transaction identifier and a CRC-16 of the queried name. The reply source address is not checked.