[PATCH] crypto: af_alg/hash: Report errors that discard hash state

From: Mark Amirkan via B4 Relay

Date: Sat Sep 12 2026 - 04:19:11 EST


From: Mark Amirkan <markdamirkan@xxxxxxxxx>

hash_sendmsg() processes large requests in several batches. If a later
batch fails, the common error path calls hash_free_result() and clears
ctx->more. The next operation therefore starts a new hash request.

The function nevertheless returns the number of bytes processed by earlier
batches. With failslab, a 262144-byte SHA-1 send without MSG_MORE returns
262128 when the result allocation fails. A digest read then returns the
digest of an empty input. Retrying the last 16 bytes instead returns the
digest of only those 16 bytes.

Return the error whenever the request state is discarded. This also
restores the error-first behavior used before the request batching code was
reworked.

Fixes: c662b043cdca ("crypto: af_alg/hash: Support MSG_SPLICE_PAGES")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: Symbolic
Signed-off-by: Mark Amirkan <markdamirkan@xxxxxxxxx>
---
crypto/algif_hash.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c
index 6e8b5fb82a7f1..7c1910c370ad6 100644
--- a/crypto/algif_hash.c
+++ b/crypto/algif_hash.c
@@ -184,7 +184,7 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg,
err = 0;
unlock:
release_sock(sk);
- return copied ?: err;
+ return err ?: copied;

unlock_free:
af_alg_free_sg(&ctx->sgl);

---
base-commit: 5225b8eec4c9bb21aecff6295fab6346a3c3738e
change-id: 20260912-afalg-b4-send-20260912-629e04ff0b51

Best regards,
--
Mark Amirkan <markdamirkan@xxxxxxxxx>