Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: starfive - Fix memory leak in starfive_aes_aead_do_one_req()

The starfive_aes_aead_do_one_req() function allocates rctx->adata with
kzalloc() but fails to free it if sg_copy_to_buffer() or
starfive_aes_hw_init() fails, which lead to memory leaks.

Since rctx->adata is unconditionally freed after the write_adata
operations, ensure consistent cleanup by freeing the allocation in these
earlier error paths as well.

Compile tested only. Issue found using a prototype static analysis tool
and code review.

Fixes: 7467147ef9bf ("crypto: starfive - Use dma for aes requests")
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Zilin Guan and committed by
Herbert Xu
ccb679fd cd576c83

+7 -2
+7 -2
drivers/crypto/starfive/jh7110-aes.c
··· 669 669 return -ENOMEM; 670 670 671 671 if (sg_copy_to_buffer(req->src, sg_nents_for_len(req->src, cryp->assoclen), 672 - rctx->adata, cryp->assoclen) != cryp->assoclen) 672 + rctx->adata, cryp->assoclen) != cryp->assoclen) { 673 + kfree(rctx->adata); 673 674 return -EINVAL; 675 + } 674 676 } 675 677 676 678 if (cryp->total_in) ··· 683 681 ctx->rctx = rctx; 684 682 685 683 ret = starfive_aes_hw_init(ctx); 686 - if (ret) 684 + if (ret) { 685 + if (cryp->assoclen) 686 + kfree(rctx->adata); 687 687 return ret; 688 + } 688 689 689 690 if (!cryp->assoclen) 690 691 goto write_text;