public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure
@ 2011-07-13  4:24 jik at kamens dot us
  2011-07-13  4:24 ` [Bug libc/12994] " jik at kamens dot us
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: jik at kamens dot us @ 2011-07-13  4:24 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12994

           Summary: getaddrinfo fails if response records returned in
                    wrong order and one of them is server failure
           Product: glibc
           Version: 2.14
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: jik@kamens.us


Created attachment 5848
  --> http://sourceware.org/bugzilla/attachment.cgi?id=5848
tcpdump capture from getaddrinfo en.wikipedia.org

A program calls getaddrinfo.

Deep within the bowels of the resolver library, __libc_res_nquery in
res_query.c creates two queries, an A query and an AAAA query.

Deeper within the bowels of the resolver library, send_dg in res_send.c sends
both queries and waits for responses. My name server sends the response to the
*second* query *first*, and it's a server failure. I'm pretty sure that if the
responses were sent in the reverse order, the problem would not occur.

At this point things get all screwed up. I'm not sure whether the problem is in
send_dg or _libc_res_nsend or _libc_res_nquery. I've spent hours poring over
the code trying to figure out who is at fault. I can't, because this is some of
the most poorly written code I've looked at in a very long time. It's
completely incomprehensible and most of its "cleverness" is inadequately
documented.

Anyway, by the time status results bubble back up to getaddrinfo, the code has
decided that it was unable to resolve the host name to an address, even though
one of the two responses that came back from the DNS server had a valid A
record in it.

Test case? Run getaddrinfo on en.wikipedia.org immediately after restarting
your name server. I'm using BIND 9.8.0-7.P4.fc15.x86_64; I don't know how
universal this behavior is. I am attaching a wireshark dump from the virtual
interface that captures both my loopback interface (on which my client is
making its queries) and the queries my DNS server is making to try to satisfy
the local queries. And here's what my test program (which I will also attach)
prints as output:

Wed Jul 13 00:14:18 2011: getaddrinfo: Name or service not known

Note that if you run the exact same getaddrinfo call a second time immediately
afterwards it works, because the previous successful query response, which is a
CNAME, is cached and gets returned in response to both the A and AAAA queries.

Since this bug causes DNS queries that should succeed to fail in a very
user-visible way, I'm tempted to set it to critical, but I suppose since
there's no permanent loss of data it isn't actually. I don't know, tough call.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug libc/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
@ 2011-07-13  4:24 ` jik at kamens dot us
  2011-07-13  4:25 ` jik at kamens dot us
                   ` (18 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: jik at kamens dot us @ 2011-07-13  4:24 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12994

--- Comment #1 from Jonathan Kamens <jik at kamens dot us> 2011-07-13 04:22:57 UTC ---
Created attachment 5849
  --> http://sourceware.org/bugzilla/attachment.cgi?id=5849
test program

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug libc/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
  2011-07-13  4:24 ` [Bug libc/12994] " jik at kamens dot us
@ 2011-07-13  4:25 ` jik at kamens dot us
  2011-07-14  0:50 ` ppluzhnikov at google dot com
                   ` (17 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: jik at kamens dot us @ 2011-07-13  4:25 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12994

--- Comment #2 from Jonathan Kamens <jik at kamens dot us> 2011-07-13 04:24:43 UTC ---
By the way, a workaround for the problem is putting "options single-request" in
/etc/resolv.conf.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug libc/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
  2011-07-13  4:24 ` [Bug libc/12994] " jik at kamens dot us
  2011-07-13  4:25 ` jik at kamens dot us
@ 2011-07-14  0:50 ` ppluzhnikov at google dot com
  2011-07-16  5:33 ` nick.jones@network-box.com
                   ` (16 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: ppluzhnikov at google dot com @ 2011-07-14  0:50 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12994

Paul Pluzhnikov <ppluzhnikov at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppluzhnikov at google dot
                   |                            |com

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug libc/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
                   ` (2 preceding siblings ...)
  2011-07-14  0:50 ` ppluzhnikov at google dot com
@ 2011-07-16  5:33 ` nick.jones@network-box.com
  2011-12-10  8:32 ` oliverml1 at oli1170 dot net
                   ` (15 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: nick.jones@network-box.com @ 2011-07-16  5:33 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12994

nick.jones@network-box.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nick.jones@network-box.com

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug libc/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
                   ` (3 preceding siblings ...)
  2011-07-16  5:33 ` nick.jones@network-box.com
@ 2011-12-10  8:32 ` oliverml1 at oli1170 dot net
  2012-02-21  2:17 ` [Bug network/12994] " jsm28 at gcc dot gnu.org
                   ` (14 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: oliverml1 at oli1170 dot net @ 2011-12-10  8:32 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12994

Oliver Winker <oliverml1 at oli1170 dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |oliverml1 at oli1170 dot
                   |                            |net

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug network/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
                   ` (4 preceding siblings ...)
  2011-12-10  8:32 ` oliverml1 at oli1170 dot net
@ 2012-02-21  2:17 ` jsm28 at gcc dot gnu.org
  2012-11-02  1:22 ` jrnieder at gmail dot com
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2012-02-21  2:17 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12994

Joseph Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|libc                        |network

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug network/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
                   ` (5 preceding siblings ...)
  2012-02-21  2:17 ` [Bug network/12994] " jsm28 at gcc dot gnu.org
@ 2012-11-02  1:22 ` jrnieder at gmail dot com
  2012-11-03 17:01 ` karme at karme dot de
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: jrnieder at gmail dot com @ 2012-11-02  1:22 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12994

Jonathan Nieder <jrnieder at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jrnieder at gmail dot com
         AssignedTo|drepper.fsp at gmail dot    |unassigned at sourceware
                   |com                         |dot org

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug network/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
                   ` (6 preceding siblings ...)
  2012-11-02  1:22 ` jrnieder at gmail dot com
@ 2012-11-03 17:01 ` karme at karme dot de
  2012-11-04 10:49 ` karme at karme dot de
                   ` (11 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: karme at karme dot de @ 2012-11-03 17:01 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12994

karme at karme dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |karme at karme dot de

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug network/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
                   ` (7 preceding siblings ...)
  2012-11-03 17:01 ` karme at karme dot de
@ 2012-11-04 10:49 ` karme at karme dot de
  2012-11-04 10:53 ` karme at karme dot de
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: karme at karme dot de @ 2012-11-04 10:49 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12994

--- Comment #3 from karme at karme dot de 2012-11-04 10:49:15 UTC ---
First: I didn't test with the latest glibc because i failed to compile it
But I am quite sure the bug is still present and quite severe. It happens not
only if the order is wrong it also happens if there is no answer to the A
record request (either request/response is lost, dns server of the typical home
router to slow, ...)

I will attach a test with some comments.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug network/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
                   ` (8 preceding siblings ...)
  2012-11-04 10:49 ` karme at karme dot de
@ 2012-11-04 10:53 ` karme at karme dot de
  2012-11-06 11:49 ` karme at karme dot de
                   ` (9 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: karme at karme dot de @ 2012-11-04 10:53 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12994

--- Comment #4 from karme at karme dot de 2012-11-04 10:53:17 UTC ---
Created attachment 6714
  --> http://sourceware.org/bugzilla/attachment.cgi?id=6714
another test

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug network/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
                   ` (9 preceding siblings ...)
  2012-11-04 10:53 ` karme at karme dot de
@ 2012-11-06 11:49 ` karme at karme dot de
  2012-11-06 13:22 ` law at redhat dot com
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: karme at karme dot de @ 2012-11-06 11:49 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12994

--- Comment #5 from karme at karme dot de 2012-11-06 11:49:19 UTC ---
I now believe packet re-ordering is not enough to reproduce the problem. I have
written a small dns proxy for better testing. The simplest scenario to
reproduce the problem is to drop all a record requests and just answer the aaaa
request.

Answer for getaddrinfo with hints.ai_family = AF_UNSPEC is then error: r=-2
Name or service not known.

Traffic is like:

12.786202    127.0.0.1 -> 127.0.0.1    DNS 68 Standard query 0x9f5f  A karme.de
12.786962    127.0.0.1 -> 127.0.0.1    DNS 68 Standard query 0x77c8  AAAA
karme.de
14.896700    127.0.0.1 -> 127.0.0.1    DNS 119 Standard query response 0x77c8 
17.788941    127.0.0.1 -> 127.0.0.1    DNS 68 Standard query 0x9f5f  A karme.de
22.794223    127.0.0.1 -> 127.0.0.1    DNS 68 Standard query 0x9f5f  A karme.de

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug network/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
                   ` (10 preceding siblings ...)
  2012-11-06 11:49 ` karme at karme dot de
@ 2012-11-06 13:22 ` law at redhat dot com
  2012-11-07 17:33 ` karme at karme dot de
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: law at redhat dot com @ 2012-11-06 13:22 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12994

law at redhat dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |law at redhat dot com

--- Comment #6 from law at redhat dot com 2012-11-06 13:22:26 UTC ---
Just one question (because I believe this bug is ultimately a duplicate of
another existing issue), what is the failure mode you're seeing?  ie, do you
hit an assert, abort, segfault, error code, whatever.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug network/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
                   ` (11 preceding siblings ...)
  2012-11-06 13:22 ` law at redhat dot com
@ 2012-11-07 17:33 ` karme at karme dot de
  2012-11-27 12:02 ` karme at karme dot de
                   ` (6 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: karme at karme dot de @ 2012-11-07 17:33 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12994

--- Comment #7 from karme at karme dot de 2012-11-07 17:32:42 UTC ---
(In reply to comment #6)
> Just one question (because I believe this bug is ultimately a duplicate of
> another existing issue), what is the failure mode you're seeing?  ie, do you
> hit an assert, abort, segfault, error code, whatever.

getaddrinfo returns error code EAI_NONAME when it should return EAI_EAGAIN

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug network/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
                   ` (12 preceding siblings ...)
  2012-11-07 17:33 ` karme at karme dot de
@ 2012-11-27 12:02 ` karme at karme dot de
  2012-11-27 16:52 ` law at redhat dot com
                   ` (5 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: karme at karme dot de @ 2012-11-27 12:02 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12994

--- Comment #8 from karme at karme dot de 2012-11-27 12:02:30 UTC ---
(In reply to comment #6)
> Just one question (because I believe this bug is ultimately a duplicate of
> another existing issue), what is the failure mode you're seeing?  ie, do you
> hit an assert, abort, segfault, error code, whatever.

which is the bug number you think this a duplicate of?

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug network/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
                   ` (13 preceding siblings ...)
  2012-11-27 12:02 ` karme at karme dot de
@ 2012-11-27 16:52 ` law at redhat dot com
  2012-12-16 15:55 ` psimerda at redhat dot com
                   ` (4 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: law at redhat dot com @ 2012-11-27 16:52 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12994

--- Comment #9 from law at redhat dot com 2012-11-27 16:51:41 UTC ---
I thought it might be a duplicate of 13013, 13651 or another (# escapes me) in
the Red Hat bugzilla database.   Based on the information you provided in c#7 I
believe this is a separate issue.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug network/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
                   ` (14 preceding siblings ...)
  2012-11-27 16:52 ` law at redhat dot com
@ 2012-12-16 15:55 ` psimerda at redhat dot com
  2014-04-16  7:34 ` siddhesh at redhat dot com
                   ` (3 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: psimerda at redhat dot com @ 2012-12-16 15:55 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12994

Pavel Šimerda <psimerda at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |psimerda at redhat dot com

--- Comment #10 from Pavel Šimerda <psimerda at redhat dot com> 2012-12-16 15:54:57 UTC ---
Splitting this bug report so that it only refers to literal address
translation.

For /etc/hosts resolutions, see:

http://sourceware.org/bugzilla/show_bug.cgi?id=14966

For other name resolution problems, search for the bug report and file a new
one if you don't find it.

That means that if Tore's patch works, this bug can be closed and the other one
would be tracked separately.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug network/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
                   ` (15 preceding siblings ...)
  2012-12-16 15:55 ` psimerda at redhat dot com
@ 2014-04-16  7:34 ` siddhesh at redhat dot com
  2014-04-16  9:11 ` siddhesh at redhat dot com
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: siddhesh at redhat dot com @ 2014-04-16  7:34 UTC (permalink / raw)
  To: glibc-bugs

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

Siddhesh Poyarekar <siddhesh at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |siddhesh at redhat dot com

--- Comment #11 from Siddhesh Poyarekar <siddhesh at redhat dot com> ---
I've posted a patch[1] that fixes bug 14308, which I think should fix this bug
too.  I have tested using some convoluted packet mangling, so I would
appreciate it if someone does an actual test with their nameservers.

[1] https://sourceware.org/ml/libc-alpha/2014-04/msg00302.html

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


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug network/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
                   ` (16 preceding siblings ...)
  2014-04-16  7:34 ` siddhesh at redhat dot com
@ 2014-04-16  9:11 ` siddhesh at redhat dot com
  2014-04-30  6:38 ` siddhesh at redhat dot com
  2014-06-27 12:55 ` fweimer at redhat dot com
  19 siblings, 0 replies; 21+ messages in thread
From: siddhesh at redhat dot com @ 2014-04-16  9:11 UTC (permalink / raw)
  To: glibc-bugs

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

Siddhesh Poyarekar <siddhesh at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aurelien at aurel32 dot net

--- Comment #12 from Siddhesh Poyarekar <siddhesh at redhat dot com> ---
*** Bug 13651 has been marked as a duplicate of this bug. ***

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


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug network/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
                   ` (17 preceding siblings ...)
  2014-04-16  9:11 ` siddhesh at redhat dot com
@ 2014-04-30  6:38 ` siddhesh at redhat dot com
  2014-06-27 12:55 ` fweimer at redhat dot com
  19 siblings, 0 replies; 21+ messages in thread
From: siddhesh at redhat dot com @ 2014-04-30  6:38 UTC (permalink / raw)
  To: glibc-bugs

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

Siddhesh Poyarekar <siddhesh at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #13 from Siddhesh Poyarekar <siddhesh at redhat dot com> ---
Fixed in master:

 Do not fail if one of the two responses to AF_UNSPEC fails (BZ #14308)

    [Fixes BZ #14308, #12994, #13651]

    AF_UNSPEC results in sending two queries in parallel, one for the A
    record and the other for the AAAA record.  If one of these is a
    referral, then the query fails, which is wrong.  It should return at
    least the one successful response.

    The fix has two parts.  The first part makes the referral fall back to
    the SERVFAIL path, which results in using the successful response.
    There is a bug in that path however, due to which the second part is
    necessary.  The bug here is that if the first response is a failure
    and the second succeeds, __libc_res_nsearch does not detect that and
    assumes a failure.  The case where the first response is a success and
    the second fails, works correctly.

    This condition is produced by buggy routers, so here's a crude
    interposable library that can simulate such a condition.  The library
    overrides the recvfrom syscall and modifies the header of the packet
    received to reproduce this scenario.  It has two key variables:
    mod_packet and first_error.

    The mod_packet variable when set to 0, results in odd packets being
    modified to be a referral.  When set to 1, even packets are modified
    to be a referral.

    The first_error causes the first response to be a failure so that a
    domain-appended search is performed to test the second part of the
    __libc_nsearch fix.

    The driver for this fix is a simple getaddrinfo program that does an
    AF_UNSPEC query.  I have omitted this since it should be easy to
    implement.

    I have tested this on x86_64.

    The interceptor library source:

    /* Override recvfrom and modify the header of the first DNS response to
make it
       a referral and reproduce bz #845218.  We have to resort to this ugly
hack
       because we cannot make bind return the buggy response of a referral for
the
       AAAA record and an authoritative response for the A record.  */
     #define _GNU_SOURCE
     #include <sys/types.h>
     #include <sys/socket.h>
     #include <netinet/in.h>
     #include <arpa/inet.h>
     #include <stdio.h>
     #include <stdbool.h>
     #include <endian.h>
     #include <dlfcn.h>
     #include <stdlib.h>

    /* Lifted from resolv/arpa/nameser_compat.h.  */
    typedef struct {
        unsigned        id :16;         /*%< query identification number */
     #if BYTE_ORDER == BIG_ENDIAN
        /* fields in third byte */
        unsigned        qr: 1;          /*%< response flag */
        unsigned        opcode: 4;      /*%< purpose of message */
        unsigned        aa: 1;          /*%< authoritive answer */
        unsigned        tc: 1;          /*%< truncated message */
        unsigned        rd: 1;          /*%< recursion desired */
        /* fields
         * in
         * fourth
         * byte
         * */
        unsigned        ra: 1;          /*%< recursion available */
        unsigned        unused :1;      /*%< unused bits (MBZ as of 4.9.3a3) */
        unsigned        ad: 1;          /*%< authentic data from named */
        unsigned        cd: 1;          /*%< checking disabled by resolver */
        unsigned        rcode :4;       /*%< response code */
     #endif
     #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
        /* fields
         * in
         * third
         * byte
         * */
        unsigned        rd :1;          /*%< recursion desired */
        unsigned        tc :1;          /*%< truncated message */
        unsigned        aa :1;          /*%< authoritive answer */
        unsigned        opcode :4;      /*%< purpose of message */
        unsigned        qr :1;          /*%< response flag */
        /* fields
         * in
         * fourth
         * byte
         * */
        unsigned        rcode :4;       /*%< response code */
        unsigned        cd: 1;          /*%< checking disabled by resolver */
        unsigned        ad: 1;          /*%< authentic data from named */
        unsigned        unused :1;      /*%< unused bits (MBZ as of 4.9.3a3) */
        unsigned        ra :1;          /*%< recursion available */
     #endif
        /* remaining
         * bytes
         * */
        unsigned        qdcount :16;    /*%< number of question entries */
        unsigned        ancount :16;    /*%< number of answer entries */
        unsigned        nscount :16;    /*%< number of authority entries */
        unsigned        arcount :16;    /*%< number of resource entries */
    } HEADER;

    static int done = 0;

    /* Packets to modify.  0 for the odd packets and 1 for even packets.  */
    static const int mod_packet = 0;

    /* Set to true if the first request should result in an error, resulting in
a
       search query.  */
    static bool first_error = true;

    static ssize_t (*real_recvfrom) (int sockfd, void *buf, size_t len, int
flags,
                  struct sockaddr *src_addr, socklen_t *addrlen);

    void
    __attribute__ ((constructor))
    init (void)
    {
      real_recvfrom = dlsym (RTLD_NEXT, "recvfrom");

      if (real_recvfrom == NULL)
        {
          printf ("Failed to get reference to recvfrom: %s\n", dlerror ());
          printf ("Cannot simulate test\n");
          abort ();
        }
    }

    /* Modify the second packet that we receive to set the header in a manner
as to
       reproduce BZ #845218.  */
    static void
    mod_buf (HEADER *h, int port)
    {
      if (done % 2 == mod_packet || (first_error && done == 1))
        {
          printf ("(Modifying header)");

          if (first_error && done == 1)
        h->rcode = 3;
          else
        h->rcode = 0;    /* NOERROR == 0.  */
          h->ancount = 0;
          h->aa = 0;
          h->ra = 0;
          h->arcount = 0;
        }
      done++;
    }

    ssize_t
    recvfrom (int sockfd, void *buf, size_t len, int flags,
          struct sockaddr *src_addr, socklen_t *addrlen)
    {
      ssize_t ret = real_recvfrom (sockfd, buf, len, flags, src_addr, addrlen);
      int port = htons (((struct sockaddr_in *) src_addr)->sin_port);
      struct in_addr addr = ((struct sockaddr_in *) src_addr)->sin_addr;
      const char *host = inet_ntoa (addr);
      printf ("\n*** From %s:%d: ", host, port);

      mod_buf (buf, port);

      printf ("returned %zd\n", ret);
      return ret;
    }

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog          |   11 +++++++++++
 NEWS               |   14 +++++++-------
 resolv/res_query.c |    7 +++++--
 resolv/res_send.c  |    2 +-
 4 files changed, 24 insertions(+), 10 deletions(-)

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


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Bug network/12994] getaddrinfo fails if response records returned in wrong order and one of them is server failure
  2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
                   ` (18 preceding siblings ...)
  2014-04-30  6:38 ` siddhesh at redhat dot com
@ 2014-06-27 12:55 ` fweimer at redhat dot com
  19 siblings, 0 replies; 21+ messages in thread
From: fweimer at redhat dot com @ 2014-06-27 12:55 UTC (permalink / raw)
  To: glibc-bugs

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

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
              Flags|                            |security-

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


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2014-06-27 12:55 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-13  4:24 [Bug libc/12994] New: getaddrinfo fails if response records returned in wrong order and one of them is server failure jik at kamens dot us
2011-07-13  4:24 ` [Bug libc/12994] " jik at kamens dot us
2011-07-13  4:25 ` jik at kamens dot us
2011-07-14  0:50 ` ppluzhnikov at google dot com
2011-07-16  5:33 ` nick.jones@network-box.com
2011-12-10  8:32 ` oliverml1 at oli1170 dot net
2012-02-21  2:17 ` [Bug network/12994] " jsm28 at gcc dot gnu.org
2012-11-02  1:22 ` jrnieder at gmail dot com
2012-11-03 17:01 ` karme at karme dot de
2012-11-04 10:49 ` karme at karme dot de
2012-11-04 10:53 ` karme at karme dot de
2012-11-06 11:49 ` karme at karme dot de
2012-11-06 13:22 ` law at redhat dot com
2012-11-07 17:33 ` karme at karme dot de
2012-11-27 12:02 ` karme at karme dot de
2012-11-27 16:52 ` law at redhat dot com
2012-12-16 15:55 ` psimerda at redhat dot com
2014-04-16  7:34 ` siddhesh at redhat dot com
2014-04-16  9:11 ` siddhesh at redhat dot com
2014-04-30  6:38 ` siddhesh at redhat dot com
2014-06-27 12:55 ` fweimer at redhat dot com

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).