Bug 824201 - getaddrinfo DNS referral response returns host not found when A and AAAA questions are sent and one response is a referral
getaddrinfo DNS referral response returns host not found when A and AAAA ques...
Status: CLOSED UPSTREAM
Product: Fedora
Classification: Fedora
Component: glibc (Show other bugs)
16
All Linux
unspecified Severity low
: ---
: ---
Assigned To: Jeff Law
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-05-22 20:58 EDT by Gino LV. Ledesma
Modified: 2016-11-24 10:51 EST (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 845218 (view as bug list)
Environment:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Wireshark Packet Capture (1.41 KB, application/octet-stream)
2012-05-22 21:14 EDT, Gino LV. Ledesma
no flags Details


External Trackers
Tracker ID Priority Status Summary Last Updated
Sourceware 14308 None None None Never

  None (edit)
Description Gino LV. Ledesma 2012-05-22 20:58:58 EDT
Description of problem:

I'm seeing a very edge-case issue with Linux hosts complaining about "host not found" name resolution errors when using the getaddrinfo() API call as provided by glibc. When getaddrinfo() is called on hosts with the IPv6 module loaded, it sends a parallel query for A and AAAA records. If one of the responses is a referral response and the other is not (e.g. A is not-referral but AAAA is referral), the function will terminate and return value -2, "No address associated with hostname" error.

Version-Release number of selected component (if applicable):

Any Linux host running glibc 2.9 or later
Affected distributions:
- Fedora 10-16, rawhide
- EL 6.0 and later

How reproducible:
100% under specific conditions:
- Linux running glibc 2.9 or later with IPv6 enabled
- Citrix Netscaler as a DNS server

Steps to Reproduce:
1. Install Fedora 16 (e.g. Live ISO)
2. Setup and install any DNS server (e.g. ISC Bind) and configure it to be an authoritative name server for a zone (e.g. example.com)
3. Setup and install a Citrix Netscaler load-balancer (e.g. VPX appliance) and configure a DNS proxy VIP
4. Enable DNS caching on the Citrix Netscaler load-balancer (set dns parameter -cache YES)
5. Configure the Linux host to use the DNS VIP as its resolver
6. Disable nscd on the Linux host to bypass name caching (alternatively, use nscd -i hosts in between calls)
7. Run a program that uses getaddrinfo() (e.g. curl, wget, telnet, etc) to resolve a hostname

Actual results:
curl -v hostname.example.com
* getaddrinfo(3) failed for hostname.example.com:80
* Couldn't resolve host 'hostname.example.com
* Closing connection #0
curl: (6) Couldn't resolve host 'hostname.example.com'

Expected results:
Connection should be fine

Additional Info:
A buggy DNS server is exposing an edge-case bug in glibc

Related Bugs:
Citrix SR 60783234
Comment 1 Gino LV. Ledesma 2012-05-22 21:14:19 EDT
Created attachment 586223 [details]
Wireshark Packet Capture
Comment 2 Gino LV. Ledesma 2012-05-22 21:14:34 EDT
I took a packet capture of the DNS request-response scenario (dns.pcap) and found the following

Case 1: Response is served fresh (not from cache)
Frame 01	Client:	A?	active-mrepo.me.com
Frame 02	Client:	AAAA?	active-mrepo.me.com
Frame 03	VIP:	A	1/1/1 active-mrepo.me.com. 17.172.194.16
Frame 04	VIP:	AAAA	0/1/0 hostmaster... 

Case 2: Response is served from cache
Frame 05	Client:	A?	active-mrepo.me.com
Frame 06	Client: AAAA?	active-mrepo.me.com
Frame 07	VIP:	A	1/0/0 active-mrepo.me.com. 17.172.194.16
Frame 08	VIP:	AAAA	0/0/0 hostmaster... 

# Try 2 (this is done automatically by glibc)
Frame 09	Client:	A?	active-mrepo.me.com
Frame 10	Client:	AAAA?	active-mrepo.me.com
Frame 11	VIP:	A	1/0/0 active-mrepo.me.com. 17.172.194.16
Frame 12	VIP:	AAAA	0/0/0 hostmaster... 

As best as I can tell, there are two things happening here:
1) This DNS server is serving a DNS response that falls under NODATA type 3 (RFC 2308 section 2.2)
2) glibc's (mis-?) interpretation of a referral response and short-circuiting its logic

