2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

Merge branch '1808-race-in-resolver-fetch' into 'master'

Fix a data access race in resolver.

Closes #1912 and #1808

See merge request isc-projects/bind9!3575
This commit is contained in:
Ondřej Surý
2020-06-05 14:21:12 +00:00
3 changed files with 20 additions and 16 deletions

View File

@@ -1,3 +1,5 @@
5437. [bug] Fix a data race in resolver log_formerr. [GL #1808]
5436. [placeholder] 5436. [placeholder]
5435. [placeholder] 5435. [placeholder]

View File

@@ -171,3 +171,6 @@ Bug Fixes
- With dnssec-policy, when creating a successor key, the goal state of - With dnssec-policy, when creating a successor key, the goal state of
the current active key (the predecessor) was not changed and thus was the current active key (the predecessor) was not changed and thus was
never is removed from the zone. [GL #1846] never is removed from the zone. [GL #1846]
- Fix a data race in resolver.c:formerr() that could lead to assertion
failure. [GL #1808]

View File

@@ -395,9 +395,9 @@ struct fetchctx {
unsigned int valfail; unsigned int valfail;
bool timeout; bool timeout;
dns_adbaddrinfo_t *addrinfo; dns_adbaddrinfo_t *addrinfo;
const isc_sockaddr_t *client;
dns_messageid_t id; dns_messageid_t id;
unsigned int depth; unsigned int depth;
char clientstr[ISC_SOCKADDR_FORMATSIZE];
}; };
#define FCTX_MAGIC ISC_MAGIC('F', '!', '!', '!') #define FCTX_MAGIC ISC_MAGIC('F', '!', '!', '!')
@@ -2100,6 +2100,7 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
goto cleanup_socket; goto cleanup_socket;
} }
#endif /* ifndef BROKEN_TCP_BIND_BEFORE_CONNECT */ #endif /* ifndef BROKEN_TCP_BIND_BEFORE_CONNECT */
/* /*
* A dispatch will be created once the connect succeeds. * A dispatch will be created once the connect succeeds.
*/ */
@@ -3494,11 +3495,13 @@ findname(fetchctx_t *fctx, const dns_name_t *name, in_port_t port,
fctx->adb, res->buckets[fctx->bucketnum].task, fctx_finddone, fctx->adb, res->buckets[fctx->bucketnum].task, fctx_finddone,
fctx, name, &fctx->name, fctx->type, options, now, NULL, fctx, name, &fctx->name, fctx->type, options, now, NULL,
res->view->dstport, fctx->depth + 1, fctx->qc, &find); res->view->dstport, fctx->depth + 1, fctx->qc, &find);
isc_log_write(dns_lctx, DNS_LOGCATEGORY_RESOLVER, isc_log_write(dns_lctx, DNS_LOGCATEGORY_RESOLVER,
DNS_LOGMODULE_RESOLVER, ISC_LOG_DEBUG(3), DNS_LOGMODULE_RESOLVER, ISC_LOG_DEBUG(3),
"fctx %p(%s): createfind for %p/%d - %s", fctx, "fctx %p(%s): createfind for %s/%d - %s", fctx,
fctx->info, fctx->client, fctx->id, fctx->info, fctx->clientstr, fctx->id,
isc_result_totext(result)); isc_result_totext(result));
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
if (result == DNS_R_ALIAS) { if (result == DNS_R_ALIAS) {
char namebuf[DNS_NAME_FORMATSIZE]; char namebuf[DNS_NAME_FORMATSIZE];
@@ -4989,7 +4992,12 @@ fctx_create(dns_resolver_t *res, const dns_name_t *name, dns_rdatatype_t type,
fctx->rand_bits = 0; fctx->rand_bits = 0;
fctx->timeout = false; fctx->timeout = false;
fctx->addrinfo = NULL; fctx->addrinfo = NULL;
fctx->client = client; if (client != NULL) {
isc_sockaddr_format(client, fctx->clientstr,
sizeof(fctx->clientstr));
} else {
memmove(fctx->clientstr, "<unknown>", sizeof("<unknown"));
}
fctx->ns_ttl = 0; fctx->ns_ttl = 0;
fctx->ns_ttl_ok = false; fctx->ns_ttl_ok = false;
@@ -5286,8 +5294,6 @@ log_lame(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo) {
static inline void static inline void
log_formerr(fetchctx_t *fctx, const char *format, ...) { log_formerr(fetchctx_t *fctx, const char *format, ...) {
char nsbuf[ISC_SOCKADDR_FORMATSIZE]; char nsbuf[ISC_SOCKADDR_FORMATSIZE];
char clbuf[ISC_SOCKADDR_FORMATSIZE];
const char *clmsg = "";
char msgbuf[2048]; char msgbuf[2048];
va_list args; va_list args;
@@ -5297,17 +5303,10 @@ log_formerr(fetchctx_t *fctx, const char *format, ...) {
isc_sockaddr_format(&fctx->addrinfo->sockaddr, nsbuf, sizeof(nsbuf)); 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, isc_log_write(dns_lctx, DNS_LOGCATEGORY_RESOLVER,
DNS_LOGMODULE_RESOLVER, ISC_LOG_NOTICE, DNS_LOGMODULE_RESOLVER, ISC_LOG_NOTICE,
"DNS format error from %s resolving %s%s%s: %s", nsbuf, "DNS format error from %s resolving %s for %s: %s", nsbuf,
fctx->info, clmsg, clbuf, msgbuf); fctx->info, fctx->clientstr, msgbuf);
} }
static isc_result_t static isc_result_t