Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#5014] IOOBE in DefaultDnsRecordDecoder#decodeName #5015

Closed
wants to merge 1 commit into from

Conversation

rkapsi
Copy link
Member

@rkapsi rkapsi commented Mar 22, 2016

This PR demonstrates the IOOBE as described in #5014.

@normanmaurer
Copy link
Member

@rkapsi will have a look. Thanks!

@normanmaurer normanmaurer self-assigned this Mar 22, 2016
@normanmaurer
Copy link
Member

@rkapsi what dns server you are using for the test ?

@normanmaurer
Copy link
Member

@rkapsi asking as it works here ... Maybe can you also show me your /etc/hosts ?

@rkapsi
Copy link
Member Author

rkapsi commented Mar 22, 2016

@normanmaurer Interesting. I'm using DnsNameResolver's defaults. When I set it explicitly to Google's DNS or let's say Level 3's it's working fine. When I use Squarespace's corp DNS then it doesn't and it seems this Unit Test triggered the exact same Exception on netty.io's TeamCity's CI box.

@normanmaurer
Copy link
Member

@rkapsi can you just do a dig and show me what your dns return ?

@rkapsi
Copy link
Member Author

rkapsi commented Mar 22, 2016

$ dig -x 127.0.0.1

; <<>> DiG 9.10.3-P4 <<>> -x 127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62490
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 3

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;1.0.0.127.in-addr.arpa.        IN  PTR

;; ANSWER SECTION:
1.0.0.127.in-addr.arpa. 86400   IN  PTR localhost.

;; AUTHORITY SECTION:
1.0.0.127.in-addr.arpa. 86400   IN  NS  1.0.0.127.in-addr.arpa.

;; ADDITIONAL SECTION:
1.0.0.127.in-addr.arpa. 86400   IN  A   127.0.0.1
1.0.0.127.in-addr.arpa. 86400   IN  AAAA    ::1

;; Query time: 5 msec
;; SERVER: 10.0.10.253#53(10.0.10.253)
;; WHEN: Tue Mar 22 11:55:07 EDT 2016
;; MSG SIZE  rcvd: 132

@rkapsi
Copy link
Member Author

rkapsi commented Mar 22, 2016

Btw. I was using 127.0.0.1 as an example. I'm getting the same error with something like 1.64.249.66.in-addr.arpa (66.249.64.1/googlebot.com).

@normanmaurer
Copy link
Member

@rkapsi can you give me the output against your dns and against the google one so I can see the diff between these ?

@rkapsi
Copy link
Member Author

rkapsi commented Mar 22, 2016

Google DNS
$ dig @8.8.8.8 -x 127.0.0.1

; <<>> DiG 9.10.3-P4 <<>> @8.8.8.8 -x 127.0.0.1
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 45792
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;1.0.0.127.in-addr.arpa.        IN  PTR

;; AUTHORITY SECTION:
in-addr.arpa.       260 IN  SOA b.in-addr-servers.arpa. nstld.iana.org. 2015073208 1800 900 604800 3600

;; Query time: 1 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Tue Mar 22 11:59:32 EDT 2016
;; MSG SIZE  rcvd: 119
Corp DNS
$ dig @10.8.64.253 -x 127.0.0.1

; <<>> DiG 9.10.3-P4 <<>> @10.8.64.253 -x 127.0.0.1
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51452
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 3

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;1.0.0.127.in-addr.arpa.        IN  PTR

;; ANSWER SECTION:
1.0.0.127.in-addr.arpa. 86400   IN  PTR localhost.

;; AUTHORITY SECTION:
1.0.0.127.in-addr.arpa. 86400   IN  NS  1.0.0.127.in-addr.arpa.

;; ADDITIONAL SECTION:
1.0.0.127.in-addr.arpa. 86400   IN  A   127.0.0.1
1.0.0.127.in-addr.arpa. 86400   IN  AAAA    ::1

;; Query time: 0 msec
;; SERVER: 10.8.64.253#53(10.8.64.253)
;; WHEN: Tue Mar 22 12:00:14 EDT 2016
;; MSG SIZE  rcvd: 132
Google DNS
$ dig @8.8.8.8 -x 66.249.64.1

; <<>> DiG 9.10.3-P4 <<>> @8.8.8.8 -x 66.249.64.1
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6172
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;1.64.249.66.in-addr.arpa.  IN  PTR

;; ANSWER SECTION:
1.64.249.66.in-addr.arpa. 21599 IN  PTR crawl-66-249-64-1.googlebot.com.

;; Query time: 52 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Tue Mar 22 12:00:58 EDT 2016
;; MSG SIZE  rcvd: 98
Corp DNS
$ dig @10.8.64.253 -x 66.249.64.1

; <<>> DiG 9.10.3-P4 <<>> @10.8.64.253 -x 66.249.64.1
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12135
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 6, ADDITIONAL: 13

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;1.64.249.66.in-addr.arpa.  IN  PTR

;; ANSWER SECTION:
1.64.249.66.in-addr.arpa. 21565 IN  PTR crawl-66-249-64-1.googlebot.com.

