mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-22 10:10:14 -04:00
[CVE-2025-40778] sec: usr: Address various spoofing attacks
Previously, several issues could be exploited to poison a DNS cache with spoofed records for zones which were not DNSSEC-signed or if the resolver was configured to not do DNSSEC validation. These issues were assigned CVE-2025-40778 and have now been fixed. As an additional layer of protection, :iscman:`named` no longer accepts DNAME records or extraneous NS records in the AUTHORITY section unless these are received via spoofing-resistant transport (TCP, UDP with DNS cookies, TSIG, or SIG(0)). ISC would like to thank Yuxiao Wu, Yunyi Zhang, Baojun Liu, and Haixin Duan from Tsinghua University for bringing this vulnerability to our attention. Closes isc-projects/bind9#5414 Merge branch '5414-security-check-name-vs-qname-again' into 'v9.21.13-release' See merge request isc-private/bind9!838
This commit is contained in:
commit
7b95c382db
4 changed files with 111 additions and 23 deletions
|
|
@ -2207,6 +2207,8 @@ Boolean Options
|
|||
autodetection of DNS COOKIE support to determine when to retry a
|
||||
request over TCP.
|
||||
|
||||
For DNAME lookups the default is ``yes`` and it is enforced. Servers
|
||||
serving DNAME must correctly support DNS over TCP.
|
||||
|
||||
.. note::
|
||||
If a UDP response is signed using TSIG, :iscman:`named` accepts it even if
|
||||
|
|
|
|||
|
|
@ -261,6 +261,7 @@ struct dns_message {
|
|||
unsigned int rdclass_set : 1; /* 14 */
|
||||
unsigned int fuzzing : 1; /* 15 */
|
||||
unsigned int free_pools : 1; /* 16 */
|
||||
unsigned int has_dname : 1; /* 17 */
|
||||
unsigned int : 0;
|
||||
|
||||
unsigned int opt_reserved;
|
||||
|
|
@ -1456,3 +1457,10 @@ dns_message_createpools(isc_mem_t *mctx, isc_mempool_t **namepoolp,
|
|||
isc_mempool_t **rdspoolp);
|
||||
void
|
||||
dns_message_destroypools(isc_mempool_t **namepoolp, isc_mempool_t **rdspoolp);
|
||||
|
||||
bool
|
||||
dns_message_hasdname(dns_message_t *msg);
|
||||
/*%<
|
||||
* Return whether a DNAME was detected in the ANSWER section of a QUERY
|
||||
* message when it was parsed.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -442,6 +442,7 @@ msginit(dns_message_t *m) {
|
|||
m->cc_bad = 0;
|
||||
m->tkey = 0;
|
||||
m->rdclass_set = 0;
|
||||
m->has_dname = 0;
|
||||
m->querytsig = NULL;
|
||||
m->indent.string = "\t";
|
||||
m->indent.count = 0;
|
||||
|
|
@ -1494,6 +1495,11 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t dctx,
|
|||
*/
|
||||
msg->tsigname->attributes.nocompress = true;
|
||||
free_name = false;
|
||||
} else if (rdtype == dns_rdatatype_dname &&
|
||||
sectionid == DNS_SECTION_ANSWER &&
|
||||
msg->opcode == dns_opcode_query)
|
||||
{
|
||||
msg->has_dname = 1;
|
||||
}
|
||||
rdataset = NULL;
|
||||
|
||||
|
|
@ -5083,3 +5089,9 @@ dns_message_destroypools(isc_mempool_t **namepoolp, isc_mempool_t **rdspoolp) {
|
|||
isc_mempool_destroy(rdspoolp);
|
||||
isc_mempool_destroy(namepoolp);
|
||||
}
|
||||
|
||||
bool
|
||||
dns_message_hasdname(dns_message_t *msg) {
|
||||
REQUIRE(DNS_MESSAGE_VALID(msg));
|
||||
return msg->has_dname;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -854,6 +854,7 @@ typedef struct respctx {
|
|||
bool get_nameservers; /* get a new NS rrset at
|
||||
* zone cut? */
|
||||
bool resend; /* resend this query? */
|
||||
bool secured; /* message was signed or had a valid cookie */
|
||||
bool nextitem; /* invalid response; keep
|
||||
* listening for the correct one */
|
||||
bool truncated; /* response was truncated */
|
||||
|
|
@ -6359,7 +6360,8 @@ mark_related(dns_name_t *name, dns_rdataset_t *rdataset, bool external,
|
|||
* locally served zone.
|
||||
*/
|
||||
static inline bool
|
||||
name_external(const dns_name_t *name, dns_rdatatype_t type, fetchctx_t *fctx) {
|
||||
name_external(const dns_name_t *name, dns_rdatatype_t type, respctx_t *rctx) {
|
||||
fetchctx_t *fctx = rctx->fctx;
|
||||
isc_result_t result;
|
||||
dns_forwarders_t *forwarders = NULL;
|
||||
dns_name_t *apex = NULL;
|
||||
|
|
@ -6369,7 +6371,7 @@ name_external(const dns_name_t *name, dns_rdatatype_t type, fetchctx_t *fctx) {
|
|||
dns_namereln_t rel;
|
||||
|
||||
apex = (ISDUALSTACK(fctx->addrinfo) || !ISFORWARDER(fctx->addrinfo))
|
||||
? fctx->domain
|
||||
? rctx->ns_name != NULL ? rctx->ns_name : fctx->domain
|
||||
: fctx->fwdname;
|
||||
|
||||
/*
|
||||
|
|
@ -6466,7 +6468,7 @@ check_section(void *arg, const dns_name_t *addname, dns_rdatatype_t type,
|
|||
result = dns_message_findname(rctx->query->rmessage, section, addname,
|
||||
dns_rdatatype_any, 0, &name, NULL);
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
external = name_external(name, type, fctx);
|
||||
external = name_external(name, type, rctx);
|
||||
if (type == dns_rdatatype_a) {
|
||||
ISC_LIST_FOREACH(name->list, rdataset, link) {
|
||||
if (dns_rdatatype_issig(rdataset->type)) {
|
||||
|
|
@ -7277,13 +7279,10 @@ rctx_cookiecheck(respctx_t *rctx) {
|
|||
resquery_t *query = rctx->query;
|
||||
|
||||
/*
|
||||
* If TSIG signed, sent via TCP, or cookie present,
|
||||
* no need to continue.
|
||||
* If the message was secured or TCP is already in the
|
||||
* retry flags, no need to continue.
|
||||
*/
|
||||
if (dns_message_gettsig(query->rmessage, NULL) != NULL ||
|
||||
query->rmessage->cc_ok || query->rmessage->cc_bad ||
|
||||
(rctx->retryopts & DNS_FETCHOPT_TCP) != 0)
|
||||
{
|
||||
if (rctx->secured || (rctx->retryopts & DNS_FETCHOPT_TCP) != 0) {
|
||||
return ISC_R_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -7346,6 +7345,47 @@ rctx_cookiecheck(respctx_t *rctx) {
|
|||
return ISC_R_SUCCESS;
|
||||
}
|
||||
|
||||
static bool
|
||||
rctx_need_tcpretry(respctx_t *rctx) {
|
||||
resquery_t *query = rctx->query;
|
||||
if ((rctx->retryopts & DNS_FETCHOPT_TCP) != 0) {
|
||||
/* TCP is already in the retry flags */
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the message was secured, no need to continue.
|
||||
*/
|
||||
if (rctx->secured) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Currently the only extra reason why we might need to
|
||||
* retry a UDP response over TCP is a DNAME in the message.
|
||||
*/
|
||||
if (dns_message_hasdname(query->rmessage)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
rctx_tcpretry(respctx_t *rctx) {
|
||||
/*
|
||||
* Do we need to retry a UDP response over TCP?
|
||||
*/
|
||||
if (rctx_need_tcpretry(rctx)) {
|
||||
rctx->retryopts |= DNS_FETCHOPT_TCP;
|
||||
rctx->resend = true;
|
||||
rctx_done(rctx, ISC_R_SUCCESS);
|
||||
return ISC_R_COMPLETE;
|
||||
}
|
||||
|
||||
return ISC_R_SUCCESS;
|
||||
}
|
||||
|
||||
static void
|
||||
resquery_response_continue(void *arg, isc_result_t result) {
|
||||
respctx_t *rctx = arg;
|
||||
|
|
@ -7365,6 +7405,17 @@ resquery_response_continue(void *arg, isc_result_t result) {
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remember whether this message was signed or had a
|
||||
* valid client cookie; if not, we may need to retry over
|
||||
* TCP later.
|
||||
*/
|
||||
if (query->rmessage->cc_ok || query->rmessage->tsig != NULL ||
|
||||
query->rmessage->sig0 != NULL)
|
||||
{
|
||||
rctx->secured = true;
|
||||
}
|
||||
|
||||
/*
|
||||
* The dispatcher should ensure we only get responses with QR
|
||||
* set.
|
||||
|
|
@ -7372,13 +7423,21 @@ resquery_response_continue(void *arg, isc_result_t result) {
|
|||
INSIST((query->rmessage->flags & DNS_MESSAGEFLAG_QR) != 0);
|
||||
|
||||
/*
|
||||
* Check for cookie issues.
|
||||
* Check for cookie issues; if found, maybe retry over TCP.
|
||||
*/
|
||||
result = rctx_cookiecheck(rctx);
|
||||
if (result == ISC_R_COMPLETE) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check whether we need to retry over TCP for some other reason.
|
||||
*/
|
||||
result = rctx_tcpretry(rctx);
|
||||
if (result == ISC_R_COMPLETE) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for EDNS issues.
|
||||
*/
|
||||
|
|
@ -8091,8 +8150,8 @@ rctx_answer_positive(respctx_t *rctx) {
|
|||
}
|
||||
|
||||
/*
|
||||
* Cache records in the authority section, if
|
||||
* there are any suitable for caching.
|
||||
* Cache records in the authority section, if there are
|
||||
* any suitable for caching.
|
||||
*/
|
||||
rctx_authority_positive(rctx);
|
||||
|
||||
|
|
@ -8152,7 +8211,7 @@ rctx_answer_scan(respctx_t *rctx) {
|
|||
/*
|
||||
* Don't accept DNAME from parent namespace.
|
||||
*/
|
||||
if (name_external(name, dns_rdatatype_dname, fctx)) {
|
||||
if (name_external(name, dns_rdatatype_dname, rctx)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -8430,22 +8489,29 @@ rctx_answer_dname(respctx_t *rctx) {
|
|||
|
||||
/*
|
||||
* rctx_authority_positive():
|
||||
* Examine the records in the authority section (if there are any) for a
|
||||
* positive answer. We expect the names for all rdatasets in this
|
||||
* section to be subdomains of the domain being queried; any that are
|
||||
* not are skipped. We expect to find only *one* owner name; any names
|
||||
* after the first one processed are ignored. We expect to find only
|
||||
* rdatasets of type NS, RRSIG, or SIG; all others are ignored. Whatever
|
||||
* remains can be cached at trust level authauthority or additional
|
||||
* (depending on whether the AA bit was set on the answer).
|
||||
* If a positive answer was received over TCP or secured with a cookie
|
||||
* or TSIG, examine the authority section. We expect names for all
|
||||
* rdatasets in this section to be subdomains of the domain being queried;
|
||||
* any that are not are skipped. We expect to find only *one* owner name;
|
||||
* any names after the first one processed are ignored. We expect to find
|
||||
* only rdatasets of type NS; all others are ignored. Whatever remains can
|
||||
* be cached at trust level authauthority or additional (depending on
|
||||
* whether the AA bit was set on the answer).
|
||||
*/
|
||||
static void
|
||||
rctx_authority_positive(respctx_t *rctx) {
|
||||
fetchctx_t *fctx = rctx->fctx;
|
||||
|
||||
dns_message_t *msg = rctx->query->rmessage;
|
||||
|
||||
/* If it's spoofable, don't cache it. */
|
||||
if (!rctx->secured && (rctx->query->options & DNS_FETCHOPT_TCP) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
MSG_SECTION_FOREACH(msg, DNS_SECTION_AUTHORITY, name) {
|
||||
if (!name_external(name, dns_rdatatype_ns, fctx)) {
|
||||
if (!name_external(name, dns_rdatatype_ns, rctx) &&
|
||||
dns_name_issubdomain(fctx->name, name))
|
||||
{
|
||||
/*
|
||||
* We expect to find NS or SIG NS rdatasets, and
|
||||
* nothing else.
|
||||
|
|
|
|||
Loading…
Reference in a new issue