Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <226cc023.3094a.1a212f4a7b3.Coremail.zhaotq@pku.edu.cn>
Date: Wed, 25 Nov 2026 21:45:53 +0800 (GMT+08:00)
From: zhaotq@....edu.cn
To: musl@...ts.openwall.com
Subject: getaddrinfo accepts a DNS reply with QDCOUNT=0

Hello,

While testing musl 1.2.5, we found that getaddrinfo() accepts a DNS reply
that does not contain a question section. The same code is still present in
musl 1.2.6 and current master.

Environment:
* Linux
* musl 1.2.5
* A local UDP DNS responder configured as nameserver 127.0.0.1

Reproduction steps:
1. Build the attached program with musl:

       musl-gcc -O2 -static dns-response-validation-poc.c -o dns-question-poc

2. Run it as root in a disposable Linux container. The program writes
   /etc/resolv.conf and binds a local UDP responder to 127.0.0.1:53.
3. The program calls getaddrinfo("victim.invalid", "80", ...) with
   ai_family=AF_INET. The responder copies the query's transaction ID but
   returns QDCOUNT=0, ANCOUNT=1, and an A record for 198.51.100.66.

Expected: The reply is ignored because it does not echo the outstanding
question. With no valid reply available, the lookup should fail.

Actual: getaddrinfo() succeeds and returns 198.51.100.66:

    getaddrinfo=0 gai=OK address=198.51.100.66 qdcount=0

As a control, glibc 2.36 rejects the same reply and returns EAI_AGAIN.

Debugging:

1. In src/network/res_msend.c, __res_msend_rc() checks the UDP source
   endpoint, then associates the reply with a query using its transaction
   ID:

       for (i=next; i<nqueries && (
           answers[next][0] != queries[i][0] ||
           answers[next][1] != queries[i][1] ); i++);
       if (i==nqueries) continue;
       if (alens[i]) continue;

   After checking the response code, it stores the reply length without
   checking the question section:

       alens[i] = rlen;

2. In src/network/dns_parse.c, __dns_parse() skips zero questions when
   QDCOUNT=0 and continues parsing the Answer section.
3. The callback in src/network/lookup_name.c filters records only by type
   and length. It does not check the record's owner or a CNAME chain, so
   it accepts the A record even though its owner is the root name rather
   than victim.invalid.

RFC 5452 section 9.1 requires matching the query name, class, and type
against the outstanding query, and treating a mismatch as invalid. A
QDCOUNT=0 reply contains no question that can match the outstanding query:
https://www.rfc-editor.org/rfc/rfc5452#section-9.1

Could you review this issue? Thanks in advance!

Tianqi

View attachment "dns-response-validation-poc.c" of type "text/plain" (2599 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.