[v2] crypto/qat: fix docsis segmentation fault

Message ID 20220629161037.94805-1-rebecca.troy@intel.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers
Series [v2] crypto/qat: fix docsis segmentation fault |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/Intel-compilation fail Compilation issues
ci/intel-Testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Rebecca Troy June 29, 2022, 4:10 p.m. UTC
  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.

Fixes: 98f0608 ("crypto/qat: add symmetric session file")
Cc: fiona.trahe@intel.com
Cc: stable@dpdk.org

Signed-off-by: Rebecca Troy <rebecca.troy@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>

---
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(-)
  

Comments

Akhil Goyal June 30, 2022, 4:29 a.m. UTC | #1
> 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.
> 
> Fixes: 98f0608 ("crypto/qat: add symmetric session file")
> Cc: fiona.trahe@intel.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Rebecca Troy <rebecca.troy@intel.com>
> Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Applied to dpdk-next-crypto

Thanks.
  

Patch

diff --git a/drivers/crypto/qat/qat_sym_session.c b/drivers/crypto/qat/qat_sym_session.c
index e40c042ba9..b30396487e 100644
--- a/drivers/crypto/qat/qat_sym_session.c
+++ b/drivers/crypto/qat/qat_sym_session.c
@@ -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;
 }