Skip to content

Commit

Permalink
crypto: algif_hash - Fix NULL hash crash with shash
Browse files Browse the repository at this point in the history
Recently algif_hash has been changed to allow null hashes.  This
triggers a bug when used with an shash algorithm whereby it will
cause a crash during the digest operation.

This patch fixes it by avoiding the digest operation and instead
doing an init followed by a final which avoids the buggy code in
shash.

This patch also ensures that the result buffer is freed after an
error so that it is not returned as a genuine hash result on the
next recv call.

The shash/ahash wrapper code will be fixed later to handle this
case correctly.

Fixes: 493b2ed ("crypto: algif_hash - Handle NULL hashes correctly")
Signed-off-by: Herbert Xu <[email protected]>
Tested-by: Laura Abbott <[email protected]>
  • Loading branch information
herbertx committed Nov 18, 2016
1 parent a5a40d4 commit a8348bc
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions crypto/algif_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,23 +214,26 @@ static int hash_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,

ahash_request_set_crypt(&ctx->req, NULL, ctx->result, 0);

if (ctx->more) {
if (!result) {
err = af_alg_wait_for_completion(
crypto_ahash_init(&ctx->req),
&ctx->completion);
if (err)
goto unlock;
}

if (!result || ctx->more) {
ctx->more = 0;
err = af_alg_wait_for_completion(crypto_ahash_final(&ctx->req),
&ctx->completion);
if (err)
goto unlock;
} else if (!result) {
err = af_alg_wait_for_completion(
crypto_ahash_digest(&ctx->req),
&ctx->completion);
}

err = memcpy_to_msg(msg, ctx->result, len);

hash_free_result(sk, ctx);

unlock:
hash_free_result(sk, ctx);
release_sock(sk);

return err ?: len;
Expand Down

0 comments on commit a8348bc

Please sign in to comment.