Skip to content

Commit 876ca38

Browse files
dominik4658gregkh
authored andcommitted
crypto: qat - check cipher length for aead AES-CBC-HMAC-SHA
commit 45cb665 upstream. Return -EINVAL for authenc(hmac(sha1),cbc(aes)), authenc(hmac(sha256),cbc(aes)) and authenc(hmac(sha512),cbc(aes)) if the cipher length is not multiple of the AES block. This is to prevent an undefined device behaviour. Fixes: d370cec ("crypto: qat - Intel(R) QAT crypto interface") Cc: <stable@vger.kernel.org> Signed-off-by: Dominik Przychodni <dominik.przychodni@intel.com> [giovanni.cabiddu@intel.com: reworded commit message] Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a745dda commit 876ca38

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

drivers/crypto/qat/qat_common/qat_algs.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,11 @@ static int qat_alg_aead_dec(struct aead_request *areq)
828828
struct icp_qat_fw_la_bulk_req *msg;
829829
int digst_size = crypto_aead_authsize(aead_tfm);
830830
int ret, ctr = 0;
831+
u32 cipher_len;
832+
833+
cipher_len = areq->cryptlen - digst_size;
834+
if (cipher_len % AES_BLOCK_SIZE != 0)
835+
return -EINVAL;
831836

832837
ret = qat_alg_sgl_to_bufl(ctx->inst, areq->src, areq->dst, qat_req);
833838
if (unlikely(ret))
@@ -842,7 +847,7 @@ static int qat_alg_aead_dec(struct aead_request *areq)
842847
qat_req->req.comn_mid.src_data_addr = qat_req->buf.blp;
843848
qat_req->req.comn_mid.dest_data_addr = qat_req->buf.bloutp;
844849
cipher_param = (void *)&qat_req->req.serv_specif_rqpars;
845-
cipher_param->cipher_length = areq->cryptlen - digst_size;
850+
cipher_param->cipher_length = cipher_len;
846851
cipher_param->cipher_offset = areq->assoclen;
847852
memcpy(cipher_param->u.cipher_IV_array, areq->iv, AES_BLOCK_SIZE);
848853
auth_param = (void *)((u8 *)cipher_param + sizeof(*cipher_param));
@@ -871,6 +876,9 @@ static int qat_alg_aead_enc(struct aead_request *areq)
871876
u8 *iv = areq->iv;
872877
int ret, ctr = 0;
873878

879+
if (areq->cryptlen % AES_BLOCK_SIZE != 0)
880+
return -EINVAL;
881+
874882
ret = qat_alg_sgl_to_bufl(ctx->inst, areq->src, areq->dst, qat_req);
875883
if (unlikely(ret))
876884
return ret;

0 commit comments

Comments
 (0)