crypto/openssl: fix asym memory leaks
PATCH 1/1 crypto/openssl: fix asym memory leaks
Numerous memory leaks were detected by ASAN
in the OpenSSL PMD asymmetric code path.
These are now fixed to free all variables allocated by OpenSSL functions such as BN_bin2bn and OSSL_PARAM_BLD_new.
Some need to exist until the op is processed,
for example the BIGNUMs associated with DSA.
The pointers for these are added to the private asym session so they can be accessed later when calling free.
---
Depends-on: patch-133837 ("crypto/openssl: fix memory leaks in asym ops")
--- drivers/crypto/openssl/openssl_pmd_private.h | 6 ++ drivers/crypto/openssl/rte_openssl_pmd.c | 42 +++------- drivers/crypto/openssl/rte_openssl_pmd_ops.c | 81 +++++++++++--------- 3 files changed, 62 insertions(+), 67 deletions(-)
drivers/crypto/openssl/openssl_pmd_private.h +6 -0
@@ -190,6 +190,8 @@ struct openssl_asym_session {struct dh {DH *dh_key;uint32_t key_op; +BIGNUM *p; +BIGNUM *g;#if (OPENSSL_VERSION_NUMBER >=0x30000000L )OSSL_PARAM_BLD * param_bld;OSSL_PARAM_BLD *param_bld_peer;
@@ -199,6 +201,10 @@ struct openssl_asym_session {DSA *dsa;#if (OPENSSL_VERSION_NUMBER >=0x30000000L )OSSL_PARAM_BLD * param_bld; +BIGNUM *p; +BIGNUM *g; +BIGNUM *q; +BIGNUM *priv_key;#endif } s;struct {
drivers/crypto/openssl/rte_openssl_pmd.c +12 -30
68 lines not on this page · raw message
drivers/crypto/openssl/rte_openssl_pmd_ops.c +44 -37
173 lines not on this page · raw message
Signature · 1 line
2.34.1
________________________________
From: Power, Ciara <[email protected]>
Sent: 03 November 2023 15:45
To: [email protected] <[email protected]>
Cc: Power, Ciara <[email protected]>; Ji, Kai <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Subject: [PATCH] crypto/openssl: fix asym memory leaks
Numerous memory leaks were detected by ASAN
in the OpenSSL PMD asymmetric code path.
These are now fixed to free all variables allocated by OpenSSL functions such as BN_bin2bn and OSSL_PARAM_BLD_new.
Some need to exist until the op is processed,
for example the BIGNUMs associated with DSA.
The pointers for these are added to the private asym session so they can be accessed later when calling free.
---
Depends-on: patch-133837 ("crypto/openssl: fix memory leaks in asym ops")
---
2.34.1
Quoted 23 lines
----------------------------------------------------------------------
Numerous memory leaks were detected by ASAN
in the OpenSSL PMD asymmetric code path.These are now fixed to free all variables allocated by OpenSSL functions such as
BN_bin2bnandOSSL_PARAM_BLD_new.Some need to exist until the op is processed,
for example the BIGNUMs associated with DSA.
The pointers for these are added to the private asym session so they can be accessed later when calling free.Fixes 4c7ae22f1f83 ("crypto/openssl: update DSA routine with 3.0 EVP API")Fixes c794b40c9258 ("crypto/openssl: update DH routine with 3.0 EVP API")Fixes 3b7d638fb11f ("crypto/openssl: support asymmetric SM2")Fixes ac42813a0a7c ("crypto/openssl: add DH and DSA asym operations")Fixes d7bd42f6db19 ("crypto/openssl: update RSA routine with 3.0 EVP API")
Quoted 1 line
Signed-off-by Ciara Power <[email protected]>
Please rebase on top of crypto tree.
PATCH v2 1/1 crypto/openssl: fix asym memory leaks
In reply to Ciara PowerNumerous memory leaks were detected by ASAN
in the OpenSSL PMD asymmetric code path.
These are now fixed to free all variables allocated by OpenSSL functions such as BN_bin2bn and OSSL_PARAM_BLD_new.
Some need to exist until the op is processed,
for example the BIGNUMs associated with DSA.
The pointers for these are added to the private asym session so they can be accessed later when calling free.
Some cases need to be treated differently if OpenSSL < 3.0. It has slightly different handling of memory, as functions such as RSA_set0_key() take over memory management of values, so the caller should not free the values.
---
v2: Added a few more fixes for OpenSSL < 3.0 cases.
--- drivers/crypto/openssl/openssl_pmd_private.h | 6 ++ drivers/crypto/openssl/rte_openssl_pmd.c | 1 + drivers/crypto/openssl/rte_openssl_pmd_ops.c | 98 +++++++++++++------- 3 files changed, 73 insertions(+), 32 deletions(-)
drivers/crypto/openssl/openssl_pmd_private.h +6 -0
@@ -190,6 +190,8 @@ struct openssl_asym_session {struct dh {DH *dh_key;uint32_t key_op; +BIGNUM *p; +BIGNUM *g;#if (OPENSSL_VERSION_NUMBER >=0x30000000L )OSSL_PARAM_BLD * param_bld;OSSL_PARAM_BLD *param_bld_peer;
@@ -199,6 +201,10 @@ struct openssl_asym_session {DSA *dsa;#if (OPENSSL_VERSION_NUMBER >=0x30000000L )OSSL_PARAM_BLD * param_bld; +BIGNUM *p; +BIGNUM *g; +BIGNUM *q; +BIGNUM *priv_key;#endif } s;struct {
drivers/crypto/openssl/rte_openssl_pmd.c +1 -0
@@ -1960,6 +1960,7 @@ process_openssl_dsa_sign_op_evp(struct rte_crypto_op *cop,OSSL_PARAM_free (params);EVP_PKEY_CTX_free (key_ctx);EVP_PKEY_CTX_free (dsa_ctx); +EVP_PKEY_free (pkey);return ret; }
drivers/crypto/openssl/rte_openssl_pmd_ops.c +66 -32
204 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 1/1 crypto/openssl: fix asym memory leaks
In reply to Ciara PowerNumerous memory leaks were detected by ASAN
in the OpenSSL PMD asymmetric code path.
These are now fixed to free all variables allocated by OpenSSL functions such as BN_bin2bn and OSSL_PARAM_BLD_new.
Some need to exist until the op is processed,
for example the BIGNUMs associated with DSA.
The pointers for these are added to the private asym session so they can be accessed later when calling free.
Some cases need to be treated differently if OpenSSL < 3.0. It has slightly different handling of memory, as functions such as RSA_set0_key() take over memory management of values, so the caller should not free the values.
---
v2: Added a few more fixes for OpenSSL < 3.0 cases.
v3: Fixed long line.
--- drivers/crypto/openssl/openssl_pmd_private.h | 6 ++ drivers/crypto/openssl/rte_openssl_pmd.c | 1 + drivers/crypto/openssl/rte_openssl_pmd_ops.c | 99 +++++++++++++------- 3 files changed, 74 insertions(+), 32 deletions(-)
drivers/crypto/openssl/openssl_pmd_private.h +6 -0
@@ -190,6 +190,8 @@ struct openssl_asym_session {struct dh {DH *dh_key;uint32_t key_op; +BIGNUM *p; +BIGNUM *g;#if (OPENSSL_VERSION_NUMBER >=0x30000000L )OSSL_PARAM_BLD * param_bld;OSSL_PARAM_BLD *param_bld_peer;
@@ -199,6 +201,10 @@ struct openssl_asym_session {DSA *dsa;#if (OPENSSL_VERSION_NUMBER >=0x30000000L )OSSL_PARAM_BLD * param_bld; +BIGNUM *p; +BIGNUM *g; +BIGNUM *q; +BIGNUM *priv_key;#endif } s;struct {
drivers/crypto/openssl/rte_openssl_pmd.c +1 -0
@@ -1960,6 +1960,7 @@ process_openssl_dsa_sign_op_evp(struct rte_crypto_op *cop,OSSL_PARAM_free (params);EVP_PKEY_CTX_free (key_ctx);EVP_PKEY_CTX_free (dsa_ctx); +EVP_PKEY_free (pkey);return ret; }
drivers/crypto/openssl/rte_openssl_pmd_ops.c +67 -32
205 lines not on this page · raw message
Signature · 1 line
2.25.1