crypto/qat: fix docsis segmentation fault
PATCH 1/1 crypto/qat: fix docsis segmentation fault
Currently if AES or DES algorithms fail for Docsis test suite, a segmentation fault occurs when cryptodev_qat_autotest is ran.
This is due to a duplicate call of EVP_CIPHER_CTX_free for the session context. Ctx is freed firstly in the bpi_cipher_ctx_init function and then again at the end of qat_sym_session_configure_cipher function.
This commit fixes this bug by removing the first instance of EVP_CIPHER_CTX_free, leaving just the dedicated function in the upper level to free the ctx.
--- drivers/crypto/qat/qat_sym_session.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/crypto/qat/qat_sym_session.c +3 -8
@@ -111,12 +111,12 @@ bpi_cipher_ctx_init(enum rte_crypto_cipher_algorithm cryptodev_algo, const uint8_t *key, uint16_t key_length, void **ctx) { const EVP_CIPHER *algo = NULL; -int ret; +int ret =0 ; *ctx =EVP_CIPHER_CTX_new ();if (*ctx ==NULL ) { ret = -ENOMEM ; - goto ctx_init_err; +return ret; }if (cryptodev_algo ==RTE_CRYPTO_CIPHER_DES_DOCSISBPI )
@@ -130,14 +130,9 @@ bpi_cipher_ctx_init(enum rte_crypto_cipher_algorithm cryptodev_algo,/* IV will be ECB encrypted whether direction is encrypt or decrypt*/ if (EVP_EncryptInit_ex (*ctx, algo,NULL , key,0 ) !=1 ) { ret = -EINVAL ; - goto ctx_init_err; +return ret; } -return 0 ; - -ctx_init_err: -if (*ctx !=NULL ) -EVP_CIPHER_CTX_free (*ctx);return ret; }
Signature · 1 line
2.34.1
Quoted 4 lines · Rebecca Troy
Currently if AES or DES algorithms fail for Docsis test suite, a segmentation fault occurs when
cryptodev_qat_autotestis ran.
Quoted 8 lines
This is due to a duplicate call of
EVP_CIPHER_CTX_freefor the session context. Ctx is freed firstly in thebpi_cipher_ctx_initfunction and then again at the end ofqat_sym_session_configure_cipherfunction.This commit fixes this bug by removing the first instance of
EVP_CIPHER_CTX_free, leaving just the dedicated function in the upper level to free the ctx.
This is awkward.
This helper should let *ctx alone until everything succeeded.
Signature · 1 line
David Marchand
Quoted 21 lines
-----Original Message-----
From: Troy, Rebecca <[email protected]>
Sent: Monday, June 27, 2022 5:44 PM
To: Zhang, Roy Fan <[email protected]>; Kusztal, ArkadiuszX <[email protected]>; Trahe, Fiona <[email protected]>; Tomasz Jozwiak <[email protected]>
Cc: [email protected]; Troy, Rebecca <[email protected]>; [email protected]
Subject: [PATCH]crypto/qat: fix docsis segmentation faultCurrently if AES or DES algorithms fail for Docsis test suite, a segmentation fault occurs when
cryptodev_qat_autotestis ran.This is due to a duplicate call of
EVP_CIPHER_CTX_freefor the session context. Ctx is freed firstly in thebpi_cipher_ctx_initfunction and then again at the end ofqat_sym_session_configure_cipherfunction.This commit fixes this bug by removing the first instance of
EVP_CIPHER_CTX_free, leaving just the dedicated function in the upper level to free the ctx.
Quoted 6 lines
Fixes 98f060891615 ("crypto/qat: add symmetric session file")Signed-off-by Rebecca Troy <[email protected]>---
PATCH v2 1/1 crypto/qat: fix docsis segmentation fault
In reply to Rebecca TroyCurrently if AES or DES algorithms fail for Docsis test suite, a segmentation fault occurs when cryptodev_qat_autotest is ran.
This is due to a duplicate call of EVP_CIPHER_CTX_free for the session context. Ctx is freed firstly in the bpi_cipher_ctx_init function and then again at the end of qat_sym_session_configure_cipher function.
This commit fixes this bug by removing the first instance of EVP_CIPHER_CTX_free, leaving just the dedicated function in the upper level to free the ctx.
---
V2:
- Changed the bug fix to set *ctx to NULL after the first
instance of EVP_CIPHER_CTX_free, rather than removing it. This will ensure NULL checks are met appropriately in further EVP_CIPHER_CTX_free calls, avoiding segmentation fault without relying solely on the caller to free the *ctx.
.
--- drivers/crypto/qat/qat_sym_session.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/crypto/qat/qat_sym_session.c +3 -1
@@ -136,8 +136,10 @@ bpi_cipher_ctx_init(enum rte_crypto_cipher_algorithm cryptodev_algo,return 0 ; ctx_init_err: -if (*ctx !=NULL ) +if (*ctx !=NULL ) {EVP_CIPHER_CTX_free (*ctx); + *ctx =NULL ; + }return ret; }
Signature · 1 line
2.25.1
Akhil Goyal
AppliedQuoted 12 lines
Currently if AES or DES algorithms fail for Docsis test suite, a segmentation fault occurs when
cryptodev_qat_autotestis ran.This is due to a duplicate call of
EVP_CIPHER_CTX_freefor the session context. Ctx is freed firstly in thebpi_cipher_ctx_initfunction and then again at the end ofqat_sym_session_configure_cipherfunction.This commit fixes this bug by removing the first instance of
EVP_CIPHER_CTX_free, leaving just the dedicated function in the upper level to free the ctx.
Quoted 6 lines
Signed-off-by Rebecca Troy <[email protected]>Acked-by Fan Zhang <[email protected]>
Applied to dpdk-next-crypto
Thanks.