clang / rpms / openssl

Forked from rpms/openssl 2 years ago
Clone
ffdfc30
From fc7804ec392fcf8051abe6bc9da9108744d2ae35 Mon Sep 17 00:00:00 2001
ffdfc30
From: Matt Caswell <matt@openssl.org>
ffdfc30
Date: Fri, 6 Jun 2014 14:25:52 -0700
ffdfc30
Subject: [PATCH] Fix DTLS handshake message size checks.
ffdfc30
MIME-Version: 1.0
ffdfc30
Content-Type: text/plain; charset=UTF-8
ffdfc30
Content-Transfer-Encoding: 8bit
ffdfc30
ffdfc30
In |dtls1_reassemble_fragment|, the value of
ffdfc30
|msg_hdr->frag_off+frag_len| was being checked against the maximum
ffdfc30
handshake message size, but then |msg_len| bytes were allocated for the
ffdfc30
fragment buffer. This means that so long as the fragment was within the
ffdfc30
allowed size, the pending handshake message could consume 16MB + 2MB
ffdfc30
(for the reassembly bitmap). Approx 10 outstanding handshake messages
ffdfc30
are allowed, meaning that an attacker could consume ~180MB per DTLS
ffdfc30
connection.
ffdfc30
ffdfc30
In the non-fragmented path (in |dtls1_process_out_of_seq_message|), no
ffdfc30
check was applied.
ffdfc30
ffdfc30
Fixes CVE-2014-3506
ffdfc30
ffdfc30
Wholly based on patch by Adam Langley with one minor amendment.
ffdfc30
ffdfc30
Reviewed-by: Emilia Käsper <emilia@openssl.org>
ffdfc30
---
ffdfc30
 ssl/d1_both.c | 29 ++++++++++++++++-------------
ffdfc30
 1 file changed, 16 insertions(+), 13 deletions(-)
ffdfc30
ffdfc30
diff --git a/ssl/d1_both.c b/ssl/d1_both.c
ffdfc30
index 6559dfc..b9e15df 100644
ffdfc30
--- a/ssl/d1_both.c
ffdfc30
+++ b/ssl/d1_both.c
ffdfc30
@@ -587,6 +587,16 @@ dtls1_retrieve_buffered_fragment(SSL *s, long max, int *ok)
ffdfc30
 		return 0;
ffdfc30
 	}
ffdfc30
 
ffdfc30
+/* dtls1_max_handshake_message_len returns the maximum number of bytes
ffdfc30
+ * permitted in a DTLS handshake message for |s|. The minimum is 16KB, but may
ffdfc30
+ * be greater if the maximum certificate list size requires it. */
ffdfc30
+static unsigned long dtls1_max_handshake_message_len(const SSL *s)
ffdfc30
+	{
ffdfc30
+	unsigned long max_len = DTLS1_HM_HEADER_LENGTH + SSL3_RT_MAX_ENCRYPTED_LENGTH;
ffdfc30
+	if (max_len < (unsigned long)s->max_cert_list)
ffdfc30
+		return s->max_cert_list;
ffdfc30
+	return max_len;
ffdfc30
+	}
ffdfc30
 
ffdfc30
 static int
ffdfc30
 dtls1_reassemble_fragment(SSL *s, struct hm_header_st* msg_hdr, int *ok)
ffdfc30
@@ -595,20 +605,10 @@ dtls1_reassemble_fragment(SSL *s, struct hm_header_st* msg_hdr, int *ok)
ffdfc30
 	pitem *item = NULL;
ffdfc30
 	int i = -1, is_complete;
ffdfc30
 	unsigned char seq64be[8];
ffdfc30
-	unsigned long frag_len = msg_hdr->frag_len, max_len;
ffdfc30
-
ffdfc30
-	if ((msg_hdr->frag_off+frag_len) > msg_hdr->msg_len)
ffdfc30
-		goto err;
ffdfc30
-
ffdfc30
-	/* Determine maximum allowed message size. Depends on (user set)
ffdfc30
-	 * maximum certificate length, but 16k is minimum.
ffdfc30
-	 */
ffdfc30
-	if (DTLS1_HM_HEADER_LENGTH + SSL3_RT_MAX_ENCRYPTED_LENGTH < s->max_cert_list)
ffdfc30
-		max_len = s->max_cert_list;
ffdfc30
-	else
ffdfc30
-		max_len = DTLS1_HM_HEADER_LENGTH + SSL3_RT_MAX_ENCRYPTED_LENGTH;
ffdfc30
+	unsigned long frag_len = msg_hdr->frag_len;
ffdfc30
 
ffdfc30
-	if ((msg_hdr->frag_off+frag_len) > max_len)
ffdfc30
+	if ((msg_hdr->frag_off+frag_len) > msg_hdr->msg_len ||
ffdfc30
+	    msg_hdr->msg_len > dtls1_max_handshake_message_len(s))
ffdfc30
 		goto err;
ffdfc30
 
ffdfc30
 	/* Try to find item in queue */
ffdfc30
@@ -749,6 +749,9 @@ dtls1_process_out_of_seq_message(SSL *s, struct hm_header_st* msg_hdr, int *ok)
ffdfc30
 		if (frag_len && frag_len < msg_hdr->msg_len)
ffdfc30
 			return dtls1_reassemble_fragment(s, msg_hdr, ok);
ffdfc30
 
ffdfc30
+		if (frag_len > dtls1_max_handshake_message_len(s))
ffdfc30
+			goto err;
ffdfc30
+
ffdfc30
 		frag = dtls1_hm_fragment_new(frag_len, 0);
ffdfc30
 		if ( frag == NULL)
ffdfc30
 			goto err;
ffdfc30
-- 
ffdfc30
1.8.3.1
ffdfc30