Skip to content

Commit a8348bc

Browse files
committed
crypto: algif_hash - Fix NULL hash crash with shash
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 <herbert@gondor.apana.org.au> Tested-by: Laura Abbott <labbott@redhat.com>
1 parent a5a40d4 commit a8348bc

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

crypto/algif_hash.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,23 +214,26 @@ static int hash_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
214214

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

217-
if (ctx->more) {
217+
if (!result) {
218+
err = af_alg_wait_for_completion(
219+
crypto_ahash_init(&ctx->req),
220+
&ctx->completion);
221+
if (err)
222+
goto unlock;
223+
}
224+
225+
if (!result || ctx->more) {
218226
ctx->more = 0;
219227
err = af_alg_wait_for_completion(crypto_ahash_final(&ctx->req),
220228
&ctx->completion);
221229
if (err)
222230
goto unlock;
223-
} else if (!result) {
224-
err = af_alg_wait_for_completion(
225-
crypto_ahash_digest(&ctx->req),
226-
&ctx->completion);
227231
}
228232

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

231-
hash_free_result(sk, ctx);
232-
233235
unlock:
236+
hash_free_result(sk, ctx);
234237
release_sock(sk);
235238

236239
return err ?: len;

0 commit comments

Comments
 (0)