]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Fix bounds check in read_key() release/2.2 112/head
authorSteffan Karger <steffan.karger@fox-it.com>
Tue, 15 Aug 2017 08:04:33 +0000 (10:04 +0200)
committerDavid Sommerseth <davids@openvpn.net>
Thu, 21 Sep 2017 23:31:06 +0000 (01:31 +0200)
The bounds check in read_key() was performed after using the value, instead
of before.  If 'key-method 1' is used, this allowed an attacker to send a
malformed packet to trigger a stack buffer overflow.

Fix this by moving the input validation to before the writes.

Note that 'key-method 1' has been replaced by 'key method 2' as the default
in OpenVPN 2.0 (released on 2005-04-17), and explicitly deprecated in 2.4
and marked for removal in 2.5.  This should limit the amount of users
impacted by this issue.

CVE: 2017-12166
Signed-off-by: Steffan Karger <steffan.karger@fox-it.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <80690690-67ac-3320-1891-9fecedc6a1fa@fox-it.com>
URL: https://www.mail-archive.com/search?l=mid&q=80690690-67ac-3320-1891-9fecedc6a1fa@fox-it.com
Signed-off-by: David Sommerseth <davids@openvpn.net>
(cherry picked from commit fce34375295151f548a26c2d0eb30141e427c81a)

crypto.c

index b1a8a0291944ef87f9295872e99196f812a30a19..df8e0672e67da5205dcc0d93a04e93ac3456ddad 100644 (file)
--- a/crypto.c
+++ b/crypto.c
@@ -1461,13 +1461,14 @@ read_key (struct key *key, const struct key_type *kt, struct buffer *buf)
   if (!buf_read (buf, &hmac_length, 1))
     goto read_err;
 
+  if (cipher_length != kt->cipher_length || hmac_length != kt->hmac_length)
+    goto key_len_err;
+
   if (!buf_read (buf, key->cipher, cipher_length))
     goto read_err;
   if (!buf_read (buf, key->hmac, hmac_length))
     goto read_err;
 
-  if (cipher_length != kt->cipher_length || hmac_length != kt->hmac_length)
-    goto key_len_err;
 
   return 1;