Avoid an overflow in constructing the ServerKeyExchange message
authorMatt Caswell <matt@openssl.org>
Fri, 1 Jul 2016 10:58:05 +0000 (11:58 +0100)
committerMatt Caswell <matt@openssl.org>
Fri, 1 Jul 2016 18:26:12 +0000 (19:26 +0100)
We calculate the size required for the ServerKeyExchange message and then
call BUF_MEM_grow_clean() on the buffer. However we fail to take account of
2 bytes required for the signature algorithm and 2 bytes for the signature
length, i.e. we could overflow by 4 bytes. In reality this won't happen
because the buffer is pre-allocated to a large size that means it should be
big enough anyway.

Addresses an OCAP Audit issue.

Reviewed-by: Rich Salz <rsalz@openssl.org>
ssl/s3_srvr.c

index 0c43c493ed6e2b875d3bb0404136a4cda24249bd..299f85b2fb57621fda82c8d9936ad7e0b8eb8f0e 100644 (file)
@@ -1872,6 +1872,11 @@ int ssl3_send_server_key_exchange(SSL *s)
                 goto f_err;
             }
             kn = EVP_PKEY_size(pkey);
+            /* Allow space for signature algorithm */
+            if (SSL_USE_SIGALGS(s))
+                kn += 2;
+            /* Allow space for signature length */
+            kn += 2;
         } else {
             pkey = NULL;
             kn = 0;