Skip to contentSkip to conversation

crypto/qat: fix stack buffer overflow in SGL loop

PATCH Applied Ciara Power 4 participants 4 messages Apr 14, 2023 – May 3, 2023 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto/qat: fix stack buffer overflow in SGL loop

The cvec pointer was incremented incorrectly in the case where the length of remaining_off equals cvec len, and there is no next cvec. This led to cvec->iova being invalid memory to access.

Instead, only increment the cvec pointer when we know there is a next cvec to point to, by checking the i value, which represents the number of cvecs available.
If i is 0, then no need to increment as the current cvec is the last one.

Fixes a815a04cea05 ("crypto/qat: support symmetric build op request")
---
 drivers/crypto/qat/dev/qat_crypto_pmd_gens.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/qat/dev/qat_crypto_pmd_gens.h +2 -1
index 524c291340..092265631b 100644
@@ -682,7 +682,8 @@ enqueue_one_chain_job_gen1(struct qat_sym_session *ctx,
 		while (remaining_off >= cvec->len && i >= 1) {
 			i--;
 			remaining_off -= cvec->len;
-			cvec++;
+			if (i)
+				cvec++;
 		}
 
 		auth_iova_end = cvec->iova + remaining_off;
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 42 lines

-----Original Message-----
From: Power, Ciara <[email protected]>
Sent: Friday, April 14, 2023 1:32 PM
To: Ji, Kai <[email protected]>
Cc: [email protected]; Power, Ciara <[email protected]>; [email protected]
Subject: [PATCH] crypto/qat: fix stack buffer overflow in SGL loop

The cvec pointer was incremented incorrectly in the case where the length of remaining_off equals cvec len, and there is no next cvec. This led to cvec->iova being invalid memory to access.

Instead, only increment the cvec pointer when we know there is a next cvec to point to, by checking the i value, which represents the number of cvecs available.
If i is 0, then no need to increment as the current cvec is the last one.

Fixes a815a04cea05 ("crypto/qat: support symmetric build op request")
---
 drivers/crypto/qat/dev/qat_crypto_pmd_gens.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/qat/dev/qat_crypto_pmd_gens.h +2 -2
index 524c291340..092265631b 100644
@@ -682,7 +682,8 @@ enqueue_one_chain_job_gen1(struct qat_sym_session *ctx,
 		while (remaining_off >= cvec->len && i >= 1) {
 			i--;
 			remaining_off -= cvec->len;
-			cvec++;
+			if (i)
+				cvec++;
 		}
 
 		auth_iova_end = cvec->iova + remaining_off;
--

2.25.1

Acked-by on v1 1/1
#3 lore raw
In reply to Ciara Power

Hi Ciara,

Quoted 40 lines

-----Original Message-----
From: Ciara Power <[email protected]>
Sent: Friday 14 April 2023 13:32
To: Ji, Kai <[email protected]>
Cc: [email protected]; Power, Ciara <[email protected]>; [email protected]
Subject: [PATCH] crypto/qat: fix stack buffer overflow in SGL loop

The cvec pointer was incremented incorrectly in the case where the length of remaining_off equals cvec len, and there is no next cvec.
This led to cvec->iova being invalid memory to access.

Instead, only increment the cvec pointer when we know there is a next cvec to point to, by checking the i value, which represents the number of cvecs available.
If i is 0, then no need to increment as the current cvec is the last one.

Fixes a815a04cea05 ("crypto/qat: support symmetric build op request")
---
 drivers/crypto/qat/dev/qat_crypto_pmd_gens.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/qat/dev/qat_crypto_pmd_gens.h +2 -1
index 524c291340..092265631b 100644
@@ -682,7 +682,8 @@ enqueue_one_chain_job_gen1(struct
 qat_sym_session *ctx,
 		while (remaining_off >= cvec->len && i >= 1) {
 			i--;
 			remaining_off -= cvec->len;
-			cvec++;
+			if (i)
+				cvec++;
 		}
 
Quoted 3 lines

auth_iova_end = cvec->iova + remaining_off;
--
2.25.1