Skip to contentSkip to conversation

crypto/openssl: validate incorrect signature in verify op

PATCH Superseded Gowrishankar Muthukrishnan 2 participants 3 messages Feb 16, 2025 – Feb 21, 2025 Crypto API

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto/openssl: validate incorrect signature in verify op

Return correct error status when incorrect signature is used in RSA verify op.

Fixes d7bd42f6db19 ("crypto/openssl: update RSA routine with 3.0 EVP API")
---
 drivers/crypto/openssl/rte_openssl_pmd.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/crypto/openssl/rte_openssl_pmd.c +3 -0
index b090611bd0..239688ed47 100644
@@ -2710,6 +2710,8 @@ process_openssl_rsa_op_evp(struct rte_crypto_op *cop,
 		return ret;
 	}
 
+	cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
+
 	switch (op->rsa.op_type) {
 	case RTE_CRYPTO_ASYM_OP_ENCRYPT:
 		if (EVP_PKEY_encrypt_init(rsa_ctx) != 1)
@@ -2807,6 +2809,7 @@ process_openssl_rsa_op_evp(struct rte_crypto_op *cop,
 				op->rsa.sign.data,
 				op->rsa.sign.length) <= 0) {
 			OPENSSL_free(tmp);
+			ret = 0;
 			goto err_rsa;
 		}
 
Signature · 1 line
2.25.1
#1 lore raw

________________________________
From: Gowrishankar Muthukrishnan
Sent: Sunday, February 16, 2025 14:28
To: [email protected]; Akhil Goyal; Ji, Kai; Fan Zhang
Cc: [email protected]; Gowrishankar Muthukrishnan; [email protected]
Subject: [PATCH] crypto/openssl: validate incorrect signature in verify op

Return correct error status when incorrect signature is used in RSA verify op.

Fixes d7bd42f6db19 ("crypto/openssl: update RSA routine with 3.0 EVP API")
---
 drivers/crypto/openssl/rte_openssl_pmd.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/crypto/openssl/rte_openssl_pmd.c +2 -0
index b090611bd0..239688ed47 100644
@@ -2710,6 +2710,8 @@ process_openssl_rsa_op_evp(struct rte_crypto_op *cop,
                 return ret;
         }
 
+       cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
+

[Kai] I dont see any status need to be change between L.2694 to here, unless I missing anyhere.

         switch (op->rsa.op_type) {
         case RTE_CRYPTO_ASYM_OP_ENCRYPT:
                 if (EVP_PKEY_encrypt_init(rsa_ctx) != 1)
@@ -2807,6 +2809,7 @@ process_openssl_rsa_op_evp(struct rte_crypto_op *cop,
                                 op->rsa.sign.data,
                                 op->rsa.sign.length) <= 0) {
                         OPENSSL_free(tmp);
+                       ret = 0;
[Kai] Please add some comments why ret need to return 0
                         goto err_rsa;
                 }

--
2.25.1

#2 lore raw

PATCH v2 1/1 crypto/openssl: validate incorrect signature in verify op

In reply to Gowrishankar Muthukrishnan

Return correct error status when incorrect signature is used in RSA verify op.

Fixes d7bd42f6db19 ("crypto/openssl: update RSA routine with 3.0 EVP API")

---
v2:
- added comments.

---
 drivers/crypto/openssl/rte_openssl_pmd.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/crypto/openssl/rte_openssl_pmd.c +8 -2
index b090611bd0..5bfad92b7c 100644
@@ -2803,9 +2803,15 @@ process_openssl_rsa_op_evp(struct rte_crypto_op *cop,
 			goto err_rsa;
 		}
 
-		if (EVP_PKEY_verify_recover(rsa_ctx, tmp, &outlen,
+		ret = EVP_PKEY_verify_recover(rsa_ctx, tmp, &outlen,
 				op->rsa.sign.data,
-				op->rsa.sign.length) <= 0) {
+				op->rsa.sign.length);
+		if (ret <= 0) {
+			/* OpenSSL RSA verification returns one on
+			 * successful verification, otherwise 0. Hence,
+			 * this enqueue operation should succeed even if
+			 * invalid signature has been requested in verify.
+			 */
 			OPENSSL_free(tmp);
 			goto err_rsa;
 		}
Signature · 1 line
2.25.1