glibc interprets DNS responses as "referral" if the following conditions are met (see glibc 2.15, resolv/res_send.c lines 1301-1303):
a) rcode == NOERROR
b) ancount == 0
c) aa == 0
d) ra == 0
e) arcount == 0

I see that this change was introduced in glibc 2.9 and is still present in 2.15.

In the above situation when two responses come in (A response = authoritative, AAAA = referral), send_dg() immediately returns 0, causing __libc_res_nsend to try the next nameserver and repeat the query, ignoring any valid responses that may have come in.
Comment 3 Gino LV. Ledesma 2012-05-22 21:20:21 EDT
Here is a debug call-trace of glibc with RES_DEBUG enabled:

looking up: active-mrepo
;; res_setoptions(" timeout:600 debug
", "conf")..
;;	debug
dots=0, statp->ndots=1, trailing_dot=0, name=active-mrepo
;; res_nquerydomain(active-mrepo, me.com, 1, 62321)
;; res_query(active-mrepo.me.com, 1, 62321)
;; res_nmkquery(QUERY, active-mrepo.me.com, IN, A)
;; res_nmkquery(QUERY, active-mrepo.me.com, IN, AAAA)
;; res_send()
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 49477
;; flags: rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;;	active-mrepo.me.com, type = A, class = IN
;; Querying server (# 1) address = 17.230.128.24
referred query:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 8813
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;;	active-mrepo.me.com, type = AAAA, class = IN
;; got answer:
;; ns_initparse: Message too long
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 8813
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;;	active-mrepo.me.com, type = AAAA, class = IN

The call trace won't show the A response because the AAAA referral response returns 0 immediately.

Adjusting the next_ns: goto label to be moved above the if(buf2 != null) under the SERVAIL/NOTIMP/REFUSED code checks seems like a work-around but is most likely incorrect (due to the subsequent goto wait call).
Comment 4 Gino LV. Ledesma 2012-05-22 21:24:17 EDT
On a side note, I can only make this happen with the Citrix Netscaler acting as a DNS cache. Other caching resolvers (bind, dnsmasq, dnscache, pdns-recursor, etc) do not expose this behavior in glibc because they will either have the "aa" or "ra" bits set to 1. The Netscaler seems to be unique in serving the following combination of flags for type=AAAA:

rcode == NOERROR
ancount == 0
ra == 0
arcount == 0
nscount=0

I've filed a bug with Citrix for this problem: Citrix SR 60783234
Comment 6 Gino LV. Ledesma 2012-05-23 14:16:26 EDT
Work-arounds:
1. Disable Netscaler caching (set dns param -cache NO)
2. Switch service type from DNS/DNS_TCP to UDP/TCP
3. Make Netscaler authoritative for all zones that its DNS proxying for (add ns soaRecord ...)
4. Disable IPv6 on client-side

Some notes / tidbits:
1. This behavior does NOT affect older glibc hosts (e.g. EL 5.x), presumably because gethostbyname3_r does two separate calls for A/AAAA
2. The order of the response (whether A or AAAA comes first) doesn't seem to matter
Comment 7 Jeff Law 2012-05-23 15:24:12 EDT
I'd be real interested to know if the F17 glibc fixes this problem.  There were a number of fixes in these paths through the resolver that might help.
Comment 8 Gino LV. Ledesma 2012-05-23 19:08:23 EDT
I just installed Fedora 17 i386 on a VM to test this. Problem still persists there (glibc-2.15-37.fc17.i686).

I've also confirmed that the problem exists with upstream, stock glibc 2.15.

Note You need to log in before you can comment on or make changes to this bug.