[Bug libc/26630] New: getaddrinfo drops ipv6 V4MAPPED addresses from ncsd results

dj at redhat dot com sourceware-bugzilla@sourceware.org
Wed Sep 16 20:57:31 GMT 2020


https://sourceware.org/bugzilla/show_bug.cgi?id=26630

            Bug ID: 26630
           Summary: getaddrinfo drops ipv6 V4MAPPED addresses from ncsd
                    results
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: dj at redhat dot com
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

Consider a set of DNS records like this:

testv5c         IN      A       1.2.3.9
testv5c         IN      AAAA    2001:1234::8393
testv5c         IN      AAAA    ::ffff:2.3.4.5

"getent ahosts testv5c" normally returns:

1.2.3.9         STREAM testv5c
1.2.3.9         DGRAM  
1.2.3.9         RAW    
::ffff:2.3.4.5  STREAM 
::ffff:2.3.4.5  DGRAM  
::ffff:2.3.4.5  RAW    
2001:1234::8393 STREAM 
2001:1234::8393 DGRAM  
2001:1234::8393 RAW    

If NSCD is running, it instead returns:

1.2.3.9         STREAM testv5c
1.2.3.9         DGRAM  
1.2.3.9         RAW    
2001:1234::8393 STREAM 
2001:1234::8393 DGRAM  
2001:1234::8393 RAW    

While this seems (arguably) normal, if the second AAAA DNS entry is missing,
only the IPv4 records are printed.  If the *only* DNS response is a V4MAPPED
address (i.e. ::ffff:*), getent will return nothing.

The root cause of this is thus:

* In sysdeps/posix/getaddrinfo.c around line 691, we are iterating on the list
of addresses we got from nscd, and detect that we've gotten at least one valid
IPv6 address, and set the "got_ipv6" flag[1].

* Around line 1035 we iterate over the list of addresses and discard any
"V4MAPPED" addresses if we've seen any IPv6 addresses.

The problem is, the IPv6 address we saw - and set the flag for - is the same
address we're later discarding.  If the test around line 691 adds a conditional
on not being a V4-mapped address, the test case seems to work correctly,
although the actual fix may be more complicated than that.  Testing should
include all eight permutations of address family availability (v4, v4mapped,
v6) with and without nscd running.

[1] Note this flag is also set around line 807, for non-nscd lookups, but does
not seem to cause the same problem.  Further investigation is warranted here.

Originally reported at https://bugzilla.redhat.com/show_bug.cgi?id=901532

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Glibc-bugs mailing list