[PATCH] crypto: ahash - Zero positive err value in ahash_update_finish

From: Herbert Xu

Date: Fri Nov 21 2025 - 00:54:26 EST


On Thu, Nov 13, 2025 at 07:30:13PM +0530, T Pratham wrote:
>
> Commit 9d7a0ab1c7536 ("crypto: ahash - Handle partial blocks in API")
> introduced partial block handling for ahashes in the crypto API layer itself.
> This enables ahash algorithms to return a positive integer from the update
> function to indicate the number of bytes in the input which are not processed
> and should be buffered for next update/finup/final call to process.

Thanks for the report!

This is a bug in the ahash API code, it should return zero instead
of the positive value.

---8<---
The partial block length returned by a block-only driver should
not be passed up to the caller since ahash itself deals with the
partial block data.

Set err to zero in ahash_update_finish if it was positive.

Reported-by: T Pratham <t-pratham@xxxxxx>
Fixes: 9d7a0ab1c753 ("crypto: ahash - Handle partial blocks in API")
Signed-off-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>

diff --git a/crypto/ahash.c b/crypto/ahash.c
index dfb4f5476428..e3d0736e9afe 100644
--- a/crypto/ahash.c
+++ b/crypto/ahash.c
@@ -423,7 +423,11 @@ static int ahash_update_finish(struct ahash_request *req, int err)

req->nbytes += nonzero - blen;

- blen = err < 0 ? 0 : err + nonzero;
+ blen = 0;
+ if (err >= 0) {
+ blen = err + nonzero;
+ err = 0;
+ }
if (ahash_request_isvirt(req))
memcpy(buf, req->svirt + req->nbytes - blen, blen);
else
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt