Fix an information leak in the RSA padding check code.
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Mon, 31 Jul 2017 18:38:26 +0000 (20:38 +0200)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Mon, 31 Jul 2017 18:38:26 +0000 (20:38 +0200)
The memory blocks contain secret data and must be
cleared before returning to the system heap.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4063)

crypto/rsa/rsa_oaep.c
crypto/rsa/rsa_pk1.c

index 19d28c6f0e60123be1ea9f953328cebaee312cb2..9a01b4afc11fb4da89889ed1362bbbcf9cea0068 100644 (file)
@@ -237,10 +237,14 @@ int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
     RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP_MGF1,
            RSA_R_OAEP_DECODING_ERROR);
  cleanup:
-    if (db != NULL)
+    if (db != NULL) {
+        OPENSSL_cleanse(db, dblen);
         OPENSSL_free(db);
-    if (em != NULL)
+    }
+    if (em != NULL) {
+        OPENSSL_cleanse(em, num);
         OPENSSL_free(em);
+    }
     return mlen;
 }
 
index 017766ce7166841ea61d62aef3ee1375e4e7ff56..50397c335a5a568e35496d2ff3a1ebdbcf058ca2 100644 (file)
@@ -264,8 +264,10 @@ int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
     memcpy(to, em + msg_index, mlen);
 
  err:
-    if (em != NULL)
+    if (em != NULL) {
+        OPENSSL_cleanse(em, num);
         OPENSSL_free(em);
+    }
     if (mlen == -1)
         RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,
                RSA_R_PKCS_DECODING_ERROR);