From 645d4f230a5e83e35bb1e580d1319e14fc62cc2d Mon Sep 17 00:00:00 2001 From: cenhuilin Date: Tue, 20 Sep 2022 07:46:17 +0000 Subject: [PATCH] fix CVE-2022-30550 --- backport-fix-CVE-2022-30550.patch | 149 ++++++++++++++++++++++++++++++ dovecot.spec | 6 +- 2 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 backport-fix-CVE-2022-30550.patch diff --git a/backport-fix-CVE-2022-30550.patch b/backport-fix-CVE-2022-30550.patch new file mode 100644 index 0000000..25ea569 --- /dev/null +++ b/backport-fix-CVE-2022-30550.patch @@ -0,0 +1,149 @@ +From e98afec7f2ea68396ac97118479315eee867f326 Mon Sep 17 00:00:00 2001 +From: cenhuilin +Date: Tue, 20 Sep 2022 07:28:24 +0000 +Subject: [PATCH] auth: Fix handling passdbs with identical driver/args but different m… +…echanisms/username_filter + +The passdb was wrongly deduplicated in this situation, causing wrong +mechanisms or username_filter setting to be used. This would be a rather +unlikely configuration though. + +Fixed by moving mechanisms and username_filter from struct passdb_module +to struct auth_passdb, which is where they should have been in the first +place. +--- + src/auth/auth-request.c | 6 +++--- + src/auth/auth.c | 18 ++++++++++++++++++ + src/auth/auth.h | 5 +++++ + src/auth/passdb.c | 16 ++-------------- + src/auth/passdb.h | 4 ---- + src/auth/userdb.c | 2 ++ + 6 files changed, 30 insertions(+), 21 deletions(-) + +diff --git a/src/auth/auth-request.c b/src/auth/auth-request.c +index 51b44d9..f8a015c 100644 +--- a/src/auth/auth-request.c ++++ b/src/auth/auth-request.c +@@ -553,8 +553,8 @@ auth_request_want_skip_passdb(struct auth_request *request, + struct auth_passdb *passdb) + { + /* if mechanism is not supported, skip */ +- const char *const *mechs = passdb->passdb->mechanisms; +- const char *const *username_filter = passdb->passdb->username_filter; ++ const char *const *mechs = passdb->mechanisms; ++ const char *const *username_filter = passdb->username_filter; + const char *username; + + username = request->fields.user; +@@ -567,7 +567,7 @@ auth_request_want_skip_passdb(struct auth_request *request, + return TRUE; + } + +- if (passdb->passdb->username_filter != NULL && ++ if (passdb->username_filter != NULL && + !auth_request_username_accepted(username_filter, username)) { + auth_request_log_debug(request, + request->mech != NULL ? AUTH_SUBSYS_MECH +diff --git a/src/auth/auth.c b/src/auth/auth.c +index 2b8d32a..324bd79 100644 +--- a/src/auth/auth.c ++++ b/src/auth/auth.c +@@ -93,6 +93,24 @@ auth_passdb_preinit(struct auth *auth, const struct auth_passdb_settings *set, + auth_passdb->override_fields_tmpl = + passdb_template_build(auth->pool, set->override_fields); + ++ if (*set->mechanisms == '\0') { ++ auth_passdb->mechanisms = NULL; ++ } else if (strcasecmp(set->mechanisms, "none") == 0) { ++ auth_passdb->mechanisms = (const char *const[]){ NULL }; ++ } else { ++ auth_passdb->mechanisms = ++ (const char *const *)p_strsplit_spaces(auth->pool, ++ set->mechanisms, " ,"); ++ } ++ ++ if (*set->username_filter == '\0') { ++ auth_passdb->username_filter = NULL; ++ } else { ++ auth_passdb->username_filter = ++ (const char *const *)p_strsplit_spaces(auth->pool, ++ set->username_filter, " ,"); ++ } ++ + /* for backwards compatibility: */ + if (set->pass) + auth_passdb->result_success = AUTH_DB_RULE_CONTINUE; +diff --git a/src/auth/auth.h b/src/auth/auth.h +index 3ca5a9b..6208e4d 100644 +--- a/src/auth/auth.h ++++ b/src/auth/auth.h +@@ -41,6 +41,11 @@ struct auth_passdb { + struct passdb_template *default_fields_tmpl; + struct passdb_template *override_fields_tmpl; + ++ /* Supported authentication mechanisms, NULL is all, {NULL} is none */ ++ const char *const *mechanisms; ++ /* Username filter, NULL is no filter */ ++ const char *const *username_filter; ++ + enum auth_passdb_skip skip; + enum auth_db_rule result_success; + enum auth_db_rule result_failure; +diff --git a/src/auth/passdb.c b/src/auth/passdb.c +index 21fd385..55e3b1e 100644 +--- a/src/auth/passdb.c ++++ b/src/auth/passdb.c +@@ -226,20 +226,8 @@ passdb_preinit(pool_t pool, const struct auth_passdb_settings *set) + passdb->id = ++auth_passdb_id; + passdb->iface = *iface; + passdb->args = p_strdup(pool, set->args); +- if (*set->mechanisms == '\0') { +- passdb->mechanisms = NULL; +- } else if (strcasecmp(set->mechanisms, "none") == 0) { +- passdb->mechanisms = (const char *const[]){NULL}; +- } else { +- passdb->mechanisms = (const char* const*)p_strsplit_spaces(pool, set->mechanisms, " ,"); +- } +- +- if (*set->username_filter == '\0') { +- passdb->username_filter = NULL; +- } else { +- passdb->username_filter = (const char* const*)p_strsplit_spaces(pool, set->username_filter, " ,"); +- } +- array_push_back(&passdb_modules, &passdb); ++ /* NOTE: if anything else than driver & args are added here, ++ passdb_find() also needs to be updated. */ + return passdb; + } + +diff --git a/src/auth/passdb.h b/src/auth/passdb.h +index b405aa7..8f50050 100644 +--- a/src/auth/passdb.h ++++ b/src/auth/passdb.h +@@ -63,10 +63,6 @@ struct passdb_module { + /* Default password scheme for this module. + If default_cache_key is set, must not be NULL. */ + const char *default_pass_scheme; +- /* Supported authentication mechanisms, NULL is all, [NULL] is none*/ +- const char *const *mechanisms; +- /* Username filter, NULL is no filter */ +- const char *const *username_filter; + + /* If blocking is set to TRUE, use child processes to access + this passdb. */ +diff --git a/src/auth/userdb.c b/src/auth/userdb.c +index 2f1fdf9..efae555 100644 +--- a/src/auth/userdb.c ++++ b/src/auth/userdb.c +@@ -161,6 +161,8 @@ userdb_preinit(pool_t pool, const struct auth_userdb_settings *set) + userdb->iface = iface; + userdb->args = p_strdup(pool, set->args); + ++ /* NOTE: if anything else than driver & args are added here, ++ userdb_find() also needs to be updated. */ + array_push_back(&userdb_modules, &userdb); + return userdb; + } +-- +2.33.0 + diff --git a/dovecot.spec b/dovecot.spec index 9df42bc..2d8599d 100644 --- a/dovecot.spec +++ b/dovecot.spec @@ -6,7 +6,7 @@ Name: dovecot Version: 2.3.15 -Release: 5 +Release: 6 Summary: Dovecot Secure imap server License: MIT and LGPLv2.1 URL: http://www.dovecot.org/ @@ -37,6 +37,7 @@ Patch6011: dovecot-2.3.15-fixvalcond.patch Patch6012: dovecot-2.3.15-valbasherr.patch # https://github.com/dovecot/core/commit/6d902507c24fca4f64e3e9bf7d79ae5a48281cd8 Patch0013: test-cpu-limit-remove-checking-for-CPU-usage-upper-limit.patch +Patch0014: backport-fix-CVE-2022-30550.patch BuildRequires: gcc-c++ openssl-devel pam-devel zlib-devel bzip2-devel libcap-devel BuildRequires: libtool autoconf automake pkgconfig sqlite-devel libpq-devel @@ -306,6 +307,9 @@ make check %changelog +* Tue Sep 20 2022 cenhuilin - 1:2.3.15-6 +- Fix CVE-2022-30550 + * Wed Aug 10 2022 yaoxin - 1:2.3.15-5 - Fix build failure -- Gitee