From: Yuansheng Yang <0xbeac@gmail.com>
To: Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>
Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH] crypto: crypto4xx - fix double-free in crypto4xx_destroy_pdr()
Date: Sat, 5 Dec 2026 09:56:33 +0800 [thread overview]
Message-ID: <20261205015633.1478657-1-0xbeac@gmail.com> (raw)
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
reply other threads:[~2026-12-05 1:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205015633.1478657-1-0xbeac@gmail.com \
--to=0xbeac@gmail.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox