]> git.ipfire.org Git - thirdparty/bind9.git/commit
Fix handling of mismatched responses past timeout
authorMichał Kępień <michal@isc.org>
Tue, 23 Nov 2021 14:35:39 +0000 (15:35 +0100)
committerMichał Kępień <michal@isc.org>
Tue, 23 Nov 2021 14:35:39 +0000 (15:35 +0100)
commit8f8a69aa0aef26da487296d443a572a5fa107ee9
treefcd878f8a9fc49d916270377be7ef0d0eeb970a6
parent87acddd760c9b633481301e28a9145542525b934
Fix handling of mismatched responses past timeout

When a UDP dispatch receives a mismatched response, it checks whether
there is still enough time to wait for the correct one to arrive before
the timeout fires.  If there is not, the result code is set to
ISC_R_TIMEDOUT, but it is not subsequently used anywhere as 'response'
is set to NULL a few lines earlier.  This results in the higher-level
read callback (resquery_response() in case of resolver code) not being
called.  However, shortly afterwards, a few levels up the call chain,
isc__nm_udp_read_cb() calls isc__nmsocket_timer_stop() on the dispatch
socket, effectively disabling read timeout handling for that socket.
Combined with the fact that reading is not restarted in such a case
(e.g. by calling dispatch_getnext() from udp_recv()), this leads to the
higher-level query structure remaining referenced indefinitely because
the dispatch socket it uses will neither be read from nor closed due to
a timeout.  This in turn causes fetch contexts to linger around
indefinitely, which in turn i.a. prevents certain cache nodes (those
containing rdatasets used by fetch contexts, like fctx->nameservers)
from being cleaned.

Fix by making sure the higher-level callback does get invoked with the
ISC_R_TIMEDOUT result code when udp_recv() determines there is no more
time left to receive the correct UDP response before the timeout fires.
This allows the higher-level callback to clean things up, preventing the
reference leak described above.
lib/dns/dispatch.c