Skip to content

Out of bounds read when unpacking DNS answers

High
ceolin published GHSA-x975-8pgf-qh66 Feb 25, 2025

Package

zephyr (zephyr)

Affected versions

<= 4.0

Patched versions

None

Description

Summary

The dns_unpack_answer function in dns_pack.c decodes DNS answers from incoming DNS
data. A lack of input validation allows for out of bounds reads caused by malicious or malformed
packets.

These functions are mostly called by dns_unpack_answer (line 109 in subsys/net/lib/dns/dns_pack.c as of 6798064), which is responsible for decoding incoming DNS data. There are many cases where these out of bounds failures occur, but this report will be
focusing on a specific case and a general solution that will correct all out of bounds reads.

Details

The target function is called when validating received DNS messages. Here is a vulnerable
program flow.

  • The answer pointer in line 118 is computed to point to the start of the DNS answers.
  • dname_len is calculated in line 120.
  • rem_size is computed and validated in line 137. However, this validation is wrong as it does not recognize the answer_offset. rem_size is computed with respect to the start of the packet, instead of the start of the answer region.
  • Hence, all accesses to the buffer pointed to by answer (lines 152 to 169) can potentially lead to an out-of-bound read.

This vulnerability can be exposed with the following packet.

uint8_t msg[18] = {7, 7, 141, 128, 0,

Impact

This out-of-bounds read can cause a crash and lead to a denial of service.

Fix Recommendation

This vulnerability can be fixed by updating the computation of rem_size in line 137.

rem_size = dns_msg->msg_size - dns_msg->answer_offset - dname_len;
if (rem_size < 2 + 2 + 4 + 2) {
return -EINVAL;
}

Patches

main: #82072

v4.0.0: #82289
v3.7.0: #82288

For more information

If you have any questions or comments about this advisory:

embargo: 2025-02-13

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

CVE ID

CVE-2025-1674

Weaknesses

Credits