Skip to content

Commit 28b66a9

Browse files
committed
limit the number of NSEC3 iterations RFC5155 10.3
1 parent da642b7 commit 28b66a9

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

pdns/common_startup.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ void declareArguments()
159159
::arg().set("default-ksk-size","Default KSK size (0 means default)")="0";
160160
::arg().set("default-zsk-algorithms","Default ZSK algorithms")="rsasha256";
161161
::arg().set("default-zsk-size","Default ZSK size (0 means default)")="0";
162+
::arg().set("max-nsec3-iterations","Limit the number of NSEC3 hash iterations")="500"; // RFC5155 10.3
162163

163164
::arg().set("include-dir","Include *.conf files from this directory");
164165
}

pdns/dbdnsseckeeper.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,16 @@ bool DNSSECKeeper::getNSEC3PARAM(const std::string& zname, NSEC3PARAMRecordConte
233233
if(value.empty()) { // "no NSEC3"
234234
return false;
235235
}
236-
236+
237+
static int maxNSEC3Iterations=::arg().asNum("max-nsec3-iterations");
237238
if(ns3p) {
238239
NSEC3PARAMRecordContent* tmp=dynamic_cast<NSEC3PARAMRecordContent*>(DNSRecordContent::mastermake(QType::NSEC3PARAM, 1, value));
239240
*ns3p = *tmp;
240241
delete tmp;
242+
if (ns3p->d_iterations > maxNSEC3Iterations) {
243+
ns3p->d_iterations = maxNSEC3Iterations;
244+
L<<Logger::Error<<"Number of NSEC3 iterations for zone '"<<zname<<"' is above 'max-nsec3-iterations'. Value adjusted to: "<<maxNSEC3Iterations<<endl;
245+
}
241246
}
242247
if(narrow) {
243248
getFromMeta(zname, "NSEC3NARROW", value);
@@ -248,6 +253,10 @@ bool DNSSECKeeper::getNSEC3PARAM(const std::string& zname, NSEC3PARAMRecordConte
248253

249254
bool DNSSECKeeper::setNSEC3PARAM(const std::string& zname, const NSEC3PARAMRecordContent& ns3p, const bool& narrow)
250255
{
256+
static int maxNSEC3Iterations=::arg().asNum("max-nsec3-iterations");
257+
if (ns3p.d_iterations > maxNSEC3Iterations)
258+
throw runtime_error("Can't set NSEC3PARAM for zone '"+zname+"': number of NSEC3 iterations is above 'max-nsec3-iterations'");
259+
251260
clearCaches(zname);
252261
string descr = ns3p.getZoneRepresentation();
253262
vector<string> meta;

pdns/pdns.conf-dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@
264264
#
265265
# max-ent-entries=100000
266266

267+
#################################
268+
# max-nsec3-iterations Limit the number of NSEC3 hash iterations
269+
#
270+
# max-nsec3-iterations=500
271+
267272
#################################
268273
# max-queue-length Maximum queuelength before considering situation lost
269274
#

pdns/pdnssec.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ void loadMainConfig(const std::string& configdir)
137137
::arg().set("entropy-source", "If set, read entropy from this file")="/dev/urandom";
138138

139139
::arg().setSwitch("direct-dnskey","Fetch DNSKEY RRs from backend during DNSKEY synthesis")="no";
140+
::arg().set("max-nsec3-iterations","Limit the number of NSEC3 hash iterations")="500"; // RFC5155 10.3
140141
::arg().laxFile(configname.c_str());
141142

142143
BackendMakers().launch(::arg()["launch"]); // vrooooom!

pdns/rfc2136handler.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,11 @@ int PacketHandler::processUpdate(DNSPacket *p) {
921921
di.backend->abortTransaction();
922922
return RCode::ServFail;
923923
}
924+
catch(std::exception &e) {
925+
L<<Logger::Error<<msgPrefix<<"Caught std:exception: "<<e.what()<<"; Sending ServFail!"<<endl;
926+
di.backend->abortTransaction();
927+
return RCode::ServFail;
928+
}
924929
catch (...) {
925930
L<<Logger::Error<<msgPrefix<<"Caught unknown exception when performing update. Sending ServFail!"<<endl;
926931
di.backend->abortTransaction();

0 commit comments

Comments
 (0)