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

From: Herbert Xu

Date: Fri Sep 18 2026 - 05:50:19 EST


On Sat, Sep 12, 2026 at 01:11:14AM -0700, Mark Amirkan via B4 Relay wrote:
> 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;

This could be simplified to:

err = copied;
unlock:
release_sock(sk);
return err;

Thanks,
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt