Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] crypto: crypto4xx - fix double-free in crypto4xx_destroy_pdr()
@ 2026-12-05  1:56 Yuansheng Yang
  0 siblings, 0 replies; only message in thread
From: Yuansheng Yang @ 2026-12-05  1:56 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller; +Cc: linux-crypto, linux-kernel, stable

In crypto4xx_build_pdr(), if kzalloc_objs() fails for dev->pdr_uinfo,
the error path frees dev->pdr via dma_free_coherent() and returns
-ENOMEM without clearing dev->pdr to NULL.

Its sole caller, crypto4xx_probe(), jumps to err_build_sdr: on error
and invokes crypto4xx_destroy_pdr(), which checks if (dev->pdr) and
frees the same coherent DMA buffer a second time:

  DMA-API: crypto4xx: device driver tries to free DMA memory it has not allocated
  Call Trace:
   check_unmap
   debug_dma_free_coherent
   dma_free_attrs
   crypto4xx_destroy_pdr
   crypto4xx_probe

  Trying to vunmap() nonexistent vm area
  Call Trace:
   vunmap
   dma_direct_free
   crypto4xx_destroy_pdr
   crypto4xx_probe

Remove the redundant dma_free_coherent() call in crypto4xx_build_pdr()
so all PDR cleanup is handled uniformly by crypto4xx_destroy_pdr() on
probe error, matching commit 746c908c4d72 ("crypto: crypto4xx - fix
double-free in crypto4xx_destroy_sdr").

Fixes: 5d59ad6eea82 ("crypto: crypto4xx - fix crypto4xx_build_pdr, crypto4xx_build_sdr leak")
Cc: stable@vger.kernel.org
Signed-off-by: Yuansheng Yang <0xbeac@gmail.com>
---
Cross-compiled for PowerPC 44x (ARCH=powerpc) with W=1 (0 warnings) and
verified on v7.4-rc5 in QEMU sam460ex (canyonlands.dtb) with
CONFIG_KASAN=y, CONFIG_DMA_API_DEBUG=y, and fail_page_alloc injected on
dev->pdr_uinfo allocation: before the fix, probing fails with DMA-API
and vunmap double-free warnings in crypto4xx_destroy_pdr(); after the
fix, 10/10 failed probe iterations return -ENOMEM cleanly with 0 errors
or warnings.

 drivers/crypto/amcc/crypto4xx_core.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c
index 5b5b76882..83f9938e7 100644
--- a/drivers/crypto/amcc/crypto4xx_core.c
+++ b/drivers/crypto/amcc/crypto4xx_core.c
@@ -172,13 +172,8 @@ static u32 crypto4xx_build_pdr(struct crypto4xx_device *dev)
 		return -ENOMEM;
 
 	dev->pdr_uinfo = kzalloc_objs(struct pd_uinfo, PPC4XX_NUM_PD);
-	if (!dev->pdr_uinfo) {
-		dma_free_coherent(dev->core_dev->device,
-				  sizeof(struct ce_pd) * PPC4XX_NUM_PD,
-				  dev->pdr,
-				  dev->pdr_pa);
+	if (!dev->pdr_uinfo)
 		return -ENOMEM;
-	}
 	dev->shadow_sa_pool = dma_alloc_coherent(dev->core_dev->device,
 				   sizeof(union shadow_sa_buf) * PPC4XX_NUM_PD,
 				   &dev->shadow_sa_pool_pa,
-- 
2.53.0

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-05  1:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05  1:56 [PATCH] crypto: crypto4xx - fix double-free in crypto4xx_destroy_pdr() Yuansheng Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox