Fix buffer overflow when generating large RSA keys in FIPS mode.
authorShane Lontis <shane.lontis@oracle.com>
Tue, 25 May 2021 03:31:44 +0000 (13:31 +1000)
committerPauli <pauli@openssl.org>
Wed, 26 May 2021 07:57:37 +0000 (17:57 +1000)
commit1ee04b791b396385cce2a0c46c112158b2005293
tree2e3fd6cd9122d3a96c2971e7ad05b17de5d3891f
parent0221b080cefa7358c0a0737d089caeec2979f930
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)
crypto/rsa/rsa_gen.c
test/recipes/15-test_genrsa.t