Blame SOURCES/dovecot-2.3.8-CVE_2020_12674.patch

7bc0c9
From bd9d2fe7da833f0e4705a8280efc56930371806b Mon Sep 17 00:00:00 2001
7bc0c9
From: Aki Tuomi <aki.tuomi@open-xchange.com>
7bc0c9
Date: Wed, 6 May 2020 13:40:36 +0300
7bc0c9
Subject: [PATCH 1/3] auth: mech-rpa - Fail on zero len buffer
7bc0c9
7bc0c9
---
7bc0c9
 src/auth/mech-rpa.c | 2 +-
7bc0c9
 1 file changed, 1 insertion(+), 1 deletion(-)
7bc0c9
7bc0c9
diff --git a/src/auth/mech-rpa.c b/src/auth/mech-rpa.c
7bc0c9
index 08298ebdd6..2de8705b4f 100644
7bc0c9
--- a/src/auth/mech-rpa.c
7bc0c9
+++ b/src/auth/mech-rpa.c
7bc0c9
@@ -224,7 +224,7 @@ rpa_read_buffer(pool_t pool, const unsigned char **data,
7bc0c9
 		return 0;
7bc0c9
 
7bc0c9
 	len = *p++;
7bc0c9
-	if (p + len > end)
7bc0c9
+	if (p + len > end || len == 0)
7bc0c9
 		return 0;
7bc0c9
 
7bc0c9
 	*buffer = p_malloc(pool, len);
7bc0c9
-- 
7bc0c9
2.11.0
7bc0c9
7bc0c9
From 98c39fd633adf9b1d11a7bad58ef0784a25042e6 Mon Sep 17 00:00:00 2001
7bc0c9
From: Aki Tuomi <aki.tuomi@open-xchange.com>
7bc0c9
Date: Mon, 18 May 2020 13:08:45 +0300
7bc0c9
Subject: [PATCH 3/3] auth: test-mech - Add tests for RPA and NTLM bug
7bc0c9
7bc0c9
---
7bc0c9
 src/auth/test-mech.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++
7bc0c9
 1 file changed, 66 insertions(+)
7bc0c9
7bc0c9
diff -up dovecot-2.3.8/src/auth/test-mech.c.CVE_2020_12674prereq dovecot-2.3.8/src/auth/test-mech.c
7bc0c9
--- dovecot-2.3.8/src/auth/test-mech.c.CVE_2020_12674prereq	2020-08-07 20:46:56.095295825 +0200
7bc0c9
+++ dovecot-2.3.8/src/auth/test-mech.c	2020-08-07 20:47:08.742124304 +0200
7bc0c9
@@ -0,0 +1,196 @@
7bc0c9
+/* Copyright (c) 2020 Dovecot authors, see the included COPYING file */
7bc0c9
+
7bc0c9
+#include "lib.h"
7bc0c9
+#include "auth.h"
7bc0c9
+#include "str.h"
7bc0c9
+#include "auth-common.h"
7bc0c9
+#include "auth-request.h"
7bc0c9
+#include "auth-request-handler-private.h"
7bc0c9
+#include "auth-settings.h"
7bc0c9
+#include "otp.h"
7bc0c9
+#include "mech-otp-skey-common.h"
7bc0c9
+#include "settings-parser.h"
7bc0c9
+#include "password-scheme.h"
7bc0c9
+#include "test-common.h"
7bc0c9
+#include "test-auth.h"
7bc0c9
+#include "auth-token.h"
7bc0c9
+
7bc0c9
+#include <unistd.h>
7bc0c9
+#include <time.h>
7bc0c9
+
7bc0c9
+#define UCHAR_LEN(str) (const unsigned char *)(str), sizeof(str)-1
7bc0c9
+
7bc0c9
+extern const struct mech_module mech_oauthbearer;
7bc0c9
+extern const struct mech_module mech_otp;
7bc0c9
+extern const struct mech_module mech_ntlm;
7bc0c9
+extern const struct mech_module mech_rpa;
7bc0c9
+
7bc0c9
+static struct auth_settings set;
7bc0c9
+static struct mechanisms_register *mech_reg;
7bc0c9
+
7bc0c9
+struct test_case {
7bc0c9
+	const struct mech_module *mech;
7bc0c9
+	const unsigned char *in;
7bc0c9
+	size_t len;
7bc0c9
+	const char *username;
7bc0c9
+	const char *expect_error;
7bc0c9
+	bool success;
7bc0c9
+	bool set_username_before_test;
7bc0c9
+	bool set_cert_username;
7bc0c9
+};
7bc0c9
+
7bc0c9
+static void
7bc0c9
+verify_plain_continue_mock_callback(struct auth_request *request,
7bc0c9
+				    verify_plain_callback_t *callback)
7bc0c9
+{
7bc0c9
+	request->passdb_success = TRUE;
7bc0c9
+	callback(PASSDB_RESULT_OK, request);
7bc0c9
+}
7bc0c9
+
7bc0c9
+static void
7bc0c9
+request_handler_reply_mock_callback(struct auth_request *request,
7bc0c9
+				    enum auth_client_result result,
7bc0c9
+				    const void *auth_reply ATTR_UNUSED,
7bc0c9
+				    size_t reply_size ATTR_UNUSED)
7bc0c9
+{
7bc0c9
+	request->failed = result != AUTH_CLIENT_RESULT_SUCCESS;
7bc0c9
+
7bc0c9
+	if (request->passdb_result == PASSDB_RESULT_OK)
7bc0c9
+		request->failed = FALSE;
7bc0c9
+	else if (request->mech == &mech_otp) {
7bc0c9
+		if (null_strcmp(request->user, "otp_phase_2") == 0)
7bc0c9
+			request->failed = FALSE;
7bc0c9
+	} else if (request->mech == &mech_oauthbearer) {
7bc0c9
+	}
7bc0c9
+};
7bc0c9
+
7bc0c9
+static void
7bc0c9
+request_handler_reply_continue_mock_callback(struct auth_request *request,
7bc0c9
+					     const void *reply,
7bc0c9
+					     size_t reply_size)
7bc0c9
+{
7bc0c9
+	request->context = p_strndup(request->pool, reply, reply_size);
7bc0c9
+}
7bc0c9
+
7bc0c9
+static void
7bc0c9
+auth_client_request_mock_callback(const char *reply ATTR_UNUSED,
7bc0c9
+				  struct auth_client_connection *conn ATTR_UNUSED)
7bc0c9
+{
7bc0c9
+}
7bc0c9
+
7bc0c9
+static void test_mechs_init(void)
7bc0c9
+{
7bc0c9
+	const char *const services[] = {NULL};
7bc0c9
+	process_start_time = time(NULL);
7bc0c9
+
7bc0c9
+	/* Copy default settings */
7bc0c9
+	set = *(struct auth_settings *) auth_setting_parser_info.defaults;
7bc0c9
+	global_auth_settings = &set;
7bc0c9
+	global_auth_settings->base_dir = ".";
7bc0c9
+	memset((&set)->username_chars_map, 1, sizeof((&set)->username_chars_map));
7bc0c9
+	set.username_format = "";
7bc0c9
+
7bc0c9
+	t_array_init(&set.passdbs, 2);
7bc0c9
+	struct auth_passdb_settings *mock_set = t_new(struct auth_passdb_settings, 1);
7bc0c9
+	*mock_set = mock_passdb_set;
7bc0c9
+	array_push_back(&set.passdbs, &mock_set);
7bc0c9
+	mock_set = t_new(struct auth_passdb_settings, 1);
7bc0c9
+	*mock_set = mock_passdb_set;
7bc0c9
+	mock_set->master = TRUE;
7bc0c9
+	array_push_back(&set.passdbs, &mock_set);
7bc0c9
+	t_array_init(&set.userdbs, 1);
7bc0c9
+
7bc0c9
+	/* Disable stats */
7bc0c9
+	set.stats = FALSE;
7bc0c9
+
7bc0c9
+	/* For tests of digest-md5. */
7bc0c9
+	set.realms_arr = t_strsplit_spaces("example.com ", " ");
7bc0c9
+	/* For tests of mech-anonymous. */
7bc0c9
+	set.anonymous_username = "anonuser";
7bc0c9
+
7bc0c9
+	mech_init(global_auth_settings);
7bc0c9
+	mech_reg = mech_register_init(global_auth_settings);
7bc0c9
+	passdbs_init();
7bc0c9
+	userdbs_init();
7bc0c9
+	passdb_mock_mod_init();
7bc0c9
+	password_schemes_init();
7bc0c9
+
7bc0c9
+	auths_preinit(&set, pool_datastack_create(), mech_reg, services);
7bc0c9
+	auths_init();
7bc0c9
+	auth_token_init();
7bc0c9
+}
7bc0c9
+
7bc0c9
+
7bc0c9
+static void test_rpa(void)
7bc0c9
+{
7bc0c9
+	test_mechs_init();
7bc0c9
+	static struct auth_request_handler handler = {
7bc0c9
+		.callback = auth_client_request_mock_callback,
7bc0c9
+		.reply_callback = request_handler_reply_mock_callback,
7bc0c9
+		.reply_continue_callback = request_handler_reply_continue_mock_callback,
7bc0c9
+		.verify_plain_continue_callback = verify_plain_continue_mock_callback,
7bc0c9
+	};
7bc0c9
+
7bc0c9
+	const struct mech_module *mech = &mech_rpa;
7bc0c9
+	test_begin("test rpa");
7bc0c9
+	struct auth_request *req = mech->auth_new();
7bc0c9
+	global_auth_settings->realms_arr = t_strsplit("example.com", " ");
7bc0c9
+	req->set = global_auth_settings;
7bc0c9
+	req->service = "login";
7bc0c9
+	req->handler = &handler;
7bc0c9
+	req->mech_event = event_create(NULL);
7bc0c9
+	req->event = event_create(NULL);
7bc0c9
+	req->mech = mech;
7bc0c9
+	req->state = AUTH_REQUEST_STATE_MECH_CONTINUE;
7bc0c9
+	auth_request_state_count[AUTH_REQUEST_STATE_MECH_CONTINUE] = 1;
7bc0c9
+	mech->auth_initial(req, UCHAR_LEN("\x60\x11\x06\x09\x60\x86\x48\x01\x86\xf8\x73\x01\x01\x01\x00\x04\x00\x00\x01"));
7bc0c9
+	mech->auth_continue(req, UCHAR_LEN("\x60\x11\x06\x09\x60\x86\x48\x01\x86\xf8\x73\x01\x01\x00\x03A@A\x00"));
7bc0c9
+	test_assert(req->failed == TRUE);
7bc0c9
+	test_assert(req->passdb_success == FALSE);
7bc0c9
+	event_unref(&req->mech_event);
7bc0c9
+	event_unref(&req->event);
7bc0c9
+	mech->auth_free(req);
7bc0c9
+	test_end();
7bc0c9
+}
7bc0c9
+
7bc0c9
+static void test_ntlm(void)
7bc0c9
+{
7bc0c9
+	static struct auth_request_handler handler = {
7bc0c9
+		.callback = auth_client_request_mock_callback,
7bc0c9
+		.reply_callback = request_handler_reply_mock_callback,
7bc0c9
+		.reply_continue_callback = request_handler_reply_continue_mock_callback,
7bc0c9
+		.verify_plain_continue_callback = verify_plain_continue_mock_callback,
7bc0c9
+	};
7bc0c9
+
7bc0c9
+	const struct mech_module *mech = &mech_ntlm;
7bc0c9
+	test_begin("test ntlm");
7bc0c9
+	struct auth_request *req = mech->auth_new();
7bc0c9
+	global_auth_settings->realms_arr = t_strsplit("example.com", " ");
7bc0c9
+	req->set = global_auth_settings;
7bc0c9
+	req->service = "login";
7bc0c9
+	req->handler = &handler;
7bc0c9
+	req->mech_event = event_create(NULL);
7bc0c9
+	req->event = event_create(NULL);
7bc0c9
+	req->mech = mech;
7bc0c9
+	req->state = AUTH_REQUEST_STATE_MECH_CONTINUE;
7bc0c9
+	auth_request_state_count[AUTH_REQUEST_STATE_MECH_CONTINUE] = 1;
7bc0c9
+	mech->auth_initial(req, UCHAR_LEN("NTLMSSP\x00\x01\x00\x00\x00\x00\x02\x00\x00""AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
7bc0c9
+	mech->auth_continue(req, UCHAR_LEN("NTLMSSP\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00""AA\x00\x00\x41\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00""orange""\x00"));
7bc0c9
+	test_assert(req->failed == TRUE);
7bc0c9
+	test_assert(req->passdb_success == FALSE);
7bc0c9
+	event_unref(&req->mech_event);
7bc0c9
+	event_unref(&req->event);
7bc0c9
+	mech->auth_free(req);
7bc0c9
+	test_end();
7bc0c9
+}
7bc0c9
+
7bc0c9
+int main(void)
7bc0c9
+{
7bc0c9
+	static void (*const test_functions[])(void) = {
7bc0c9
+		test_rpa,
7bc0c9
+		test_ntlm,
7bc0c9
+		NULL
7bc0c9
+	};
7bc0c9
+
7bc0c9
+	return test_run(test_functions);
7bc0c9
+}