Blame SOURCES/dovecot-2.3.8-CVE_2020_12674.patch

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