All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/7] crypto: qce - fix CCM AAD buffer leak and AEAD error-path bugs
@ 2026-11-13  6:54 ZhaoJinming
  2026-11-13  6:54 ` [PATCH v2 1/7] crypto: qce - unmap the correct scatterlist in the CCM error path ZhaoJinming
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: ZhaoJinming @ 2026-11-13  6:54 UTC (permalink / raw)
  To: Bartosz Golaszewski, Herbert Xu, David S. Miller, Thara Gopinath
  Cc: linux-crypto, linux-arm-msm, linux-kernel, ZhaoJinming,
	Eric Biggers, Bartosz Golaszewski, stable

This series fixes a memory leak in the QCE AEAD driver together with
several bugs in the error handling around it.

qce_aead_ccm_prepare_buf_assoclen() allocates rctx->adata for every CCM
request that carries associated data, but the buffer is never freed.

While preparing that fix, a number of problems in the error paths turned
out to matter:

  - qce_aead_async_req_handle() unmaps req->src although rctx->src_sg is
    the scatterlist that was passed to dma_map_sg().  For CCM requests
    with associated data, rctx->src_sg carries the AAD buffer, so its
    mapping is leaked, and freeing rctx->adata there would free memory
    that is still DMA-mapped.

  - A dma_map_sg() failure for the source scatterlist is not detected,
    because the result is checked for a negative value while
    dma_map_sg() returns 0 on failure.  The error path then unmaps a
    scatterlist that was never mapped.

  - The error path frees rctx->dst_tbl even for in-place CCM decryption
    without associated data, where that table was never allocated.

  - qce_dma_prep_sgs() may leave a submitted RX descriptor behind when
    preparing the TX descriptor fails, and the error path does not
    terminate the channels before the buffers are unmapped.

  - sg_nents_for_len() failures in the CCM AAD preparation are not
    checked, so a negative count can be turned into an enormous
    sg_alloc_table() request.

  - qce_aead_prepare_buf() leaks rctx->dst_tbl when the source
    scatterlist is shorter than the requested length, because it returns
    the error after that table has already been allocated.

Patch 1 unmaps the correct scatterlist, patch 2 adds the missing frees,
patch 3 fixes the dma_map_sg() check, patch 4 guards the dst_tbl free,
patch 5 terminates the DMA channels on prepare failure, patch 6 checks
the scatterlist count and patch 7 releases dst_tbl when the source
scatterlist is invalid.

The first three issues were reported by Eric Biggers in July 2026 and
later flagged as pre-existing by the Sashiko review of the QCE BAM
locking series.  Patches 4-7 address further pre-existing issues found in
the review of this series.  They touch the same function that was
recently fixed by commit 7f2345f47dd1 ("crypto: qce - fix CCM AAD buffer
underallocation").

The DMA API issue in qce_ahash_async_req_handle() in
drivers/crypto/qce/sha.c, reported by the same Sashiko review, is
unrelated to these AEAD paths and will be submitted separately.

Signed-off-by: ZhaoJinming <zhaojinming@uniontech.com>
---
Changes in v2:
- guard the uninitialized dst_tbl free on the error path
- terminate the DMA channels when descriptor preparation fails
- reject a negative scatterlist count in CCM AAD preparation
- release dst_tbl when the source scatterlist is invalid
- add Reported-by and Link for Eric Biggers' original report
- carry Bartosz Golaszewski's Reviewed-by from v1
- the sha.c DMA API fix will be submitted separately
- Link to v1: https://patch.msgid.link/20261016-fix-qce-ccm-adata-leak-v1-0-f54a82af2de0@uniontech.com

---
ZhaoJinming (7):
      crypto: qce - unmap the correct scatterlist in the CCM error path
      crypto: qce - fix memory leak of the CCM AAD buffer
      crypto: qce - check dma_map_sg() result for the source scatterlist
      crypto: qce - do not free an uninitialized dst_tbl on the error path
      crypto: qce - terminate the DMA channels if descriptor preparation fails
      crypto: qce - reject a negative scatterlist count in CCM AAD preparation
      crypto: qce - release dst_tbl when the source scatterlist is invalid

 drivers/crypto/qce/aead.c | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)
---
base-commit: 0fcb05b72344f40806cbe810de8872f1698bf053
change-id: 20261015-fix-qce-ccm-adata-leak-1ef34f172ba1

Best regards,
--  
ZhaoJinming <zhaojinming@uniontech.com>


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-11-13  7:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13  6:54 [PATCH v2 0/7] crypto: qce - fix CCM AAD buffer leak and AEAD error-path bugs ZhaoJinming
2026-11-13  6:54 ` [PATCH v2 1/7] crypto: qce - unmap the correct scatterlist in the CCM error path ZhaoJinming
2026-11-13  6:54 ` [PATCH v2 2/7] crypto: qce - fix memory leak of the CCM AAD buffer ZhaoJinming
2026-11-13  7:06   ` sashiko-bot
2026-11-13  6:54 ` [PATCH v2 3/7] crypto: qce - check dma_map_sg() result for the source scatterlist ZhaoJinming
2026-11-13  6:54 ` [PATCH v2 4/7] crypto: qce - do not free an uninitialized dst_tbl on the error path ZhaoJinming
2026-11-13  6:54 ` [PATCH v2 5/7] crypto: qce - terminate the DMA channels if descriptor preparation fails ZhaoJinming
2026-11-13  6:54 ` [PATCH v2 6/7] crypto: qce - reject a negative scatterlist count in CCM AAD preparation ZhaoJinming
2026-11-13  7:08   ` sashiko-bot
2026-11-13  6:54 ` [PATCH v2 7/7] crypto: qce - release dst_tbl when the source scatterlist is invalid ZhaoJinming

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.