* [PATCH 04/10] crypto: sun8i-ss - Fix scatterlist array overflow for HMAC requests
[not found] <20261123151055.2533735-1-lee@kernel.org>
@ 2026-11-23 15:09 ` Lee Jones
2026-11-23 15:10 ` [PATCH 10/10] crypto: atmel-tdes - Update output IV before clearing busy flag Lee Jones
1 sibling, 0 replies; 2+ 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] 2+ messages in thread* [PATCH 10/10] crypto: atmel-tdes - Update output IV before clearing busy flag
[not found] <20261123151055.2533735-1-lee@kernel.org>
2026-11-23 15:09 ` [PATCH 04/10] crypto: sun8i-ss - Fix scatterlist array overflow for HMAC requests Lee Jones
@ 2026-11-23 15:10 ` Lee Jones
1 sibling, 0 replies; 2+ 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] 2+ messages in thread