Skip to contentSkip to conversation

crypto/ipsec_mb: fix usage of untrusted value

PATCH Superseded Piotr Bronowski 5 participants 10 messages Mar 7, 2022 – Mar 14, 2022 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto/ipsec_mb: fix usage of untrusted value

This patch removes coverity defect CID 375828:
Untrusted value as argument (TAINTED_SCALAR)

Coverity issue: CID 375828

Fixes 918fd2f1466b ("crypto/ipsec_mb: move aesni_mb PMD")
---
 drivers/crypto/ipsec_mb/pmd_aesni_gcm.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/crypto/ipsec_mb/pmd_aesni_gcm.c +3 -0
index e5ad629fe5..f735b77680 100644
@@ -206,6 +206,9 @@ post_process_gcm_crypto_op(struct ipsec_mb_qp *qp,
 			op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
 	} else {
 		if (session->req_digest_length != session->gen_digest_length) {
+			session->req_digest_length =
+				RTE_MIN(session->req_digest_length,
+						DIGEST_LENGTH_MAX);
 			if (session->op ==
 				IPSEC_MB_OP_AEAD_AUTHENTICATED_ENCRYPT)
 				memcpy(op->sym->aead.digest.data,
Signature · 13 lines
2.30.2

--------------------------------------------------------------
Intel Research and Development Ireland Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263


This e-mail and any attachments may contain confidential material for the sole
use of the intended recipient(s). Any review or distribution by others is
strictly prohibited. If you are not the intended recipient, please contact the
sender and delete all copies.
#1 lore raw

PATCH v2 1/1 crypto/ipsec_mb: fix usage of untrusted value

This patch removes coverity defect CID 375828:
Untrusted value as argument (TAINTED_SCALAR)

Coverity issue: CID 375828

Fixes 918fd2f1466b ("crypto/ipsec_mb: move aesni_mb PMD")

---
v2: use a different logic to check digest length

---
 drivers/crypto/ipsec_mb/pmd_aesni_gcm.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/crypto/ipsec_mb/pmd_aesni_gcm.c +8 -4
index e5ad629fe5..7cd20fc1cf 100644
@@ -96,7 +96,9 @@ aesni_gcm_session_configure(IMB_MGR *mb_mgr, void *session,
 		sess->iv.length = auth_xform->auth.iv.length;
 		key_length = auth_xform->auth.key.length;
 		key = auth_xform->auth.key.data;
-		sess->req_digest_length = auth_xform->auth.digest_length;
+		sess->req_digest_length =
+		    RTE_MIN(auth_xform->auth.digest_length,
+				DIGEST_LENGTH_MAX);
 		break;
 	case IPSEC_MB_OP_AEAD_AUTHENTICATED_ENCRYPT:
 	case IPSEC_MB_OP_AEAD_AUTHENTICATED_DECRYPT:
@@ -116,7 +118,9 @@ aesni_gcm_session_configure(IMB_MGR *mb_mgr, void *session,
 		key_length = aead_xform->aead.key.length;
 		key = aead_xform->aead.key.data;
 		sess->aad_length = aead_xform->aead.aad_length;
-		sess->req_digest_length = aead_xform->aead.digest_length;
+		sess->req_digest_length =
+			RTE_MIN(aead_xform->aead.digest_length,
+				DIGEST_LENGTH_MAX);
 		break;
 	default:
 		IPSEC_MB_LOG(
@@ -146,7 +150,7 @@ aesni_gcm_session_configure(IMB_MGR *mb_mgr, void *session,
 	}
 
 	/* Digest check */
-	if (sess->req_digest_length > 16) {
+	if (sess->req_digest_length > DIGEST_LENGTH_MAX) {
 		IPSEC_MB_LOG(ERR, "Invalid digest length");
 		ret = -EINVAL;
 		goto error_exit;
@@ -157,7 +161,7 @@ aesni_gcm_session_configure(IMB_MGR *mb_mgr, void *session,
 	 * the requested number of bytes.
 	 */
 	if (sess->req_digest_length < 4)
-		sess->gen_digest_length = 16;
+		sess->gen_digest_length = DIGEST_LENGTH_MAX;
 	else
 		sess->gen_digest_length = sess->req_digest_length;
 
Signature · 13 lines
2.30.2

--------------------------------------------------------------
Intel Research and Development Ireland Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263


This e-mail and any attachments may contain confidential material for the sole
use of the intended recipient(s). Any review or distribution by others is
strictly prohibited. If you are not the intended recipient, please contact the
sender and delete all copies.
Acked-by on v2 1/1
#2 lore raw
Quoted 16 lines

-----Original Message-----
From: Bronowski, PiotrX <[email protected]>
Sent: Monday, March 7, 2022 3:33 PM
To: [email protected]
Cc: Zhang, Roy Fan <[email protected]>; [email protected]; [email protected]; Yigit, Ferruh <[email protected]>; Doherty, Declan <[email protected]>; Bronowski, PiotrX <[email protected]>; [email protected]
Subject: [PATCH v2] crypto/ipsec_mb: fix usage of untrusted value

This patch removes coverity defect CID 375828:
Untrusted value as argument (TAINTED_SCALAR)

Coverity issue: CID 375828

Fixes 918fd2f1466b ("crypto/ipsec_mb: move aesni_mb PMD")
Quoted 7 lines

---
v2: use a different logic to check digest length
---

Acked-by
#3 lore raw
Quoted 16 lines
Quoted 16 lines

-----Original Message-----
From: Bronowski, PiotrX <[email protected]>
Sent: Monday, March 7, 2022 3:33 PM
To: [email protected]
Cc: Zhang, Roy Fan <[email protected]>; [email protected]; [email protected]; Yigit, Ferruh <[email protected]>; Doherty, Declan <[email protected]>; Bronowski, PiotrX <[email protected]>; [email protected]
Subject: [PATCH v2] crypto/ipsec_mb: fix usage of untrusted value

This patch removes coverity defect CID 375828:
Untrusted value as argument (TAINTED_SCALAR)

Coverity issue: CID 375828

Fixes 918fd2f1466b ("crypto/ipsec_mb: move aesni_mb PMD")
Quoted 8 lines
Quoted 7 lines

---
v2: use a different logic to check digest length
---

#4 lore raw
In reply to Zhang, Roy Fan

Hi Piotr,

Quoted 26 lines

-----Original Message-----
From: Zhang, Roy Fan <[email protected]>
Sent: Monday, March 7, 2022 4:27 PM
To: Bronowski, PiotrX <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; Yigit, Ferruh <[email protected]>; Doherty, Declan <[email protected]>; [email protected]
Subject: RE: [PATCH v2] crypto/ipsec_mb: fix usage of untrusted value

Quoted 6 lines

-----Original Message-----
From: Bronowski, PiotrX <[email protected]>
Sent: Monday, March 7, 2022 3:33 PM
To: [email protected]
Cc: Zhang, Roy Fan <[email protected]>; [email protected]; [email protected]; Yigit, Ferruh <[email protected]>; Doherty,

Declan

Quoted 10 lines

<[email protected]>; Bronowski, PiotrX <[email protected]>; [email protected]
Subject: [PATCH v2] crypto/ipsec_mb: fix usage of untrusted value

This patch removes coverity defect CID 375828:
Untrusted value as argument (TAINTED_SCALAR)

Coverity issue: CID 375828

Fixes 918fd2f1466b ("crypto/ipsec_mb: move aesni_mb PMD")
Quoted 8 lines
Quoted 7 lines

---
v2: use a different logic to check digest length
---

Sorry I missed a point in your change and thanks for Ciara pointing this out. You are changing the gen_digest_size to 64 which is wrong.
Please send v3.
Also instead of ack - Nack this patch.

#5 lore raw

Hi Piotr,

Quoted 45 lines

-----Original Message-----
From: Zhang, Roy Fan <[email protected]>
Sent: Wednesday 9 March 2022 14:35
To: Zhang, Roy Fan <[email protected]>; Bronowski, PiotrX <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; Yigit, Ferruh <[email protected]>; Doherty, Declan <[email protected]>; [email protected]; Power, Ciara <[email protected]>
Subject: RE: [PATCH v2] crypto/ipsec_mb: fix usage of untrusted value

Hi Piotr,

Quoted 33 lines

-----Original Message-----
From: Zhang, Roy Fan <[email protected]>
Sent: Monday, March 7, 2022 4:27 PM
To: Bronowski, PiotrX <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; Yigit, Ferruh <[email protected]>; Doherty, Declan <[email protected]>; [email protected]
Subject: RE: [PATCH v2] crypto/ipsec_mb: fix usage of untrusted value

Quoted 6 lines

-----Original Message-----
From: Bronowski, PiotrX <[email protected]>
Sent: Monday, March 7, 2022 3:33 PM
To: [email protected]
Cc: Zhang, Roy Fan <[email protected]>; [email protected]; [email protected]; Yigit, Ferruh <[email protected]>; Doherty,

Declan

Quoted 17 lines

<[email protected]>; Bronowski, PiotrX <[email protected]>; [email protected]
Subject: [PATCH v2] crypto/ipsec_mb: fix usage of untrusted value

This patch removes coverity defect CID 375828:
Untrusted value as argument (TAINTED_SCALAR)

Coverity issue: CID 375828

Fixes 918fd2f1466b ("crypto/ipsec_mb: move aesni_mb PMD")

---
v2: use a different logic to check digest length
---

Quoted 6 lines
Quoted 1 line

Sorry I missed a point in your change and thanks for Ciara pointing this out. You are changing the gen_digest_size to 64 which is wrong.
Please send v3.
Also instead of ack - Nack this patch.

[CP]

In the v3 I think Fixes line should also be updated to either:

Fixes 746825e5c0ea ("crypto/ipsec_mb: move aesni_gcm PMD")

Or

Fixes ceb863938708 ("crypto/aesni_gcm: support all truncated digest sizes")

(The second one seems to be where the code was introduced before being moved into the consolidated ipsec_mb PMD in 21.11)

Thanks,
Ciara

#6 lore raw

PATCH v3 1/1 crypto/ipsec_mb: fix coverity issue

In reply to Piotr Bronowski

This patch removes coverity defect CID 375828:
Untrusted value as argument (TAINTED_SCALAR)

Coverity issue: CID 375828

Fixes 918fd2f1466b ("crypto/ipsec_mb: move aesni_mb PMD")

---
v3: use a different logic to check digest length

---
 drivers/crypto/ipsec_mb/pmd_aesni_gcm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/crypto/ipsec_mb/pmd_aesni_gcm.c +6 -2
index e5ad629fe5..2c033c6f28 100644
@@ -96,7 +96,9 @@ aesni_gcm_session_configure(IMB_MGR *mb_mgr, void *session,
 		sess->iv.length = auth_xform->auth.iv.length;
 		key_length = auth_xform->auth.key.length;
 		key = auth_xform->auth.key.data;
-		sess->req_digest_length = auth_xform->auth.digest_length;
+		sess->req_digest_length =
+		    RTE_MIN(auth_xform->auth.digest_length,
+				DIGEST_LENGTH_MAX);
 		break;
 	case IPSEC_MB_OP_AEAD_AUTHENTICATED_ENCRYPT:
 	case IPSEC_MB_OP_AEAD_AUTHENTICATED_DECRYPT:
@@ -116,7 +118,9 @@ aesni_gcm_session_configure(IMB_MGR *mb_mgr, void *session,
 		key_length = aead_xform->aead.key.length;
 		key = aead_xform->aead.key.data;
 		sess->aad_length = aead_xform->aead.aad_length;
-		sess->req_digest_length = aead_xform->aead.digest_length;
+		sess->req_digest_length =
+			RTE_MIN(aead_xform->aead.digest_length,
+				DIGEST_LENGTH_MAX);
 		break;
 	default:
 		IPSEC_MB_LOG(
Signature · 13 lines
2.30.2

--------------------------------------------------------------
Intel Research and Development Ireland Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263


This e-mail and any attachments may contain confidential material for the sole
use of the intended recipient(s). Any review or distribution by others is
strictly prohibited. If you are not the intended recipient, please contact the
sender and delete all copies.
#7 lore raw

PATCH v4 1/1 crypto/ipsec_mb: fix coverity issue

This patch removes coverity defect CID 375828:
Untrusted value as argument (TAINTED_SCALAR)

Coverity issue: CID 375828

Fixes ceb863938708 ("crypto/aesni_gcm: support all truncated digest sizes")

---
v4: commit message corrected

---
 drivers/crypto/ipsec_mb/pmd_aesni_gcm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/crypto/ipsec_mb/pmd_aesni_gcm.c +6 -2
index e5ad629fe5..2c033c6f28 100644
@@ -96,7 +96,9 @@ aesni_gcm_session_configure(IMB_MGR *mb_mgr, void *session,
 		sess->iv.length = auth_xform->auth.iv.length;
 		key_length = auth_xform->auth.key.length;
 		key = auth_xform->auth.key.data;
-		sess->req_digest_length = auth_xform->auth.digest_length;
+		sess->req_digest_length =
+		    RTE_MIN(auth_xform->auth.digest_length,
+				DIGEST_LENGTH_MAX);
 		break;
 	case IPSEC_MB_OP_AEAD_AUTHENTICATED_ENCRYPT:
 	case IPSEC_MB_OP_AEAD_AUTHENTICATED_DECRYPT:
@@ -116,7 +118,9 @@ aesni_gcm_session_configure(IMB_MGR *mb_mgr, void *session,
 		key_length = aead_xform->aead.key.length;
 		key = aead_xform->aead.key.data;
 		sess->aad_length = aead_xform->aead.aad_length;
-		sess->req_digest_length = aead_xform->aead.digest_length;
+		sess->req_digest_length =
+			RTE_MIN(aead_xform->aead.digest_length,
+				DIGEST_LENGTH_MAX);
 		break;
 	default:
 		IPSEC_MB_LOG(
Signature · 13 lines
2.30.2

--------------------------------------------------------------
Intel Research and Development Ireland Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263


This e-mail and any attachments may contain confidential material for the sole
use of the intended recipient(s). Any review or distribution by others is
strictly prohibited. If you are not the intended recipient, please contact the
sender and delete all copies.
Acked-by on v4 1/1
#8 lore raw

RE: [PATCH v4] crypto/ipsec_mb: fix coverity issue

Quoted 27 lines

-----Original Message-----
From: Piotr Bronowski <[email protected]>
Sent: Wednesday 9 March 2022 18:02
To: [email protected]
Cc: Zhang, Roy Fan <[email protected]>; [email protected]; [email protected]; Yigit, Ferruh <[email protected]>; Doherty, Declan <[email protected]>; Bronowski, PiotrX <[email protected]>; [email protected]
Subject: [PATCH v4] crypto/ipsec_mb: fix coverity issue

This patch removes coverity defect CID 375828:
Untrusted value as argument (TAINTED_SCALAR)

Coverity issue: CID 375828

Fixes ceb863938708 ("crypto/aesni_gcm: support all truncated digest sizes")

---
v4: commit message corrected
---
drivers/crypto/ipsec_mb/pmd_aesni_gcm.c | 8 ++++++--

1 file changed, 6 insertions(+), 2 deletions(-)

<snip>

#9 lore raw

Re: [PATCH v4] crypto/ipsec_mb: fix coverity issue

Quoted 2 lines
Quoted 2 lines

This patch removes coverity defect CID 375828:
Untrusted value as argument (TAINTED_SCALAR)

It lacks an explanation of the cause.

Quoted 1 line
Quoted 1 line

Coverity issue: CID 375828

You should not write CID above.

Quoted 6 lines
Quoted 6 lines
Fixes ceb863938708 ("crypto/aesni_gcm: support all truncated digest sizes")

This Cc should be just below the "Fixes".

Quoted 1 line

Fixed formatting, writing a better title, and applied.