From b0707ebba0e5364866d4764ef940ad7a2c7d8052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Kr=C4=99cicki?= Date: Thu, 21 May 2020 14:31:09 +0200 Subject: [PATCH 1/3] Fix a data access race in resolver We were passing client address to dns_resolver_createfetch as a pointer and it was saved as a pointer. The client (with its address) could be gone before the fetch is finished, and in a very odd scenario log_formerr would call isc_sockaddr_format() which first checks if the address family is valid (and at this point it still is), then the sockaddr is cleared, and then isc_netaddr_fromsockaddr is called which fails an assertion as the address family is now invalid. (cherry picked from commit 175c4d905567a841c0f76704ebc126ee9268ecd7) --- lib/dns/resolver.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index bb23870449..ecb3ddb4dc 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -378,8 +378,8 @@ struct fetchctx { unsigned int valfail; bool timeout; dns_adbaddrinfo_t *addrinfo; - const isc_sockaddr_t *client; unsigned int depth; + char clientstr[ISC_SOCKADDR_FORMATSIZE]; }; #define FCTX_MAGIC ISC_MAGIC('F', '!', '!', '!') @@ -4409,7 +4409,12 @@ fctx_create(dns_resolver_t *res, dns_name_t *name, dns_rdatatype_t type, fctx->rand_bits = 0; fctx->timeout = false; fctx->addrinfo = NULL; - fctx->client = client; + if (client != NULL) { + isc_sockaddr_format(client, fctx->clientstr, + sizeof(fctx->clientstr)); + } else { + strlcpy(fctx->clientstr, "", sizeof(fctx->clientstr)); + } fctx->ns_ttl = 0; fctx->ns_ttl_ok = false; @@ -4670,8 +4675,6 @@ log_lame(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo) { static inline void log_formerr(fetchctx_t *fctx, const char *format, ...) { char nsbuf[ISC_SOCKADDR_FORMATSIZE]; - char clbuf[ISC_SOCKADDR_FORMATSIZE]; - const char *clmsg = ""; char msgbuf[2048]; va_list args; @@ -4681,17 +4684,10 @@ log_formerr(fetchctx_t *fctx, const char *format, ...) { isc_sockaddr_format(&fctx->addrinfo->sockaddr, nsbuf, sizeof(nsbuf)); - if (fctx->client != NULL) { - clmsg = " for client "; - isc_sockaddr_format(fctx->client, clbuf, sizeof(clbuf)); - } else { - clbuf[0] = '\0'; - } - isc_log_write(dns_lctx, DNS_LOGCATEGORY_RESOLVER, DNS_LOGMODULE_RESOLVER, ISC_LOG_NOTICE, - "DNS format error from %s resolving %s%s%s: %s", - nsbuf, fctx->info, clmsg, clbuf, msgbuf); + "DNS format error from %s resolving %s for %s: %s", + nsbuf, fctx->info, fctx->clientstr, msgbuf); } static isc_result_t From 530c04c33a15e7deed74edf4e0ee39d6648ba6c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Kr=C4=99cicki?= Date: Thu, 21 May 2020 14:31:09 +0200 Subject: [PATCH 2/3] Add CHANGES entry for #1808 (cherry picked from commit f0f859411f95bc7957a4e1d01acca3e3cc491263) --- CHANGES | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES b/CHANGES index 1f800de914..3a63e2921c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ +5437. [bug] Fix a data race in resolver log_formerr. [GL #1808] + 5433. [test] Resolver system test for change #5395 (max-recursion-queries) failed on system without IPv6 suport. [GL #1873] From 724fd536432192c13662da26120e044047056b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 5 Jun 2020 12:08:13 +0200 Subject: [PATCH 3/3] Add release note for #1808 (cherry picked from commit 5a9f594629557eef74f89bfbaaaffe5b22a20c8e) --- doc/arm/notes-9.11.20.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/arm/notes-9.11.20.xml b/doc/arm/notes-9.11.20.xml index d3453c3458..6b194c2f8e 100644 --- a/doc/arm/notes-9.11.20.xml +++ b/doc/arm/notes-9.11.20.xml @@ -47,7 +47,8 @@ - None. + Fix a data race in resolver.c:formerr() that could lead to assertion + failure. [GL #1808]