Fix S390X bad size_t that causes memory trash in legacy ciphers
authorShane Lontis <shane.lontis@oracle.com>
Fri, 13 Sep 2019 23:11:28 +0000 (09:11 +1000)
committerShane Lontis <shane.lontis@oracle.com>
Fri, 13 Sep 2019 23:11:28 +0000 (09:11 +1000)
This caused a SEGV inside tls13_enc() when using chacha_poly.
The tls code assigns the iv_length to a size_t (even though it is an int).
This is actually really bad since it could be -1, which will then trash the iv buffer.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/9890)

crypto/evp/evp_lib.c

index 5be04b050285d6ecfcd1e616b3c239f232d4b36f..eeed7359a41dd0a1dde6d88acb31ed7af988188a 100644 (file)
@@ -317,8 +317,8 @@ int EVP_CIPHER_iv_length(const EVP_CIPHER *cipher)
 
 int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx)
 {
-    int rv;
-    size_t len, v = EVP_CIPHER_iv_length(ctx->cipher);
+    int rv, len = EVP_CIPHER_iv_length(ctx->cipher);
+    size_t v = len;
     OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
 
     params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_IVLEN, &v);
@@ -331,9 +331,9 @@ legacy:
     if ((EVP_CIPHER_flags(ctx->cipher) & EVP_CIPH_CUSTOM_IV_LENGTH) != 0) {
         rv = EVP_CIPHER_CTX_ctrl((EVP_CIPHER_CTX *)ctx, EVP_CTRL_GET_IVLEN,
                                  0, &len);
-        return (rv == 1) ? (int)len : -1;
+        return (rv == 1) ? len : -1;
     }
-    return v;
+    return len;
 }
 
 int EVP_CIPHER_CTX_tag_length(const EVP_CIPHER_CTX *ctx)