Skip to contentSkip to conversation

crypto: qat - fix parameter check in aead encryption

PATCH In review Giovanni Cabiddu 2 participants 2 messages May 27, 2020 – Jun 12, 2020 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: qat - fix parameter check in aead encryption

Return -EINVAL if the input digest size and/or cipher
length is zero or the cipher length is not multiple of a block. These additional parameter checks prevent an undefined device behaviour.

---
 drivers/crypto/qat/qat_common/qat_algs.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/crypto/qat/qat_common/qat_algs.c +14 -1
index 9df4aebf37ca..00e10a4d578a 100644
@@ -825,8 +825,15 @@ static int qat_alg_aead_dec(struct aead_request *areq)
 	struct icp_qat_fw_la_auth_req_params *auth_param;
 	struct icp_qat_fw_la_bulk_req *msg;
 	int digst_size = crypto_aead_authsize(aead_tfm);
+	u32 cipher_length = areq->cryptlen - digst_size;
 	int ret, ctr = 0;
 
+	if (!digst_size || !areq->cryptlen || !cipher_length)
+		return -EINVAL;
+
+	if (cipher_length % 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;
@@ -840,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_length;
 	cipher_param->cipher_offset = areq->assoclen;
 	memcpy(cipher_param->u.cipher_IV_array, areq->iv, AES_BLOCK_SIZE);
 	auth_param = (void *)((uint8_t *)cipher_param + sizeof(*cipher_param));
@@ -869,6 +876,12 @@ static int qat_alg_aead_enc(struct aead_request *areq)
 	uint8_t *iv = areq->iv;
 	int ret, ctr = 0;
 
+	if (!areq->cryptlen)
+		return -EINVAL;
+
+	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
maintainer
#1 lore raw
Quoted 3 lines · Giovanni Cabiddu

Return -EINVAL if the input digest size and/or cipher
length is zero or the cipher length is not multiple of a block. These additional parameter checks prevent an undefined device behaviour.

But a zero-length encryption is valid for AEAD. If this triggers an issue in the hardware, then you must fallback to software rather than rejecting it.

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt