2. Recursion Bugs
When a server receives a client request, it first looks up its zone data and the cache to check if the query can be answered. If the answer is unavailable in either place, the server seeks names of servers that are more likely to have the information, in its cache or zone data. It then does one of two things. If the client desires the server to recurse and the server architecture allows recursion, the server chains this request to these known servers closest to the queried name. If the client doesn't seek recursion or if the server cannot handle recursion, it returns the list of name servers to the client assuming the client knows what to do with these records.
The client queries this new list of name servers to get either the answer, or names of another set of name servers to query. This process repeats until the client is satisfied. Servers might also go through this chaining process if the server returns a CNAME record for the queried name. Some servers reprocess this name to try and get the desired record type.
However, in certain cases, this chain of events may not be good. For example, a broken or malicious name server might list itself as one of the name servers to query again. The unsuspecting client resends the same query to the same server.
In another situation, more difficult to detect, a set of servers might form a loop wherein A refers to B and B refers to A. This loop might involve more than two servers.
Yet another error is where the client does not know how to process the list of name servers returned, and requeries the same server since that is one (of the few) servers it knows.
We, therefore, classify recursion bugs into three distinct categories:
-
a. Ignored referral: Client did not know how to handle NS records in the AUTHORITY section.
-
b. Too many referrals: Client called on a server too many times, beyond a "reasonable" number, with same query. This is different from a Fast retransmission problem and a Server Failure detection problem in that a response is seen for every query. Also, the identifiers are always different. It implies client is in a loop and should have detected that and broken it. (RFC 1035 mentions that client should not recurse beyond a certain depth.)
-
c. Malicious Server: a server refers to itself in the authority section. If a server does not have an answer now, it is very unlikely it will be any better the next time you query it, specially when it claims to be authoritative over a domain.
RFC 1034 warns against such situations, on page 35.
"Bound the amount of work (packets sent, parallel processes started) so that a request can't get into an infinite loop or start off a chain reaction of requests or queries with other implementations EVEN IF SOMEONE HAS INCORRECTLY CONFIGURED SOME DATA."
A Good Implementation
BIND fixes at least one of these problems. It places an upper limit on the number of recursive queries it will make, to answer a question. It chases a maximum of 20 referral links and 8 canonical name translations.
Fixes
- a. Set an upper limit on the number of referral links and CNAME links you are willing to chase.
Note that this is not guaranteed to break only recursion loops. It could, in a rare case, prune off a very long search path, prematurely. We know, however, with high probability, that if the number of links cross a certain metric (two times the depth of the DNS tree), it is a recursion problem.
-
b. Watch out for self-referring servers. Avoid them whenever possible.
-
c. Make sure you never pass off an authority NS record with your own name on it!
-
d. Fix clients to accept iterative answers from servers not built to provide recursion. Such clients should either be happy with the non-authoritative answer or be willing to chase the referral links themselves.