* [PATCH 01/10] crypto: caam - Fix descriptor buffer overflow in caam_process_blob()
[not found] <20261123151055.2533735-1-lee@kernel.org>
@ 2026-11-23 15:09 ` Lee Jones
2026-11-23 15:09 ` [PATCH 02/10] crypto: marvell - Fix AEAD key buffer overflow for SHA-384/512 HMAC Lee Jones
` (8 subsequent siblings)
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:09 UTC (permalink / raw)
To: lee, Horia Geantă, Pankaj Gupta, Sahil Malhotra, Herbert Xu,
David S. Miller, Steffen Trumtrar, Meenakshi Aggarwal,
linux-crypto, linux-kernel
Cc: stable
Commit a703a4c2a328 ("KEYS: trusted: caam based protected key") switched
caam_process_blob() from append_seq_in_ptr_intlen() and
append_seq_out_ptr_intlen() to append_seq_in_ptr() and
append_seq_out_ptr(), each of which emits an extra 32-bit extended
length word, and added append_key(), append_fifo_store(), and
append_jump() when encapsulating a protected key.
However, CAAM_BLOB_DESC_BYTES_MAX was not updated and still reserves
only 44 or 52 bytes (for 32-bit or 64-bit DMA addresses), whereas
caam_process_blob() now writes up to 60 bytes for standard blobs on
64-bit DMA platforms and up to 72 or 88 bytes when encapsulating a
protected key, overflowing the kzalloc()-allocated job descriptor
buffer into adjacent slab memory.
Update CAAM_BLOB_DESC_BYTES_MAX to account for the protected-key
commands and the extended sequence pointer length words.
Fixes: a703a4c2a328 ("KEYS: trusted: caam based protected key")
Closes: https://sashiko.dev/#/bug/linux-fd968875-61a8-4100-ba0c-b9cd164d86e8
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/crypto/caam/blob_gen.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/crypto/caam/blob_gen.c b/drivers/crypto/caam/blob_gen.c
index c18dbac56493..b4fdc15dd0b6 100644
--- a/drivers/crypto/caam/blob_gen.c
+++ b/drivers/crypto/caam/blob_gen.c
@@ -23,12 +23,16 @@
#define CAAM_BLOB_DESC_BYTES_MAX \
/* Command to initialize & stating length of descriptor */ \
(CAAM_CMD_SZ + \
+ /* Commands to load plain key, store protected key and jump */ \
+ CAAM_CMD_SZ + CAAM_PTR_SZ_MAX + \
+ CAAM_CMD_SZ + CAAM_PTR_SZ_MAX + \
+ CAAM_CMD_SZ + \
/* Command to append the key-modifier + key-modifier data */ \
CAAM_CMD_SZ + CAAM_BLOB_KEYMOD_LENGTH + \
- /* Command to include input key + pointer to the input key */ \
- CAAM_CMD_SZ + CAAM_PTR_SZ_MAX + \
- /* Command to include output key + pointer to the output key */ \
- CAAM_CMD_SZ + CAAM_PTR_SZ_MAX + \
+ /* Command to include input key + pointer and length */ \
+ 2 * CAAM_CMD_SZ + CAAM_PTR_SZ_MAX + \
+ /* Command to include output key + pointer and length */ \
+ 2 * CAAM_CMD_SZ + CAAM_PTR_SZ_MAX + \
/* Command describing the operation to perform */ \
CAAM_CMD_SZ)
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 02/10] crypto: marvell - Fix AEAD key buffer overflow for SHA-384/512 HMAC
[not found] <20261123151055.2533735-1-lee@kernel.org>
2026-11-23 15:09 ` [PATCH 01/10] crypto: caam - Fix descriptor buffer overflow in caam_process_blob() Lee Jones
@ 2026-11-23 15:09 ` Lee Jones
2026-11-23 15:09 ` [PATCH 03/10] crypto: nx - Fix bounce buffer copy overflow in decompress() Lee Jones
` (7 subsequent siblings)
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:09 UTC (permalink / raw)
To: lee, Srujana Challa, Bharat Bhushan, Herbert Xu, David S. Miller,
linux-crypto, linux-kernel
Cc: stable
Commit 311eea7e37c4 ("crypto: octeontx - Fix authenc setkey") and commit
7ccb750dcac8 ("crypto: octeontx2 - Fix authenc setkey") updated
aead_hmac_init() in the OcteonTX and OcteonTX2 CPT VF drivers to hash
authentication keys only when authkeylen exceeds the hash block size
(128 bytes for SHA-384 and SHA-512), copying shorter keys directly into
ctx->key followed by the encryption key.
However, OTX_CPT_MAX_HASH_KEY_SIZE and OTX2_CPT_MAX_HASH_KEY_SIZE are
defined as 64 rather than 128, sizing ctx->key at only 96 bytes. An
HMAC-SHA384 or HMAC-SHA512 AEAD key with an authentication key between
65 and 128 bytes writes up to 160 bytes into ctx->key, clobbering the
adjacent hashalg, sdesc, ipad, and opad pointers in struct
otx_cpt_aead_ctx and struct otx2_cpt_aead_ctx before writing through
ctx->ipad.
Increase OTX_CPT_MAX_HASH_KEY_SIZE and OTX2_CPT_MAX_HASH_KEY_SIZE to
128 to accommodate a full SHA-384/512 block-sized HMAC key.
Fixes: 311eea7e37c4 ("crypto: octeontx - Fix authenc setkey")
Fixes: 7ccb750dcac8 ("crypto: octeontx2 - Fix authenc setkey")
Closes: https://sashiko.dev/#/bug/linux-bf3e3416-972b-4a32-bb3c-9fe7d3f28c9d
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/crypto/marvell/octeontx/otx_cptvf_algs.h | 2 +-
drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/crypto/marvell/octeontx/otx_cptvf_algs.h b/drivers/crypto/marvell/octeontx/otx_cptvf_algs.h
index a50b5e2f8d00..29976126d5cf 100644
--- a/drivers/crypto/marvell/octeontx/otx_cptvf_algs.h
+++ b/drivers/crypto/marvell/octeontx/otx_cptvf_algs.h
@@ -15,7 +15,7 @@
#include "otx_cpt_common.h"
#define OTX_CPT_MAX_ENC_KEY_SIZE 32
-#define OTX_CPT_MAX_HASH_KEY_SIZE 64
+#define OTX_CPT_MAX_HASH_KEY_SIZE 128
#define OTX_CPT_MAX_KEY_SIZE (OTX_CPT_MAX_ENC_KEY_SIZE + \
OTX_CPT_MAX_HASH_KEY_SIZE)
enum otx_cpt_request_type {
diff --git a/drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.h b/drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.h
index d29f84f01cee..cbc590e9e020 100644
--- a/drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.h
+++ b/drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.h
@@ -12,7 +12,7 @@
#include "cn10k_cpt.h"
#define OTX2_CPT_MAX_ENC_KEY_SIZE 32
-#define OTX2_CPT_MAX_HASH_KEY_SIZE 64
+#define OTX2_CPT_MAX_HASH_KEY_SIZE 128
#define OTX2_CPT_MAX_KEY_SIZE (OTX2_CPT_MAX_ENC_KEY_SIZE + \
OTX2_CPT_MAX_HASH_KEY_SIZE)
enum otx2_cpt_request_type {
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 03/10] crypto: nx - Fix bounce buffer copy overflow in decompress()
[not found] <20261123151055.2533735-1-lee@kernel.org>
2026-11-23 15:09 ` [PATCH 01/10] crypto: caam - Fix descriptor buffer overflow in caam_process_blob() Lee Jones
2026-11-23 15:09 ` [PATCH 02/10] crypto: marvell - Fix AEAD key buffer overflow for SHA-384/512 HMAC Lee Jones
@ 2026-11-23 15:09 ` Lee Jones
2026-11-23 15:09 ` [PATCH 04/10] crypto: sun8i-ss - Fix scatterlist array overflow for HMAC requests Lee Jones
` (6 subsequent siblings)
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:09 UTC (permalink / raw)
To: lee, Haren Myneni, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Herbert Xu,
David S. Miller, Thorsten Blum, Bulent Abali, Robert Jennings,
Seth Jennings, Dan Streetman, linuxppc-dev, linux-crypto,
linux-kernel
Cc: stable
When decompress() falls back to software 842 decompression and the
remaining destination capacity p->oremain is smaller than required_len,
it redirects decompression into the bounce buffer ctx->dbounce with
dlen set to BOUNCE_BUFFER_SIZE.
After sw842_decompress() completes and ignore bytes are subtracted,
decompress() copies dlen bytes from ctx->dbounce into p->out via
memcpy() before update_param() validates that dlen does not exceed
p->oremain. A crafted compressed stream whose decompressed output
exceeds p->oremain therefore overflows the caller's destination buffer
by up to BOUNCE_BUFFER_SIZE bytes.
Validate that dlen does not exceed p->oremain and return -ENOSPC before
copying out of ctx->dbounce.
Fixes: ed70b479c2c0 ("crypto: nx - add hardware 842 crypto comp alg")
Closes: https://sashiko.dev/#/bug/linux-7309787b-8efe-4919-bb31-c4d9eceb9c0f
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/crypto/nx/nx-842.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/crypto/nx/nx-842.c b/drivers/crypto/nx/nx-842.c
index b4404a138962..4f96c2b2397b 100644
--- a/drivers/crypto/nx/nx-842.c
+++ b/drivers/crypto/nx/nx-842.c
@@ -427,8 +427,11 @@ static int decompress(struct nx842_crypto_ctx *ctx,
if (ignore)
pr_debug("ignoring last %x bytes\n", ignore);
- if (dst == ctx->dbounce)
+ if (dst == ctx->dbounce) {
+ if (dlen > p->oremain)
+ return -ENOSPC;
memcpy(p->out, dst, dlen);
+ }
pr_debug("decompress slen %x padding %x dlen %x ignore %x\n",
slen, padding, dlen, ignore);
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 04/10] crypto: sun8i-ss - Fix scatterlist array overflow for HMAC requests
[not found] <20261123151055.2533735-1-lee@kernel.org>
` (2 preceding siblings ...)
2026-11-23 15:09 ` [PATCH 03/10] crypto: nx - Fix bounce buffer copy overflow in decompress() Lee Jones
@ 2026-11-23 15:09 ` Lee Jones
2026-11-23 15:09 ` [PATCH 05/10] crypto: hisilicon/hpre - Fix buffer overflow on odd ECDH input size Lee Jones
` (5 subsequent siblings)
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:09 UTC (permalink / raw)
To: lee, Corentin Labbe, Herbert Xu, David S. Miller, Chen-Yu Tsai,
Jernej Skrabec, Samuel Holland, bui duc phuc, linux-crypto,
linux-arm-kernel, linux-sunxi, linux-kernel
Cc: stable
sun8i_ss_hash_need_fallback() reserves one hardware scatterlist slot
out of MAX_SG (8) for the trailing hash padding buffer, allowing up to
7 input scatterlist entries.
However, for HMAC requests (tfmctx->keylen > 0), sun8i_ss_hash_run()
also shifts the mapped source array up by one slot to insert the inner
pad at index 0 and increments i before writing the trailing padding
entry at rctx->t_src[i] and rctx->t_dst[i]. When an HMAC request
contains 7 block-aligned scatterlist entries, i reaches 8 (MAX_SG),
writing past the end of rctx->t_src and rctx->t_dst, corrupting
rctx->method and rctx->flow, and indexing out of bounds into ss->flows.
Reserve an extra scatterlist slot in sun8i_ss_hash_need_fallback() when
tfmctx->keylen is non-zero so 7-entry HMAC requests use the software
fallback.
Fixes: 801b7d572c0a ("crypto: sun8i-ss - add hmac(sha1)")
Closes: https://sashiko.dev/#/bug/linux-93388c71-507c-42fd-9c86-8076b06fc7c0
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
index 56ba4ff6d5ff..c2e0c6520f84 100644
--- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
+++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
@@ -344,9 +344,11 @@ static int sun8i_ss_run_hash_task(struct sun8i_ss_dev *ss,
static bool sun8i_ss_hash_need_fallback(struct ahash_request *areq)
{
struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
+ struct sun8i_ss_hash_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
struct ahash_alg *alg = crypto_ahash_alg(tfm);
struct sun8i_ss_alg_template *algt;
struct scatterlist *sg;
+ int max_sg;
algt = container_of(alg, struct sun8i_ss_alg_template, alg.hash.base);
@@ -360,8 +362,9 @@ static bool sun8i_ss_hash_need_fallback(struct ahash_request *areq)
return true;
}
- /* we need to reserve one SG for the padding one */
- if (sg_nents(areq->src) > MAX_SG - 1) {
+ /* Reserve one SG for padding and, for HMAC, one for ipad */
+ max_sg = tfmctx->keylen ? MAX_SG - 2 : MAX_SG - 1;
+ if (sg_nents(areq->src) > max_sg) {
algt->stat_fb_sgnum++;
return true;
}
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 05/10] crypto: hisilicon/hpre - Fix buffer overflow on odd ECDH input size
[not found] <20261123151055.2533735-1-lee@kernel.org>
` (3 preceding siblings ...)
2026-11-23 15:09 ` [PATCH 04/10] crypto: sun8i-ss - Fix scatterlist array overflow for HMAC requests Lee Jones
@ 2026-11-23 15:09 ` Lee Jones
2026-11-23 15:09 ` [PATCH 06/10] crypto: talitos - Remove duplicate IV unmap in AEAD encrypt path Lee Jones
` (4 subsequent siblings)
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:09 UTC (permalink / raw)
To: lee, Zhiqi Song, Longfang Liu, Herbert Xu, David S. Miller,
Weili Qian, Zaibo Xu, Meng Yu, linux-crypto, linux-kernel
Cc: stable
hpre_ecdh_src_data_init() validates the input public key length using
ctx->key_sz - (len >> 1) < 0 before copying len bytes into the upper
half (offset ctx->key_sz << 1) of a (ctx->key_sz << 2)-byte coherent
DMA buffer.
Because len >> 1 truncates the least significant bit, an odd input
length of (ctx->key_sz << 1) + 1 (such as 65 bytes for NIST P-256)
evaluates shift to 0, bypasses the bounds check, and writes one byte
past the end of the coherent DMA allocation in
scatterwalk_map_and_copy(). A zero length when ctx->key_sz is unset
similarly bypasses the check.
Reject zero, odd, or oversized lengths explicitly before computing the
coordinate offset.
Fixes: 05e7b906aa7c ("crypto: hisilicon/hpre - add 'ECDH' algorithm")
Closes: https://sashiko.dev/#/bug/linux-42c6cdd1-7f7e-4071-bb2f-a4db5935267e
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/crypto/hisilicon/hpre/hpre_crypto.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/crypto/hisilicon/hpre/hpre_crypto.c b/drivers/crypto/hisilicon/hpre/hpre_crypto.c
index 66a276786a7d..78ae987d338a 100644
--- a/drivers/crypto/hisilicon/hpre/hpre_crypto.c
+++ b/drivers/crypto/hisilicon/hpre/hpre_crypto.c
@@ -1484,9 +1484,10 @@ static int hpre_ecdh_src_data_init(struct hpre_asym_request *hpre_req,
int shift;
/* Src_data include gx and gy. */
+ if (unlikely(!len || (len & 1) || len > (ctx->key_sz << 1)))
+ return -EINVAL;
+
shift = ctx->key_sz - (len >> 1);
- if (unlikely(shift < 0))
- return -EINVAL;
ptr = dma_alloc_coherent(dev, ctx->key_sz << 2, &dma, gfp);
if (unlikely(!ptr))
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 06/10] crypto: talitos - Remove duplicate IV unmap in AEAD encrypt path
[not found] <20261123151055.2533735-1-lee@kernel.org>
` (4 preceding siblings ...)
2026-11-23 15:09 ` [PATCH 05/10] crypto: hisilicon/hpre - Fix buffer overflow on odd ECDH input size Lee Jones
@ 2026-11-23 15:09 ` Lee Jones
2026-11-23 15:09 ` [PATCH 07/10] crypto: safexcel - Check scatterlist errors before max() for in-place Lee Jones
` (3 subsequent siblings)
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:09 UTC (permalink / raw)
To: lee, Herbert Xu, David S. Miller, Paul Louvel, Evgeniy Polyakov,
Kim Phillips, Christophe Leroy, linux-crypto, linux-kernel
Cc: stable
Commit 2e13ce0812c6 ("crypto: talitos - DMA map key in setkey()") moved
key DMA mapping into setkey(), but inadvertently added an extra
dma_unmap_single() call on edesc->iv_dma in ipsec_esp_encrypt_done().
Because ipsec_esp() populates civ_ptr with edesc->iv_dma and
ipsec_esp_unmap() already unmaps civ_ptr via
unmap_single_talitos_ptr(), calling dma_unmap_single() on edesc->iv_dma
after ipsec_esp_unmap() unmaps the same IV DMA address twice on every
completed AEAD encryption request.
Remove the duplicate dma_unmap_single() call and the now-unused local
variables from ipsec_esp_encrypt_done().
Fixes: 2e13ce0812c6 ("crypto: talitos - DMA map key in setkey()")
Closes: https://sashiko.dev/#/bug/linux-d3edc145-eaef-4da2-b463-3374b9a54d57
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/crypto/talitos.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index 8a9f0d1e7df9..e9af242c7134 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -1097,16 +1097,12 @@ static void ipsec_esp_encrypt_done(struct device *dev,
int err)
{
struct aead_request *areq = context;
- struct crypto_aead *authenc = crypto_aead_reqtfm(areq);
- unsigned int ivsize = crypto_aead_ivsize(authenc);
struct talitos_edesc *edesc;
edesc = container_of(desc, struct talitos_edesc, desc);
ipsec_esp_unmap(dev, edesc, areq, true);
- dma_unmap_single(dev, edesc->iv_dma, ivsize, DMA_TO_DEVICE);
-
kfree(edesc);
aead_request_complete(areq, err);
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 07/10] crypto: safexcel - Check scatterlist errors before max() for in-place
[not found] <20261123151055.2533735-1-lee@kernel.org>
` (5 preceding siblings ...)
2026-11-23 15:09 ` [PATCH 06/10] crypto: talitos - Remove duplicate IV unmap in AEAD encrypt path Lee Jones
@ 2026-11-23 15:09 ` Lee Jones
2026-11-23 15:09 ` [PATCH 08/10] crypto: qce - Pass mapped scatterlist count to qce_dma_prep_sgs() Lee Jones
` (2 subsequent siblings)
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:09 UTC (permalink / raw)
To: lee, Antoine Tenart, Herbert Xu, David S. Miller,
Aleksander Jan Bajkowski, Pascal van Leeuwen, linux-crypto,
linux-kernel
Cc: stable
In safexcel_send_req(), sg_nents_for_len() returns -EINVAL when a
scatterlist is shorter than the required payload length. For in-place
requests (src == dst), the driver combines sreq->nr_src and
sreq->nr_dst using max() before checking for errors.
When an in-place AEAD encryption request provides a scatterlist large
enough for totlen_src (sreq->nr_src > 0) but too short for the
appended authentication tag in totlen_dst (sreq->nr_dst == -EINVAL),
max() selects the positive sreq->nr_src and discards -EINVAL. The
driver then maps only the undersized buffer while programming the
engine token to emit totlen_dst bytes.
Check both sreq->nr_src and sreq->nr_dst for negative error values
before combining them with max().
Fixes: 19b347b32bb1 ("crypto: inside-secure - fix scatter/gather list to descriptor conversion")
Closes: https://sashiko.dev/#/bug/linux-78f87af5-af5e-439c-bb52-de4c8c53fdee
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/crypto/inside-secure/safexcel_cipher.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/crypto/inside-secure/safexcel_cipher.c b/drivers/crypto/inside-secure/safexcel_cipher.c
index b031cb9652ec..e7816f6ddeaa 100644
--- a/drivers/crypto/inside-secure/safexcel_cipher.c
+++ b/drivers/crypto/inside-secure/safexcel_cipher.c
@@ -736,14 +736,13 @@ static int safexcel_send_req(struct crypto_async_request *base, int ring,
queued = totlen_src;
if (src == dst) {
- sreq->nr_src = max(sreq->nr_src, sreq->nr_dst);
- sreq->nr_dst = sreq->nr_src;
- if (unlikely((totlen_src || totlen_dst) &&
- (sreq->nr_src <= 0))) {
+ if (unlikely(sreq->nr_src < 0 || sreq->nr_dst < 0)) {
dev_err(priv->dev, "In-place buffer not large enough (need %d bytes)!",
max(totlen_src, totlen_dst));
return -EINVAL;
}
+ sreq->nr_src = max(sreq->nr_src, sreq->nr_dst);
+ sreq->nr_dst = sreq->nr_src;
if (sreq->nr_src > 0 &&
!dma_map_sg(priv->dev, src, sreq->nr_src, DMA_BIDIRECTIONAL))
return -EIO;
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 08/10] crypto: qce - Pass mapped scatterlist count to qce_dma_prep_sgs()
[not found] <20261123151055.2533735-1-lee@kernel.org>
` (6 preceding siblings ...)
2026-11-23 15:09 ` [PATCH 07/10] crypto: safexcel - Check scatterlist errors before max() for in-place Lee Jones
@ 2026-11-23 15:09 ` Lee Jones
2026-11-23 15:10 ` [PATCH 09/10] crypto: qce - Terminate RX DMA channel if TX preparation fails Lee Jones
2026-11-23 15:10 ` [PATCH 10/10] crypto: atmel-tdes - Update output IV before clearing busy flag Lee Jones
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:09 UTC (permalink / raw)
To: lee, Bartosz Golaszewski, Herbert Xu, David S. Miller,
Thorsten Blum, Stanimir Varbanov, linux-crypto, linux-arm-msm,
linux-kernel
Cc: stable
In qce_ahash_async_req_handle(), dma_map_sg() maps req->src and returns
the number of coalesced DMA segments in ret, which is immediately
overwritten when mapping rctx->result_sg. The function then passes the
unmapped segment count rctx->src_nents to qce_dma_prep_sgs().
When an IOMMU coalesces scatterlist entries so the mapped count is
smaller than rctx->src_nents, dmaengine_prep_slave_sg() walks past the
mapped entries and reads uninitialised DMA addresses and lengths from
the tail of req->src, while dma_unmap_sg() still requires the original
rctx->src_nents count.
Save the mapped segment count from dma_map_sg() in a dedicated
src_nents variable and pass it to qce_dma_prep_sgs(), matching the
skcipher path.
Fixes: ec8f5d8f6f76 ("crypto: qce - Qualcomm crypto engine driver")
Closes: https://sashiko.dev/#/bug/linux-24490c31-257a-4148-a816-0aaf416f64a1
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/crypto/qce/sha.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/crypto/qce/sha.c b/drivers/crypto/qce/sha.c
index b67d749db05f..56106f415db6 100644
--- a/drivers/crypto/qce/sha.c
+++ b/drivers/crypto/qce/sha.c
@@ -77,7 +77,7 @@ static int qce_ahash_async_req_handle(struct crypto_async_request *async_req)
struct qce_alg_template *tmpl = to_ahash_tmpl(async_req->tfm);
struct qce_device *qce = tmpl->qce;
unsigned long flags = rctx->flags;
- int ret;
+ int ret, src_nents;
if (IS_SHA_HMAC(flags)) {
rctx->authkey = ctx->authkey;
@@ -93,8 +93,9 @@ static int qce_ahash_async_req_handle(struct crypto_async_request *async_req)
return rctx->src_nents;
}
- ret = dma_map_sg(qce->dev, req->src, rctx->src_nents, DMA_TO_DEVICE);
- if (!ret)
+ src_nents = dma_map_sg(qce->dev, req->src, rctx->src_nents,
+ DMA_TO_DEVICE);
+ if (!src_nents)
return -EIO;
sg_init_one(&rctx->result_sg, qce->dma.result_buf, QCE_RESULT_BUF_SZ);
@@ -105,7 +106,7 @@ static int qce_ahash_async_req_handle(struct crypto_async_request *async_req)
goto error_unmap_src;
}
- ret = qce_dma_prep_sgs(&qce->dma, req->src, rctx->src_nents,
+ ret = qce_dma_prep_sgs(&qce->dma, req->src, src_nents,
&rctx->result_sg, 1, qce_ahash_done, async_req);
if (ret)
goto error_unmap_dst;
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 09/10] crypto: qce - Terminate RX DMA channel if TX preparation fails
[not found] <20261123151055.2533735-1-lee@kernel.org>
` (7 preceding siblings ...)
2026-11-23 15:09 ` [PATCH 08/10] crypto: qce - Pass mapped scatterlist count to qce_dma_prep_sgs() Lee Jones
@ 2026-11-23 15:10 ` Lee Jones
2026-11-23 15:10 ` [PATCH 10/10] crypto: atmel-tdes - Update output IV before clearing busy flag Lee Jones
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:10 UTC (permalink / raw)
To: lee, Bartosz Golaszewski, Herbert Xu, David S. Miller,
Stanimir Varbanov, linux-crypto, linux-arm-msm, linux-kernel
Cc: stable
qce_dma_prep_sgs() prepares and submits the rxchan DMA descriptor via
qce_dma_prep_sg() before preparing the txchan descriptor. If the
subsequent txchan preparation fails, qce_dma_prep_sgs() returns an
error while leaving the submitted rxchan descriptor queued in the DMA
engine, and callers jump straight to unmapping their scatterlists
without calling qce_dma_terminate_all().
On the next cryptographic request, qce_dma_issue_pending() flushes the
stale rxchan descriptor against already-unmapped memory.
Terminate rxchan via dmaengine_terminate_async() when preparing txchan
fails in qce_dma_prep_sgs().
Fixes: ec8f5d8f6f76 ("crypto: qce - Qualcomm crypto engine driver")
Closes: https://sashiko.dev/#/bug/linux-0b5dbd9f-7869-4856-a8e5-47c2c6e342f1
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/crypto/qce/dma.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/crypto/qce/dma.c b/drivers/crypto/qce/dma.c
index 68cafd4741ad..726e7fd3421e 100644
--- a/drivers/crypto/qce/dma.c
+++ b/drivers/crypto/qce/dma.c
@@ -116,8 +116,12 @@ int qce_dma_prep_sgs(struct qce_dma_data *dma, struct scatterlist *rx_sg,
if (ret)
return ret;
- return qce_dma_prep_sg(txchan, tx_sg, tx_nents, flags, DMA_DEV_TO_MEM,
- cb, cb_param);
+ ret = qce_dma_prep_sg(txchan, tx_sg, tx_nents, flags, DMA_DEV_TO_MEM,
+ cb, cb_param);
+ if (ret)
+ dmaengine_terminate_async(rxchan);
+
+ return ret;
}
void qce_dma_issue_pending(struct qce_dma_data *dma)
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 10/10] crypto: atmel-tdes - Update output IV before clearing busy flag
[not found] <20261123151055.2533735-1-lee@kernel.org>
` (8 preceding siblings ...)
2026-11-23 15:10 ` [PATCH 09/10] crypto: qce - Terminate RX DMA channel if TX preparation fails Lee Jones
@ 2026-11-23 15:10 ` Lee Jones
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:10 UTC (permalink / raw)
To: lee, Herbert Xu, David S. Miller, Nicolas Ferre,
Alexandre Belloni, Claudiu Beznea, Thorsten Blum, Nicolas Royer,
Tudor Ambarus, linux-crypto, linux-arm-kernel, linux-kernel
Cc: stable
In atmel_tdes_finish_req(), dd->flags clears TDES_FLAGS_BUSY without
holding dd->lock and before calling
atmel_tdes_set_iv_as_last_ciphertext_block().
As soon as TDES_FLAGS_BUSY is cleared, a concurrent
atmel_tdes_handle_queue() caller on another CPU can dequeue the next
request and overwrite dd->req (as well as modify dd->flags). When
atmel_tdes_set_iv_as_last_ciphertext_block() then reads dd->req, it
overwrites the newly dequeued request's IV with the previous request's
ciphertext and leaves the completed request's output IV un-updated.
Update the output IV before clearing TDES_FLAGS_BUSY, and clear
TDES_FLAGS_BUSY under dd->lock to serialise flag updates with
atmel_tdes_handle_queue().
Fixes: 61b0dd664fa1 ("crypto: atmel-tdes - Set the IV after {en,de}crypt")
Closes: https://sashiko.dev/#/bug/linux-d6fd6f42-d6fc-47d0-86d5-f428e2203a64
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/crypto/atmel-tdes.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/crypto/atmel-tdes.c b/drivers/crypto/atmel-tdes.c
index c86d06169ab9..392a2a3a8b85 100644
--- a/drivers/crypto/atmel-tdes.c
+++ b/drivers/crypto/atmel-tdes.c
@@ -504,14 +504,17 @@ static void atmel_tdes_finish_req(struct atmel_tdes_dev *dd, int err)
{
struct skcipher_request *req = dd->req;
struct atmel_tdes_reqctx *rctx = skcipher_request_ctx(req);
+ unsigned long flags;
clk_disable_unprepare(dd->iclk);
- dd->flags &= ~TDES_FLAGS_BUSY;
-
if (!err && (rctx->mode & TDES_FLAGS_OPMODE_MASK) != TDES_FLAGS_ECB)
atmel_tdes_set_iv_as_last_ciphertext_block(dd);
+ spin_lock_irqsave(&dd->lock, flags);
+ dd->flags &= ~TDES_FLAGS_BUSY;
+ spin_unlock_irqrestore(&dd->lock, flags);
+
skcipher_request_complete(req, err);
}
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread