Skip to content

Commit d8cd67b

Browse files
committed
Make the negcache forwarded zones aware
Because of DNSSEC (without NTAs configured), we 'leak' the forwarded name to the cache when looking for the DNSKEY. This resulted in NXDOMAIN answers for actual NXDOMAINs, but with the root SOA record. Leading to inconsistent answers to the client.
1 parent 0dbcd62 commit d8cd67b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pdns/syncres.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,13 @@ bool SyncRes::doCacheCheck(const DNSName &qname, const QType &qtype, vector<DNSR
758758
pair<negcache_t::const_iterator, negcache_t::const_iterator> range;
759759
QType qtnull(0);
760760

761+
DNSName authname(qname);
762+
bool wasForwardedOrAuth = (getBestAuthZone(&authname) != t_sstorage->domainmap->end());
763+
761764
if(s_rootNXTrust &&
762765
(range.first=t_sstorage->negcache.find(tie(getLastLabel(qname), qtnull))) != t_sstorage->negcache.end() &&
763-
range.first->d_qname.isRoot() && (uint32_t)d_now.tv_sec < range.first->d_ttd ) {
766+
!(wasForwardedOrAuth && !authname.isRoot()) && // when forwarding, the root may only neg-cache if it was forwarded to.
767+
range.first->d_qname.isRoot() && (uint32_t)d_now.tv_sec < range.first->d_ttd) {
764768
sttl=range.first->d_ttd - d_now.tv_sec;
765769

766770
LOG(prefix<<qname<<": Entire name '"<<qname<<"', is negatively cached via '"<<range.first->d_name<<"' & '"<<range.first->d_qname<<"' for another "<<sttl<<" seconds"<<endl);
@@ -776,7 +780,8 @@ bool SyncRes::doCacheCheck(const DNSName &qname, const QType &qtype, vector<DNSR
776780
negcache_t::iterator ni;
777781
for(ni=range.first; ni != range.second; ni++) {
778782
// we have something
779-
if(ni->d_qtype.getCode() == 0 || ni->d_qtype == qtype) {
783+
if(!(wasForwardedOrAuth && ni->d_qname != authname) && // Only the authname nameserver can neg cache entries
784+
(ni->d_qtype.getCode() == 0 || ni->d_qtype == qtype)) {
780785
res=0;
781786
if((uint32_t)d_now.tv_sec < ni->d_ttd) {
782787
sttl=ni->d_ttd - d_now.tv_sec;

0 commit comments

Comments
 (0)