Ran across an exploit for glibc today which involves the getaddrinfo() call for DNS resolution. I'm running Ubuntu 12.04 on two Bind9 boxes that face the internet. I'm not sure I totally understand the exploit, but it seems to be caused by a large reply from a malicous DNS server. One of the mitigations is a "firewall that drops UDP DNS packets > 512 bytes" so I've configured netfilter on the DNS servers to drop any UDP > 512 bytes coming from, or going to, port 53:
-A INPUT -i lo -j ACCEPT
-A INPUT -p udp --sport 53 -m length --length 511:65535 -j DROP
-A INPUT -p udp --dport 53 -m length --length 511:65535 -j DROP
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
Is there a better way to do this with a Bind setting or anything? I've tested the rule with scapy and it does indeed block a UDP packet > 512 tossed at port 53.
UPDATED per responses:
-A INPUT -i lo -j ACCEPT
-A INPUT -p udp --sport 53 -m length --length 949:65535 -j DROP
-A INPUT -p udp --dport 53 -m length --length 949:65535 -j DROP
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
and /etc/bind/named.conf.options
options {
...
// 2016-02-17 - tmb - glibc exploit mitigation
edns-udp-size 900 ;
max-udp-size 900 ;
};
UPDATE 2: As pointed out by atdre below, Cloudflare tried the above technique and although the entire payload could not be transferred, memory corruption was still a possibility. I think I'll look into Unbound.