public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Stefan Liebler <stli@linux.vnet.ibm.com>, libc-alpha@sourceware.org
Subject: Re: [PATCH][BZ 21295] getaddrinfo: do not overwrite IPv6 IPs with IPv4 when using AF_UNSPEC
Date: Thu, 06 Jul 2017 12:19:00 -0000	[thread overview]
Message-ID: <1ae7c5f6-530a-2ed5-452d-99387cd6ee9a@redhat.com> (raw)
In-Reply-To: <a0cbf96b-96f0-cf27-37c2-ca13766eade5@linux.vnet.ibm.com>

[-- Attachment #1: Type: text/plain, Size: 1031 bytes --]

On 07/06/2017 11:02 AM, Stefan Liebler wrote:
> I've recognized the test-fail resolv/tst-resolv-basic on some but not
> all machines of mine on different architectures s390, intel, power and
> according to 2.26 release page, Joseph also recognized it on his arm,
> mips, power32 machines:
> warning: could not become root outside namespace (Operation not permitted)
> warning: unshare (CLONE_NEWUTS) failed: Operation not permitted
> warning: could not enter network namespace
> error: addrinfo comparison failure
> query: www.example:80 [10]/0x18
> --- expected
> +++ actual
> @@ -1,3 +1,3 @@
>  flags: AI_V4MAPPED AI_ALL
> -address: STREAM/TCP 2001:db8::1 80
>  address: STREAM/TCP ::ffff:192.0.2.17 80
> +address: STREAM/TCP 2001:db8::1 80
> error: addrinfo comparison failure
> query: t.www.example:80 [10]/0x18

I saw this as well, but have not figured out whether it's due to UDP
response ordering or system configuration if (network) namespaces are
not in effect.

Would you please try the attached patch?  Thanks.

Florian

[-- Attachment #2: ipv6-order.patch --]
[-- Type: text/x-patch, Size: 3867 bytes --]

resolv: Deal with non-deterministic address order in tst-resolv-basic

2017-07-06  Florian Weimer  <fw@deneb.enyo.de>

	* resolv/tst-resolv-basic.c (test_bug_21295): New function.
	(do_test): Call it.

diff --git a/resolv/tst-resolv-basic.c b/resolv/tst-resolv-basic.c
index 3dfa165..64eedbb 100644
--- a/resolv/tst-resolv-basic.c
+++ b/resolv/tst-resolv-basic.c
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <support/check.h>
 #include <support/check_nss.h>
+#include <support/format_nss.h>
 #include <support/resolv_test.h>
 #include <support/support.h>
 
@@ -204,6 +205,68 @@ check_ai (const char *name, const char *service,
                          expected);
 }
 
+/* Test for bug 21295: getaddrinfo used to discard address information
+   instead of merging it.  */
+static void
+test_bug_21295 (void)
+{
+  /* The address order is unpredictable.  There are two factors which
+     contribute to that: The stub resolver does not perform proper
+     response matching for A/AAAA queries (an A response could be
+     associated with an AAAA query and vice versa), and without
+     namespaces, system configuration could affect address
+     ordering.  */
+  for (int do_tcp = 0; do_tcp < 2; ++do_tcp)
+    {
+      const struct addrinfo hints =
+        {
+          .ai_family = AF_INET6,
+          .ai_socktype = SOCK_STREAM,
+          .ai_flags = AI_V4MAPPED | AI_ALL,
+        };
+      const char *qname;
+      if (do_tcp)
+        qname = "t.www.example";
+      else
+        qname = "www.example";
+      struct addrinfo *ai = NULL;
+      int ret = getaddrinfo (qname, "80", &hints, &ai);
+      TEST_VERIFY_EXIT (ret == 0);
+
+      const char *expected_a;
+      const char *expected_b;
+      if (do_tcp)
+        {
+          expected_a = "flags: AI_V4MAPPED AI_ALL\n"
+            "address: STREAM/TCP 2001:db8::3 80\n"
+            "address: STREAM/TCP ::ffff:192.0.2.19 80\n";
+          expected_b = "flags: AI_V4MAPPED AI_ALL\n"
+            "address: STREAM/TCP ::ffff:192.0.2.19 80\n"
+            "address: STREAM/TCP 2001:db8::3 80\n";
+        }
+      else
+        {
+          expected_a = "flags: AI_V4MAPPED AI_ALL\n"
+            "address: STREAM/TCP 2001:db8::1 80\n"
+            "address: STREAM/TCP ::ffff:192.0.2.17 80\n";
+          expected_b = "flags: AI_V4MAPPED AI_ALL\n"
+            "address: STREAM/TCP ::ffff:192.0.2.17 80\n"
+            "address: STREAM/TCP 2001:db8::1 80\n";
+        }
+
+      char *actual = support_format_addrinfo (ai, ret);
+      if (!(strcmp (actual, expected_a) == 0
+            || strcmp (actual, expected_b) == 0))
+        {
+          support_record_failure ();
+          printf ("error: %s: unexpected response (TCP: %d):\n%s\n",
+                  __func__, do_tcp, actual);
+        }
+      free (actual);
+      freeaddrinfo (ai);
+    }
+}
+
 static int
 do_test (void)
 {
@@ -398,21 +461,7 @@ do_test (void)
   check_ai ("t.nxdomain.example", "80", AF_INET6,
             "error: Name or service not known\n");
 
-  /* Test for bug 21295.  */
-  check_ai_hints ("www.example", "80",
-                  (struct addrinfo) { .ai_family = AF_INET6,
-                      .ai_socktype = SOCK_STREAM,
-                      .ai_flags = AI_V4MAPPED | AI_ALL, },
-                  "flags: AI_V4MAPPED AI_ALL\n"
-                  "address: STREAM/TCP 2001:db8::1 80\n"
-                  "address: STREAM/TCP ::ffff:192.0.2.17 80\n");
-  check_ai_hints ("t.www.example", "80",
-                  (struct addrinfo) { .ai_family = AF_INET6,
-                      .ai_socktype = SOCK_STREAM,
-                      .ai_flags = AI_V4MAPPED | AI_ALL, },
-                  "flags: AI_V4MAPPED AI_ALL\n"
-                  "address: STREAM/TCP 2001:db8::3 80\n"
-                  "address: STREAM/TCP ::ffff:192.0.2.19 80\n");
+  test_bug_21295 ();
 
   resolv_test_end (aux);
 

  reply	other threads:[~2017-07-06 12:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-23 13:21 kmeaw
2017-04-20 12:41 ` Florian Weimer
2017-04-20 12:58   ` Florian Weimer
2017-04-20 13:44   ` kmeaw
2017-04-20 14:05     ` Florian Weimer
2017-06-24 14:59 ` Florian Weimer
2017-07-06  9:03   ` Stefan Liebler
2017-07-06 12:19     ` Florian Weimer [this message]
2017-07-06 15:18       ` Stefan Liebler
2017-07-06 21:05         ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1ae7c5f6-530a-2ed5-452d-99387cd6ee9a@redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=stli@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).