Fix unbounded memory growth when using no-cached-fetch
authorMatt Caswell <matt@openssl.org>
Wed, 13 Mar 2024 15:19:43 +0000 (15:19 +0000)
committerMatt Caswell <matt@openssl.org>
Fri, 15 Mar 2024 18:12:48 +0000 (18:12 +0000)
commitce50d8941c303880b3cbb5ee1452b1269dbb14ce
tree41e24b190d79b78870b653bdef126eba2b1c1b37
parent002f3837ac6cd1f4bfd5147db6ba1ffda93f7627
Fix unbounded memory growth when using no-cached-fetch

When OpenSSL has been compiled with no-cached-fetch we do not cache
algorithms fetched from a provider. When we export an EVP_PKEY to a
provider we cache the details of that export in the operation cache for
that EVP_PKEY. Amoung the details we cache is the EVP_KEYMGMT that we used
for the export. When we come to reuse the key in the same provider that
we have previously exported the key to, we check the operation cache for
the cached key data. However because the EVP_KEYMGMT instance was not
cached then instance will be different every time and we were not
recognising that we had already exported the key to the provider.

This causes us to re-export the key to the same provider everytime the key
is used. Since this consumes memory we end up with unbounded memory growth.

The fix is to be more intelligent about recognising that we have already
exported key data to a given provider even if the EVP_KEYMGMT instance is
different.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/23841)

(cherry picked from commit dc9bc6c8e1bd329ead703417a2235ab3e97557ec)
crypto/evp/keymgmt_lib.c
crypto/evp/p_lib.c