Skip to contentSkip to conversation

crypto: qat - aead cipher length should be block multiple

PATCH In review Giovanni Cabiddu 2 participants 4 messages Aug 22, 2020 – Aug 31, 2020 1 message not in the archive Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: qat - aead cipher length should be block multiple

From: Dominik Przychodni <[email protected]>

Include an additional check on the cipher length to prevent undefined behaviour from occurring upon submitting requests which are not a multiple of AES_BLOCK_SIZE.

Fixes d370cec32194 ("crypto: qat - Intel(R) QAT crypto interface")
---
 drivers/crypto/qat/qat_common/qat_algs.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/crypto/qat/qat_common/qat_algs.c +9 -1
index 72753b84dc95..d552dbcfe0a0 100644
@@ -828,6 +828,11 @@ static int qat_alg_aead_dec(struct aead_request *areq)
 	struct icp_qat_fw_la_bulk_req *msg;
 	int digst_size = crypto_aead_authsize(aead_tfm);
 	int ret, ctr = 0;
+	u32 cipher_len;
+
+	cipher_len = areq->cryptlen - digst_size;
+	if (cipher_len % AES_BLOCK_SIZE != 0)
+		return -EINVAL;
 
 	ret = qat_alg_sgl_to_bufl(ctx->inst, areq->src, areq->dst, qat_req);
 	if (unlikely(ret))
@@ -842,7 +847,7 @@ static int qat_alg_aead_dec(struct aead_request *areq)
 	qat_req->req.comn_mid.src_data_addr = qat_req->buf.blp;
 	qat_req->req.comn_mid.dest_data_addr = qat_req->buf.bloutp;
 	cipher_param = (void *)&qat_req->req.serv_specif_rqpars;
-	cipher_param->cipher_length = areq->cryptlen - digst_size;
+	cipher_param->cipher_length = cipher_len;
 	cipher_param->cipher_offset = areq->assoclen;
 	memcpy(cipher_param->u.cipher_IV_array, areq->iv, AES_BLOCK_SIZE);
 	auth_param = (void *)((u8 *)cipher_param + sizeof(*cipher_param));
@@ -871,6 +876,9 @@ static int qat_alg_aead_enc(struct aead_request *areq)
 	u8 *iv = areq->iv;
 	int ret, ctr = 0;
 
+	if (areq->cryptlen % AES_BLOCK_SIZE != 0)
+		return -EINVAL;
+
 	ret = qat_alg_sgl_to_bufl(ctx->inst, areq->src, areq->dst, qat_req);
 	if (unlikely(ret))
 		return ret;
Signature · 1 line
2.26.2
#1 lore raw
Quoted 10 lines · Giovanni Cabiddu

From: Dominik Przychodni <[email protected]>

Include an additional check on the cipher length to prevent undefined behaviour from occurring upon submitting requests which are not a multiple of AES_BLOCK_SIZE.

Fixes d370cec32194 ("crypto: qat - Intel(R) QAT crypto interface")

I only looked at the patch, and not at the entire file, but could you explain which AES based AEAD implementations require the input length to be a multiple of the block size? CCM and GCM are both CTR based, and so any input length should be supported for at least those modes.

Quoted 42 lines
---
 drivers/crypto/qat/qat_common/qat_algs.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/crypto/qat/qat_common/qat_algs.c +9 -2
index 72753b84dc95..d552dbcfe0a0 100644
@@ -828,6 +828,11 @@ static int qat_alg_aead_dec(struct aead_request *areq)
        struct icp_qat_fw_la_bulk_req *msg;
        int digst_size = crypto_aead_authsize(aead_tfm);
        int ret, ctr = 0;
+       u32 cipher_len;
+
+       cipher_len = areq->cryptlen - digst_size;
+       if (cipher_len % AES_BLOCK_SIZE != 0)
+               return -EINVAL;
 
        ret = qat_alg_sgl_to_bufl(ctx->inst, areq->src, areq->dst, qat_req);
        if (unlikely(ret))
@@ -842,7 +847,7 @@ static int qat_alg_aead_dec(struct aead_request *areq)
        qat_req->req.comn_mid.src_data_addr = qat_req->buf.blp;
        qat_req->req.comn_mid.dest_data_addr = qat_req->buf.bloutp;
        cipher_param = (void *)&qat_req->req.serv_specif_rqpars;
-       cipher_param->cipher_length = areq->cryptlen - digst_size;
+       cipher_param->cipher_length = cipher_len;
        cipher_param->cipher_offset = areq->assoclen;
        memcpy(cipher_param->u.cipher_IV_array, areq->iv, AES_BLOCK_SIZE);
        auth_param = (void *)((u8 *)cipher_param + sizeof(*cipher_param));
@@ -871,6 +876,9 @@ static int qat_alg_aead_enc(struct aead_request *areq)
        u8 *iv = areq->iv;
        int ret, ctr = 0;
 
+       if (areq->cryptlen % AES_BLOCK_SIZE != 0)
+               return -EINVAL;
+
        ret = qat_alg_sgl_to_bufl(ctx->inst, areq->src, areq->dst, qat_req);
        if (unlikely(ret))
                return ret;
--

2.26.2

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 9 lines · Ard Biesheuvel
Quoted 7 lines · Giovanni Cabiddu

From: Dominik Przychodni <[email protected]>

Include an additional check on the cipher length to prevent undefined behaviour from occurring upon submitting requests which are not a multiple of AES_BLOCK_SIZE.

Quoted 8 lines
Quoted 3 lines
Fixes d370cec32194 ("crypto: qat - Intel(R) QAT crypto interface")

I only looked at the patch, and not at the entire file, but could you explain which AES based AEAD implementations require the input length to be a multiple of the block size? CCM and GCM are both CTR based, and so any input length should be supported for at least those modes.

This is only for AES CBC as the qat driver supports only authenc(hmac(sha1),cbc(aes)), authenc(hmac(sha256),cbc(aes)) and authenc(hmac(sha512),cbc(aes)).

Regards,

Signature · 1 line
Giovanni
#4 lore raw
Quoted 15 lines · Giovanni Cabiddu
Quoted 13 lines · Ard Biesheuvel
Quoted 10 lines · Giovanni Cabiddu

From: Dominik Przychodni <[email protected]>

Include an additional check on the cipher length to prevent undefined behaviour from occurring upon submitting requests which are not a multiple of AES_BLOCK_SIZE.

Fixes d370cec32194 ("crypto: qat - Intel(R) QAT crypto interface")
Quoted 8 lines
Quoted 4 lines

I only looked at the patch, and not at the entire file, but could you explain which AES based AEAD implementations require the input length to be a multiple of the block size? CCM and GCM are both CTR based, and so any input length should be supported for at least those modes.

This is only for AES CBC as the qat driver supports only authenc(hmac(sha1),cbc(aes)), authenc(hmac(sha256),cbc(aes)) and authenc(hmac(sha512),cbc(aes)).

Ah right, yes that makes sense.