;; AUTHORITY SECTION:
in-addr.arpa.       51609   IN  NS  c.in-addr-servers.arpa.
in-addr.arpa.       51609   IN  NS  a.in-addr-servers.arpa.
in-addr.arpa.       51609   IN  NS  e.in-addr-servers.arpa.
in-addr.arpa.       51609   IN  NS  d.in-addr-servers.arpa.
in-addr.arpa.       51609   IN  NS  f.in-addr-servers.arpa.
in-addr.arpa.       51609   IN  NS  b.in-addr-servers.arpa.

;; ADDITIONAL SECTION:
a.in-addr-servers.arpa. 51609   IN  A   199.212.0.73
a.in-addr-servers.arpa. 51609   IN  AAAA    2001:500:13::73
e.in-addr-servers.arpa. 51609   IN  A   203.119.86.101
e.in-addr-servers.arpa. 51609   IN  AAAA    2001:dd8:6::101
c.in-addr-servers.arpa. 51609   IN  A   196.216.169.10
c.in-addr-servers.arpa. 51609   IN  AAAA    2001:43f8:110::10
f.in-addr-servers.arpa. 51609   IN  A   193.0.9.1
f.in-addr-servers.arpa. 51609   IN  AAAA    2001:67c:e0::1
b.in-addr-servers.arpa. 51609   IN  A   199.253.183.183
b.in-addr-servers.arpa. 51609   IN  AAAA    2001:500:87::87
d.in-addr-servers.arpa. 51609   IN  A   200.10.60.53
d.in-addr-servers.arpa. 51609   IN  AAAA    2001:13c7:7010::53

;; Query time: 0 msec
;; SERVER: 10.8.64.253#53(10.8.64.253)
;; WHEN: Tue Mar 22 12:01:24 EDT 2016
;; MSG SIZE  rcvd: 474

@rkapsi
Copy link
Member Author

rkapsi commented Mar 22, 2016

Interesting. The 127.0.0.1 lookup is potentially misleading. Using 1.64.249.66.in-addr.arpa (66.249.64.1/googlebot.com) with Google DNS triggers it for me.

public class ReverseDnsQueryTest {

    @Test
    public void rdns() throws Exception {
        NioEventLoopGroup group = new NioEventLoopGroup();
        DnsNameResolver resolver = new DnsNameResolverBuilder(group.next())
            .channelType(NioDatagramChannel.class)
            .nameServerAddresses(DnsServerAddresses.sequential(
                new InetSocketAddress("8.8.8.8", 53)))
            .build();

        try {
          String name = "1.64.249.66.in-addr.arpa";
          DnsQuestion question = new DefaultDnsQuestion(name, DnsRecordType.PTR);

          resolver.query(question).get();
        } finally {
            resolver.close();
            group.shutdownGracefully();
        }
    }
}

@normanmaurer
Copy link
Member

@rkapsi I will need to dig a bit deeper into the RFC I guess . I mean I know how to work around this but I'm not sure it is the correct thing to do in this case.

@normanmaurer
Copy link
Member

@rkapsi in the meantime you can use .optResourceEnabled(false) on the builder to have it work.

@rkapsi
Copy link
Member Author

rkapsi commented Mar 22, 2016

@normanmaurer the .optResourceEnabled(false) flag works with Google DNS but not with our Corp DNS (bind 9.9.4). I'm not familiar with DNS internals to be of much use but I've captured the DNS response with Wireshark and have created a simple repro. I can email you the byte[] if you like (repro code is below).

@Test
    public void wireshark() throws Exception {

      DatagramDnsResponseDecoder decoder = new DatagramDnsResponseDecoder();

      ByteBuf response = response("/home/rkapsi/ioobe-5015/response");

      DatagramPacket packet = new DatagramPacket(
          response, new InetSocketAddress("localhost", 53));

      ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
      decoder.channelRead(ctx, packet);
    }

    private static ByteBuf response(String path) throws IOException {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();

      FileInputStream in = new FileInputStream(path);
      try {
        byte[] buf = new byte[4*1024];
        int len = -1;
        while ((len = in.read(buf)) != -1) {
          baos.write(buf, 0, len);
        }
      } finally {
        in.close();
      }

      return Unpooled.wrappedBuffer(baos.toByteArray());
    }

@normanmaurer
Copy link
Member

@rkapsi sure why not... norman dot maurer at googlemail dot com .

@normanmaurer
Copy link
Member

@rkapsi thanks again for the code to test this. Fixed by #5017

@normanmaurer normanmaurer added this to the 4.1.0.Final milestone Mar 24, 2016
@rkapsi rkapsi deleted the rkapsi/5014-ioobe branch March 28, 2016 13:51
@normanmaurer normanmaurer modified the milestones: 4.1.0.Final, 4.1.0.CR5 Mar 29, 2016
@rkapsi rkapsi restored the rkapsi/5014-ioobe branch March 30, 2016 12:27
@rkapsi rkapsi deleted the rkapsi/5014-ioobe branch March 30, 2016 12:28
@normanmaurer
Copy link
Member

@rkapsi I know its been a while but do you bay any chance still have "/home/rkapsi/ioobe-5015/response" somewhere ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants