check length sanity before correcting in EVP_CTRL_AEAD_TLS1_AAD
authorRich Salz <rsalz@openssl.org>
Mon, 24 Apr 2017 22:23:11 +0000 (18:23 -0400)
committerRich Salz <rsalz@openssl.org>
Mon, 24 Apr 2017 22:23:11 +0000 (18:23 -0400)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3290)

crypto/evp/e_aes_cbc_hmac_sha1.c
crypto/evp/e_aes_cbc_hmac_sha256.c
engines/e_dasync.c

index 52c7c7445ed920661f3ee1a5bb47f9ebe737aae0..8e71e591ea465248f423a4e5466467888628fdb6 100644 (file)
@@ -809,6 +809,8 @@ static int aesni_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
                 key->payload_length = len;
                 if ((key->aux.tls_ver =
                      p[arg - 4] << 8 | p[arg - 3]) >= TLS1_1_VERSION) {
+                    if (len < AES_BLOCK_SIZE)
+                        return 0;
                     len -= AES_BLOCK_SIZE;
                     p[arg - 2] = len >> 8;
                     p[arg - 1] = len;
index 93b88a0bbc25b0bb571382590ae3f9a0014b7035..f0be05ca46417bda0a3d29eb6d4d200ac41c416e 100644 (file)
@@ -788,6 +788,8 @@ static int aesni_cbc_hmac_sha256_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
                 key->payload_length = len;
                 if ((key->aux.tls_ver =
                      p[arg - 4] << 8 | p[arg - 3]) >= TLS1_1_VERSION) {
+                    if (len < AES_BLOCK_SIZE)
+                        return 0;
                     len -= AES_BLOCK_SIZE;
                     p[arg - 2] = len >> 8;
                     p[arg - 1] = len;
index 89b12775b1c4896401fe4eacddfb69a8a1724c60..4e3e9369fc6367e75cd7a5c4b398bc8c8e299aa1 100644 (file)
@@ -606,6 +606,8 @@ static int dasync_cipher_ctrl_helper(EVP_CIPHER_CTX *ctx, int type, int arg,
 
             if (pipe_ctx->enc) {
                 if ((p[arg - 4] << 8 | p[arg - 3]) >= TLS1_1_VERSION) {
+                    if (len < AES_BLOCK_SIZE)
+                        return 0;
                     len -= AES_BLOCK_SIZE;
                 }