summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorShane Lontis <shane.lontis@oracle.com>2021-05-25 13:31:44 +1000
committerPauli <pauli@openssl.org>2021-05-26 17:57:37 +1000
commit1ee04b791b396385cce2a0c46c112158b2005293 (patch)
tree2e3fd6cd9122d3a96c2971e7ad05b17de5d3891f /crypto
parent0221b080cefa7358c0a0737d089caeec2979f930 (diff)
Fix buffer overflow when generating large RSA keys in FIPS mode.
A pairwise test runs only in FIPS mode. An assumption about the size of the 'to' buffer passed to RSA_private_decrypt() was incorrect. It needs to be up to RSA_size() bytes long - so a fixed buffer of 256 bytes was not large enough. An exiting malloc has increased in size to allocate buffer space for both the encrypt and decrypt buffer. The existing test used 2080 bits which was not quite large enough to trigger the issue. A test using 3072 bits has been added. Reported by Mark Powers from Acumen. Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15447)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/rsa/rsa_gen.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/crypto/rsa/rsa_gen.c b/crypto/rsa/rsa_gen.c
index 07a3a7800e..ac64483e6a 100644
--- a/crypto/rsa/rsa_gen.c
+++ b/crypto/rsa/rsa_gen.c
@@ -479,7 +479,7 @@ static int rsa_keygen_pairwise_test(RSA *rsa, OSSL_CALLBACK *cb, void *cbarg)
unsigned int ciphertxt_len;
unsigned char *ciphertxt = NULL;
const unsigned char plaintxt[16] = {0};
- unsigned char decoded[256];
+ unsigned char *decoded = NULL;
unsigned int decoded_len;
unsigned int plaintxt_len = (unsigned int)sizeof(plaintxt_len);
int padding = RSA_PKCS1_PADDING;
@@ -492,9 +492,14 @@ static int rsa_keygen_pairwise_test(RSA *rsa, OSSL_CALLBACK *cb, void *cbarg)
OSSL_SELF_TEST_DESC_PCT_RSA_PKCS1);
ciphertxt_len = RSA_size(rsa);
- ciphertxt = OPENSSL_zalloc(ciphertxt_len);
+ /*
+ * RSA_private_encrypt() and RSA_private_decrypt() requires the 'to'
+ * parameter to be a maximum of RSA_size() - allocate space for both.
+ */
+ ciphertxt = OPENSSL_zalloc(ciphertxt_len * 2);
if (ciphertxt == NULL)
goto err;
+ decoded = ciphertxt + ciphertxt_len;
ciphertxt_len = RSA_public_encrypt(plaintxt_len, plaintxt, ciphertxt, rsa,
padding);