Skip to content

Harden DNS response parser against malformed replies#14

Open
dfateyev wants to merge 1 commit into
halon:masterfrom
dfateyev:harden-dns-response
Open

Harden DNS response parser against malformed replies#14
dfateyev wants to merge 1 commit into
halon:masterfrom
dfateyev:harden-dns-response

Conversation

@dfateyev

Copy link
Copy Markdown
Contributor

The POSIX resolver parsed res_nquery() responses without validating record boundaries, trusting attacker-controlled header counts and RDLENGTH fields. A spoofed or malicious DNS reply could trigger out-of-bounds reads of the 64 KiB response buffer, causing crashes or leaking adjacent stack memory into the resolved addresses.

  • Bounds-check the fixed RR fields (TYPE/CLASS/TTL/RDLENGTH) and the question section before reading them.
  • Verify RDLENGTH stays within the response before use.
  • Guard the MX PREFERENCE subtraction against RDLENGTH < 2, which previously underflowed the unsigned length and advanced the cursor far past the buffer.
  • Require A/AAAA rdata to be large enough before inet_ntop() reads its fixed 4/16 bytes.
  • Advance the record cursor by the original RDLENGTH via a separate rdata pointer, decoupling it from the MX preference read.

The POSIX resolver parsed res_nquery() responses without validating
record boundaries, trusting attacker-controlled header counts and
RDLENGTH fields. A spoofed or malicious DNS reply could trigger
out-of-bounds reads of the 64 KiB response buffer, causing crashes or
leaking adjacent stack memory into the resolved addresses.

- Bounds-check the fixed RR fields (TYPE/CLASS/TTL/RDLENGTH) and the
  question section before reading them.
- Verify RDLENGTH stays within the response before use.
- Guard the MX PREFERENCE subtraction against RDLENGTH < 2, which
  previously underflowed the unsigned length and advanced the cursor
  far past the buffer.
- Require A/AAAA rdata to be large enough before inet_ntop() reads its
  fixed 4/16 bytes.
- Advance the record cursor by the original RDLENGTH via a separate
  rdata pointer, decoupling it from the MX preference read.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant