[PATCH 04/10] crypto: sun8i-ss - Fix scatterlist array overflow for HMAC requests
From: Lee Jones
Date: Mon Nov 23 2026 - 10:12:28 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
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