crypto/evp: harden RC4_MD5 cipher.
authorAndy Polyakov <appro@openssl.org>
Wed, 18 Jan 2017 23:17:30 +0000 (00:17 +0100)
committerMatt Caswell <matt@openssl.org>
Thu, 26 Jan 2017 10:55:03 +0000 (10:55 +0000)
Originally a crash in 32-bit build was reported CHACHA20-POLY1305
cipher. The crash is triggered by truncated packet and is result
of excessive hashing to the edge of accessible memory (or bogus
MAC value is produced if x86 MD5 assembly module is involved). Since
hash operation is read-only it is not considered to be exploitable
beyond a DoS condition.

Thanks to Robert Święcki for report.

CVE-2017-3731

Reviewed-by: Rich Salz <rsalz@openssl.org>
crypto/evp/e_rc4_hmac_md5.c

index 5e92855dfdc01e7f342fdf74c8a4f811d49ea4a6..93cfe3f1074f7fa59526b651a6ef9b854a2f1ede 100644 (file)
@@ -269,6 +269,8 @@ static int rc4_hmac_md5_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
             len = p[arg - 2] << 8 | p[arg - 1];
 
             if (!ctx->encrypt) {
             len = p[arg - 2] << 8 | p[arg - 1];
 
             if (!ctx->encrypt) {
+                if (len < MD5_DIGEST_LENGTH)
+                    return -1;
                 len -= MD5_DIGEST_LENGTH;
                 p[arg - 2] = len >> 8;
                 p[arg - 1] = len;
                 len -= MD5_DIGEST_LENGTH;
                 p[arg - 2] = len >> 8;
                 p[arg - 1] = len;