|
|
f80c77 |
From 6b9716ca5aa1bfe44c0d1ad7030446b28b4f9f84 Mon Sep 17 00:00:00 2001
|
|
|
f80c77 |
From: Stepan Broz <sbroz@redhat.com>
|
|
|
f80c77 |
Date: Mon, 25 Sep 2023 12:41:54 +0200
|
|
|
f80c77 |
Subject: [PATCH 1/1] Backport of CVE-2023-3341 fix
|
|
|
f80c77 |
|
|
|
f80c77 |
Taken from BIND 9.16.44 change.
|
|
|
f80c77 |
---
|
|
|
f80c77 |
lib/isccc/cc.c | 36 +++++++++++++++++++++++---------
|
|
|
f80c77 |
lib/isccc/include/isccc/result.h | 4 +++-
|
|
|
f80c77 |
lib/isccc/result.c | 4 +++-
|
|
|
f80c77 |
3 files changed, 32 insertions(+), 12 deletions(-)
|
|
|
f80c77 |
|
|
|
f80c77 |
diff --git a/lib/isccc/cc.c b/lib/isccc/cc.c
|
|
|
f80c77 |
index 42b3046..7f67d70 100644
|
|
|
f80c77 |
--- a/lib/isccc/cc.c
|
|
|
f80c77 |
+++ b/lib/isccc/cc.c
|
|
|
f80c77 |
@@ -51,6 +51,10 @@
|
|
|
f80c77 |
|
|
|
f80c77 |
#define MAX_TAGS 256
|
|
|
f80c77 |
#define DUP_LIFETIME 900
|
|
|
f80c77 |
+#ifndef ISCCC_MAXDEPTH
|
|
|
f80c77 |
+#define ISCCC_MAXDEPTH \
|
|
|
f80c77 |
+ 10 /* Big enough for rndc which just sends a string each way. */
|
|
|
f80c77 |
+#endif
|
|
|
f80c77 |
|
|
|
f80c77 |
typedef isccc_sexpr_t *sexpr_ptr;
|
|
|
f80c77 |
|
|
|
f80c77 |
@@ -571,19 +575,23 @@ verify(isccc_sexpr_t *alist, unsigned char *data, unsigned int length,
|
|
|
f80c77 |
|
|
|
f80c77 |
static isc_result_t
|
|
|
f80c77 |
table_fromwire(isccc_region_t *source, isccc_region_t *secret,
|
|
|
f80c77 |
- isc_uint32_t algorithm, isccc_sexpr_t **alistp);
|
|
|
f80c77 |
+ isc_uint32_t algorithm, unsigned int depth, isccc_sexpr_t **alistp);
|
|
|
f80c77 |
|
|
|
f80c77 |
static isc_result_t
|
|
|
f80c77 |
-list_fromwire(isccc_region_t *source, isccc_sexpr_t **listp);
|
|
|
f80c77 |
+list_fromwire(isccc_region_t *source, unsigned int depth, isccc_sexpr_t **listp);
|
|
|
f80c77 |
|
|
|
f80c77 |
static isc_result_t
|
|
|
f80c77 |
-value_fromwire(isccc_region_t *source, isccc_sexpr_t **valuep) {
|
|
|
f80c77 |
+value_fromwire(isccc_region_t *source, unsigned int depth, isccc_sexpr_t **valuep) {
|
|
|
f80c77 |
unsigned int msgtype;
|
|
|
f80c77 |
isc_uint32_t len;
|
|
|
f80c77 |
isccc_sexpr_t *value;
|
|
|
f80c77 |
isccc_region_t active;
|
|
|
f80c77 |
isc_result_t result;
|
|
|
f80c77 |
|
|
|
f80c77 |
+ if (depth > ISCCC_MAXDEPTH) {
|
|
|
f80c77 |
+ return (ISCCC_R_MAXDEPTH);
|
|
|
f80c77 |
+ }
|
|
|
f80c77 |
+
|
|
|
f80c77 |
if (REGION_SIZE(*source) < 1 + 4)
|
|
|
f80c77 |
return (ISC_R_UNEXPECTEDEND);
|
|
|
f80c77 |
GET8(msgtype, source->rstart);
|
|
|
f80c77 |
@@ -601,9 +609,9 @@ value_fromwire(isccc_region_t *source, isccc_sexpr_t **valuep) {
|
|
|
f80c77 |
} else
|
|
|
f80c77 |
result = ISC_R_NOMEMORY;
|
|
|
f80c77 |
} else if (msgtype == ISCCC_CCMSGTYPE_TABLE)
|
|
|
f80c77 |
- result = table_fromwire(&active, NULL, 0, valuep);
|
|
|
f80c77 |
+ result = table_fromwire(&active, NULL, 0, depth + 1, valuep);
|
|
|
f80c77 |
else if (msgtype == ISCCC_CCMSGTYPE_LIST)
|
|
|
f80c77 |
- result = list_fromwire(&active, valuep);
|
|
|
f80c77 |
+ result = list_fromwire(&active, depth + 1, valuep);
|
|
|
f80c77 |
else
|
|
|
f80c77 |
result = ISCCC_R_SYNTAX;
|
|
|
f80c77 |
|
|
|
f80c77 |
@@ -612,7 +620,7 @@ value_fromwire(isccc_region_t *source, isccc_sexpr_t **valuep) {
|
|
|
f80c77 |
|
|
|
f80c77 |
static isc_result_t
|
|
|
f80c77 |
table_fromwire(isccc_region_t *source, isccc_region_t *secret,
|
|
|
f80c77 |
- isc_uint32_t algorithm, isccc_sexpr_t **alistp)
|
|
|
f80c77 |
+ isc_uint32_t algorithm, unsigned int depth, isccc_sexpr_t **alistp)
|
|
|
f80c77 |
{
|
|
|
f80c77 |
char key[256];
|
|
|
f80c77 |
isc_uint32_t len;
|
|
|
f80c77 |
@@ -623,6 +631,10 @@ table_fromwire(isccc_region_t *source, isccc_region_t *secret,
|
|
|
f80c77 |
|
|
|
f80c77 |
REQUIRE(alistp != NULL && *alistp == NULL);
|
|
|
f80c77 |
|
|
|
f80c77 |
+ if (depth > ISCCC_MAXDEPTH) {
|
|
|
f80c77 |
+ return (ISCCC_R_MAXDEPTH);
|
|
|
f80c77 |
+ }
|
|
|
f80c77 |
+
|
|
|
f80c77 |
checksum_rstart = NULL;
|
|
|
f80c77 |
first_tag = ISC_TRUE;
|
|
|
f80c77 |
alist = isccc_alist_create();
|
|
|
f80c77 |
@@ -638,7 +650,7 @@ table_fromwire(isccc_region_t *source, isccc_region_t *secret,
|
|
|
f80c77 |
GET_MEM(key, len, source->rstart);
|
|
|
f80c77 |
key[len] = '\0'; /* Ensure NUL termination. */
|
|
|
f80c77 |
value = NULL;
|
|
|
f80c77 |
- result = value_fromwire(source, &value);
|
|
|
f80c77 |
+ result = value_fromwire(source, depth + 1, &value);
|
|
|
f80c77 |
if (result != ISC_R_SUCCESS)
|
|
|
f80c77 |
goto bad;
|
|
|
f80c77 |
if (isccc_alist_define(alist, key, value) == NULL) {
|
|
|
f80c77 |
@@ -671,14 +683,18 @@ table_fromwire(isccc_region_t *source, isccc_region_t *secret,
|
|
|
f80c77 |
}
|
|
|
f80c77 |
|
|
|
f80c77 |
static isc_result_t
|
|
|
f80c77 |
-list_fromwire(isccc_region_t *source, isccc_sexpr_t **listp) {
|
|
|
f80c77 |
+list_fromwire(isccc_region_t *source, unsigned int depth, isccc_sexpr_t **listp) {
|
|
|
f80c77 |
isccc_sexpr_t *list, *value;
|
|
|
f80c77 |
isc_result_t result;
|
|
|
f80c77 |
|
|
|
f80c77 |
+ if (depth > ISCCC_MAXDEPTH) {
|
|
|
f80c77 |
+ return (ISCCC_R_MAXDEPTH);
|
|
|
f80c77 |
+ }
|
|
|
f80c77 |
+
|
|
|
f80c77 |
list = NULL;
|
|
|
f80c77 |
while (!REGION_EMPTY(*source)) {
|
|
|
f80c77 |
value = NULL;
|
|
|
f80c77 |
- result = value_fromwire(source, &value);
|
|
|
f80c77 |
+ result = value_fromwire(source, depth + 1, &value);
|
|
|
f80c77 |
if (result != ISC_R_SUCCESS) {
|
|
|
f80c77 |
isccc_sexpr_free(&list);
|
|
|
f80c77 |
return (result);
|
|
|
f80c77 |
@@ -709,7 +725,7 @@ isccc_cc_fromwire(isccc_region_t *source, isccc_sexpr_t **alistp,
|
|
|
f80c77 |
if (version != 1)
|
|
|
f80c77 |
return (ISCCC_R_UNKNOWNVERSION);
|
|
|
f80c77 |
|
|
|
f80c77 |
- return (table_fromwire(source, secret, algorithm, alistp));
|
|
|
f80c77 |
+ return (table_fromwire(source, secret, algorithm, 0, alistp));
|
|
|
f80c77 |
}
|
|
|
f80c77 |
|
|
|
f80c77 |
static isc_result_t
|
|
|
f80c77 |
diff --git a/lib/isccc/include/isccc/result.h b/lib/isccc/include/isccc/result.h
|
|
|
f80c77 |
index 6ff81ad..3e14ee0 100644
|
|
|
f80c77 |
--- a/lib/isccc/include/isccc/result.h
|
|
|
f80c77 |
+++ b/lib/isccc/include/isccc/result.h
|
|
|
f80c77 |
@@ -47,8 +47,10 @@
|
|
|
f80c77 |
#define ISCCC_R_CLOCKSKEW (ISC_RESULTCLASS_ISCCC + 4)
|
|
|
f80c77 |
/*% Duplicate */
|
|
|
f80c77 |
#define ISCCC_R_DUPLICATE (ISC_RESULTCLASS_ISCCC + 5)
|
|
|
f80c77 |
+/*% Maximum recursion depth */
|
|
|
f80c77 |
+#define ISCCC_R_MAXDEPTH (ISC_RESULTCLASS_ISCCC + 6)
|
|
|
f80c77 |
|
|
|
f80c77 |
-#define ISCCC_R_NRESULTS 6 /*%< Number of results */
|
|
|
f80c77 |
+#define ISCCC_R_NRESULTS 7 /*%< Number of results */
|
|
|
f80c77 |
|
|
|
f80c77 |
ISC_LANG_BEGINDECLS
|
|
|
f80c77 |
|
|
|
f80c77 |
diff --git a/lib/isccc/result.c b/lib/isccc/result.c
|
|
|
f80c77 |
index 75f5ade..91df50a 100644
|
|
|
f80c77 |
--- a/lib/isccc/result.c
|
|
|
f80c77 |
+++ b/lib/isccc/result.c
|
|
|
f80c77 |
@@ -40,7 +40,8 @@ static const char *text[ISCCC_R_NRESULTS] = {
|
|
|
f80c77 |
"bad auth", /* 3 */
|
|
|
f80c77 |
"expired", /* 4 */
|
|
|
f80c77 |
"clock skew", /* 5 */
|
|
|
f80c77 |
- "duplicate" /* 6 */
|
|
|
f80c77 |
+ "duplicate", /* 6 */
|
|
|
f80c77 |
+ "max depth", /* 7 */
|
|
|
f80c77 |
};
|
|
|
f80c77 |
|
|
|
f80c77 |
static const char *ids[ISCCC_R_NRESULTS] = {
|
|
|
f80c77 |
@@ -50,6 +51,7 @@ static const char *ids[ISCCC_R_NRESULTS] = {
|
|
|
f80c77 |
"ISCCC_R_EXPIRED",
|
|
|
f80c77 |
"ISCCC_R_CLOCKSKEW",
|
|
|
f80c77 |
"ISCCC_R_DUPLICATE",
|
|
|
f80c77 |
+ "ISCCC_R_MAXDEPTH",
|
|
|
f80c77 |
};
|
|
|
f80c77 |
|
|
|
f80c77 |
#define ISCCC_RESULT_RESULTSET 2
|
|
|
f80c77 |
--
|
|
|
f80c77 |
2.41.0
|
|
|
f80c77 |
|