Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-16643

glibc: nscd fails to resolve IP address depending on hosts cache ordering

    • Icon: Bug Bug
    • Resolution: Done-Errata
    • Icon: Major Major
    • rhel-9.4
    • rhel-9.2.0
    • glibc
    • glibc-2.34-98.el9
    • ZStream
    • sst_pt_libraries
    • ssg_platform_tools
    • 20
    • 23
    • 1
    • QE ack, Dev ack
    • False
    • Hide

      None

      Show
      None
    • Yes
    • Approved Blocker
    • Bug Fix
    • Hide
      .The `glibc` `getaddrinfo` function now correctly reads `ncsd` cache information

      Previously, a bug in the `glibc` `getaddrinfo` function would cause it to occasionally return empty elements in the list address information structure. With this update, the `getaddrinfo` function has been fixed to read and translate `ncsd` cache data correctly and, as a result, returns correct address information.
      Show
      .The `glibc` `getaddrinfo` function now correctly reads `ncsd` cache information Previously, a bug in the `glibc` `getaddrinfo` function would cause it to occasionally return empty elements in the list address information structure. With this update, the `getaddrinfo` function has been fixed to read and translate `ncsd` cache data correctly and, as a result, returns correct address information.
    • Done
    • x86_64

      What were you trying to do that didn't work?

      After a system upgrade that changed the glibc version from glibc-2.34-40.el9_1.1.src.rpm to glibc-2.34-60.el9_2.7.src.rpm we started noticing the JVM intermediately resolving host names to the 0.0.0.0 mask:

      import java.net.InetSocketAddress
      
      System.setProperty("java.net.preferIPv4Stack" , "true");
      
      System.out.println("Prefer IPv4 = " + System.getProperty("java.net.preferIPv4Stack"));
      System.out.println("Prefer IPv6 = " + System.getProperty("java.net.preferIPv6Addresses"));
      System.out.println();
      
      for (int i = 0;; i++) {
          var addr = new InetSocketAddress("google.com", 443);
          System.out.println(i + " " + addr);
          Thread.sleep(5000);
      }
      
      Prefer IPv4 = true
      Prefer IPv6 = null
      
      0 google.com/216.58.222.14:443
      1 google.com/216.58.222.14:443
      2 google.com/216.58.222.14:443
      ...
      24 google.com/216.58.222.14:443
      25 google.com/0.0.0.0:443
      26 google.com/0.0.0.0:443
      27 google.com/0.0.0.0:443
      ...
      81 google.com/0.0.0.0:443
      82 google.com/216.58.222.14:443
      83 google.com/216.58.222.14:443
      

      After reading through the OpenJDK's code base we were able to narrow it down to the glibc's getaddrinfo call: if passing an IPv4 hint and the first IP address in the hosts cache file is an IPv6 address, we get an empty addrinfo struct back with no error code.

      Please provide the package NVR for which bug is seen:

      The bug was reproduced in:

      • glibc-2.34-60.el9_2.7.src.rpm
      • glibc-2.34-83.el9_3.7.src.rpm

      How reproducible:

      Steps to reproduce

      1.  Starting with RHEL 9.2 and install nscd and gcc;
      2.  Compile this code with gcc -o repro repro.c and run it with ./repro google.com);
      3.  On another shell, look at the nscd hosts file with nscd -p /var/db/nscd/hosts and invalidate (sudo nscd -i hosts) nscd's hosts cache until the first IP address in the cache file for the target host name is an IPv6 address, followed by an IPv4 address.

      Expected results

      The correct IPv4 address is always returned.

      Actual results

      IPv4 is returned until the hosts file order changes:

      [root@5f8af5257739 wrk]# ./repro "google.com"
      ...
      17 family=IPv4 size=16 addr=216.58.222.14 family=IPv4 size=16 addr=216.58.222.14 family=IPv4 size=16 addr=216.58.222.14
      18 family=IPv4 size=16 addr=216.58.222.14 family=IPv4 size=16 addr=216.58.222.14 family=IPv4 size=16 addr=216.58.222.14
      19 family=IPv4 size=16 addr=216.58.222.14 family=IPv4 size=16 addr=216.58.222.14 family=IPv4 size=16 addr=216.58.222.14
      20 family=IPv4 size=16 addr=216.58.222.14 family=IPv4 size=16 addr=216.58.222.14 family=IPv4 size=16 addr=216.58.222.14
      21 family=IPv4 size=16 addr=216.58.222.14 family=IPv4 size=16 addr=216.58.222.14 family=IPv4 size=16 addr=216.58.222.14
      22 family=IPv4 size=16 addr=216.58.222.14 family=IPv4 size=16 addr=216.58.222.14 family=IPv4 size=16 addr=216.58.222.14
      23 family=IPv4 size=16 addr=216.58.222.14 family=IPv4 size=16 addr=216.58.222.14 family=IPv4 size=16 addr=216.58.222.14
      ...
      24 family=0 family=0 family=0
      25 family=0 family=0 family=0
      26 family=0 family=0 family=0
      27 family=0 family=0 family=0
      28 family=0 family=0 family=0
      ...
      

            ashankar@redhat.com Arjun Shankar
            erickpintor Erick Pintor
            Arjun Shankar Arjun Shankar
            Sergey Kolosov Sergey Kolosov
            Petr Hybl Petr Hybl
            Votes:
            0 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved: