Skip to content

Commit 17ccc64

Browse files
Dan Carpentergregkh
authored andcommitted
crypto: ccp - fix resource leaks in ccp_run_aes_gcm_cmd()
commit 505d9dc upstream. There are three bugs in this code: 1) If we ccp_init_data() fails for &src then we need to free aad. Use goto e_aad instead of goto e_ctx. 2) The label to free the &final_wa was named incorrectly as "e_tag" but it should have been "e_final_wa". One error path leaked &final_wa. 3) The &tag was leaked on one error path. In that case, I added a free before the goto because the resource was local to that block. Fixes: 36cf515 ("crypto: ccp - Enable support for AES GCM on v5 CCPs") Reported-by: "minihanshen(沈明航)" <minihanshen@tencent.com> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: John Allen <john.allen@amd.com> Tested-by: John Allen <john.allen@amd.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 28f0fdb commit 17ccc64

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

‎drivers/crypto/ccp/ccp-ops.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
778778
in_place ? DMA_BIDIRECTIONAL
779779
: DMA_TO_DEVICE);
780780
if (ret)
781-
goto e_ctx;
781+
goto e_aad;
782782

783783
if (in_place) {
784784
dst = src;
@@ -863,7 +863,7 @@ ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
863863
op.u.aes.size = 0;
864864
ret = cmd_q->ccp->vdata->perform->aes(&op);
865865
if (ret)
866-
goto e_dst;
866+
goto e_final_wa;
867867

868868
if (aes->action == CCP_AES_ACTION_ENCRYPT) {
869869
/* Put the ciphered tag after the ciphertext. */
@@ -873,17 +873,19 @@ ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
873873
ret = ccp_init_dm_workarea(&tag, cmd_q, authsize,
874874
DMA_BIDIRECTIONAL);
875875
if (ret)
876-
goto e_tag;
876+
goto e_final_wa;
877877
ret = ccp_set_dm_area(&tag, 0, p_tag, 0, authsize);
878-
if (ret)
879-
goto e_tag;
878+
if (ret) {
879+
ccp_dm_free(&tag);
880+
goto e_final_wa;
881+
}
880882

881883
ret = crypto_memneq(tag.address, final_wa.address,
882884
authsize) ? -EBADMSG : 0;
883885
ccp_dm_free(&tag);
884886
}
885887

886-
e_tag:
888+
e_final_wa:
887889
ccp_dm_free(&final_wa);
888890

889891
e_dst:

0 commit comments

Comments
 (0)