From 1ddb1cd440aa2fd9ec95d416cd8ec7572f763251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Thu, 5 Oct 2017 09:42:31 +0200 Subject: [PATCH] [v9_10] Prevent dig INSIST failures and hangs in some failure modes 4756. [bug] Interrupting dig could lead to an INSIST failure after certain errors were encountered while querying a host whose name resolved to more than one address. Change 4537 increased the odds of triggering this issue by causing dig to hang indefinitely when certain error paths were evaluated. dig now also retries TCP queries (once) if the server gracefully closes the connection before sending a response. [RT #42832, #45159] (cherry picked from commit b1ce9b3d54cd072adb5275f08a9afac31cfb4c1c) --- CHANGES | 9 +++++++++ bin/dig/dighost.c | 20 +++++++++++++++++++- bin/dig/include/dig/dig.h | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 74b1dfe36f..fd7f8a1651 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,12 @@ +4756. [bug] Interrupting dig could lead to an INSIST failure after + certain errors were encountered while querying a host + whose name resolved to more than one address. Change + 4537 increased the odds of triggering this issue by + causing dig to hang indefinitely when certain error + paths were evaluated. dig now also retries TCP queries + (once) if the server gracefully closes the connection + before sending a response. [RT #42832, #45159] + 4754. [bug] dns_zone_setview needs a two stage commit to properly handle errors. [RT #45841] diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 218399d052..bd1be0041f 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -862,6 +862,7 @@ make_empty_lookup(void) { looknew->ednsopts = NULL; looknew->ednsoptscnt = 0; looknew->ednsneg = ISC_FALSE; + looknew->eoferr = 0; dns_fixedname_init(&looknew->fdomain); ISC_LINK_INIT(looknew, link); ISC_LIST_INIT(looknew->q); @@ -952,6 +953,7 @@ clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers) { looknew->tsigctx = NULL; looknew->need_search = lookold->need_search; looknew->done_as_is = lookold->done_as_is; + looknew->eoferr = lookold->eoferr; if (lookold->ecs_addr != NULL) { size_t len = sizeof(isc_sockaddr_t); @@ -3143,7 +3145,7 @@ tcp_length_done(isc_task_t *task, isc_event_t *event) { isc_buffer_t *b = NULL; isc_result_t result; dig_query_t *query = NULL; - dig_lookup_t *l; + dig_lookup_t *l, *n; isc_uint16_t length; REQUIRE(event->ev_type == ISC_SOCKEVENT_RECVDONE); @@ -3178,13 +3180,20 @@ tcp_length_done(isc_task_t *task, isc_event_t *event) { sizeof(sockstr)); printf(";; communications error to %s: %s\n", sockstr, isc_result_totext(sevent->result)); + if (keep != NULL) + isc_socket_detach(&keep); l = query->lookup; isc_socket_detach(&query->sock); sockcount--; debug("sockcount=%d", sockcount); INSIST(sockcount >= 0); + if (sevent->result == ISC_R_EOF && l->eoferr == 0U) { + n = requeue_lookup(l, ISC_TRUE); + n->eoferr++; + } isc_event_free(&event); clear_query(query); + cancel_lookup(l); check_next_lookup(l); UNLOCK_LOOKUP; return; @@ -3692,13 +3701,20 @@ recv_done(isc_task_t *task, isc_event_t *event) { } else { printf(";; communications error: %s\n", isc_result_totext(sevent->result)); + if (keep != NULL) + isc_socket_detach(&keep); isc_socket_detach(&query->sock); sockcount--; debug("sockcount=%d", sockcount); INSIST(sockcount >= 0); } + if (sevent->result == ISC_R_EOF && l->eoferr == 0U) { + n = requeue_lookup(l, ISC_TRUE); + n->eoferr++; + } isc_event_free(&event); clear_query(query); + cancel_lookup(l); check_next_lookup(l); UNLOCK_LOOKUP; return; @@ -3760,6 +3776,7 @@ recv_done(isc_task_t *task, isc_event_t *event) { if (fail) { isc_event_free(&event); clear_query(query); + cancel_lookup(l); check_next_lookup(l); UNLOCK_LOOKUP; return; @@ -3871,6 +3888,7 @@ recv_done(isc_task_t *task, isc_event_t *event) { if (l->tcp_mode) { isc_event_free(&event); clear_query(query); + cancel_lookup(l); check_next_lookup(l); UNLOCK_LOOKUP; return; diff --git a/bin/dig/include/dig/dig.h b/bin/dig/include/dig/dig.h index 835c902990..2ad0769d6a 100644 --- a/bin/dig/include/dig/dig.h +++ b/bin/dig/include/dig/dig.h @@ -197,6 +197,7 @@ isc_boolean_t sigchase; unsigned int ednsoptscnt; unsigned int ednsflags; dns_opcode_t opcode; + unsigned int eoferr; }; /*% The dig_query structure */