[PATCH v2] crypto: amlogic: Fix DMA memory leak in cipher error path
Herbert Xu
herbert at gondor.apana.org.au
Thu Sep 10 22:14:14 PDT 2026
On Sat, Aug 22, 2026 at 02:15:08PM +0530, Mohamad Raizudeen wrote:
> A DMA memory leak occurs in meson_cipher() on the mapping error paths.
> The driver jumps to the end of the function without unmapping the
> previously mapped source scatterlist and key/IV buffer when the
> destination apping fails.
>
> Additionally, a memory leak occurs when a scatterlist mapping succeeds
> but the returned count exceeds the driver's MAXDESC limit. In this case,
> the driver rejects the mapping without unmapping it. The BIDIRECTIONAL
> mapping branch also lacks the required 'MAXDESC -3' upper bound check.
>
> Fix this by introducing proper error labels, error_src and error_keyiv
> and unmap resources immediately inside the calidation checks to ensure
> all successfully mapped resources are cleaned up before returning the
> error.
>
> Fixes: 48fe583fe541 ("crypto: amlogic - Add crypto accelerator for amlogic GXL")
> Signed-off-by: Mohamad Raizudeen <raizudeen.kerneldev at gmail.com>
> ---
> Changes in v2:
> - Add missing '> MAXDESC - 3' upper bound check for the BIDIRECTIONAL
> scatterlist mapping branch.
> - Unmap scatterlists immediately inside the 'if' block when the count
> exceeds MAXDESC - 3, because dma_map_sg() actually succeeds in this
> case and the mapping must be undone.
>
> drivers/crypto/amlogic/amlogic-gxl-cipher.c | 25 ++++++++++++++++-----
> 1 file changed, 20 insertions(+), 5 deletions(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert at gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
More information about the linux-amlogic
mailing list