]> git.ipfire.org Git - thirdparty/bind9.git/commit
Improve RBT overmem cache cleaning
authorOndřej Surý <ondrej@isc.org>
Tue, 30 May 2023 06:46:17 +0000 (08:46 +0200)
committerMichal Nowak <mnowak@isc.org>
Thu, 8 Jun 2023 09:43:18 +0000 (11:43 +0200)
commite9d5219fca9f6b819d953990b369d6acfb4e952b
tree3d0ed7eb045bc9a4b7420450c84764285d87a675
parent36d019ffce55818142a819515278462d13bdf2c9
Improve RBT overmem cache cleaning

When cache memory usage is over the configured cache size (overmem) and
we are cleaning unused entries, it might not be enough to clean just two
entries if the entries to be expired are smaller than the newly added
rdata.  This could be abused by an attacker to cause a remote Denial of
Service by possibly running out of the operating system memory.

Currently, the addrdataset() tries to do a single TTL-based cleaning
considering the serve-stale TTL and then optionally moves to overmem
cleaning if we are in that condition.  Then the overmem_purge() tries to
do another single TTL based cleaning from the TTL heap and then continue
with LRU-based cleaning up to 2 entries cleaned.

Squash the TTL-cleaning mechanism into single call from addrdataset(),
but ignore the serve-stale TTL if we are currently overmem.

Then instead of having a fixed number of entries to clean, pass the size
of newly added rdatasetheader to the overmem_purge() function and
cleanup at least the size of the newly added data.  This prevents the
cache going over the configured memory limit (`max-cache-size`).

Additionally, refactor the overmem_purge() function to reduce for-loop
nesting for readability.
lib/dns/rbtdb.c