Skip to contentSkip to conversation

crypto/qat: fix docsis segmentation fault

PATCH Superseded Rebecca Troy 4 participants 5 messages Jun 27, 2022 – Jun 30, 2022 Crypto API

lore
Share & tools
lore
#0 lore raw

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.

Fixes 98f060891615 ("crypto/qat: add symmetric session file")
---
 drivers/crypto/qat/qat_sym_session.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/crypto/qat/qat_sym_session.c +3 -8
index e40c042ba9..568792b753 100644
@@ -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
#1 lore raw
Quoted 4 lines · Rebecca Troy

Currently if AES or DES algorithms fail for Docsis test suite, a segmentation fault occurs when cryptodev_qat_autotest is ran.

Quoted 8 lines

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.

This is awkward.
This helper should let *ctx alone until everything succeeded.

Signature · 1 line
David Marchand
Acked-by on v1 1/1
#2 lore raw
In reply to Rebecca Troy
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 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.

Quoted 6 lines
Fixes 98f060891615 ("crypto/qat: add symmetric session file")

---

#3 lore raw

PATCH v2 1/1 crypto/qat: fix docsis segmentation fault

In reply to Rebecca Troy

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

---
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
index e40c042ba9..b30396487e 100644
@@ -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
Applied
#4 lore raw
Quoted 12 lines

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.

Quoted 6 lines
Fixes 98f0608 ("crypto/qat: add symmetric session file")

Applied to dpdk-next-crypto

Thanks.