Skip to content

Commit 24c890d

Browse files
committed
crypto: algif_hash - Remove bogus SGL free on zero-length error path
When a zero-length message is hashed by algif_hash, and an error is triggered, it tries to free an SG list that was never allocated in the first place. Fix this by not freeing the SG list on the zero-length error path. Reported-by: Shigeru Yoshida <syoshida@redhat.com> Reported-by: xingwei lee <xrivendell7@gmail.com> Fixes: b6d972f ("crypto: af_alg/hash: Fix recvmsg() after sendmsg(MSG_MORE)") Cc: <stable@vger.kernel.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Reported-by: syzbot+3266db0c26d1fbbe3abb@syzkaller.appspotmail.com Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 69fba37 commit 24c890d

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

crypto/algif_hash.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg,
9191
if (!(msg->msg_flags & MSG_MORE)) {
9292
err = hash_alloc_result(sk, ctx);
9393
if (err)
94-
goto unlock_free;
94+
goto unlock_free_result;
9595
ahash_request_set_crypt(&ctx->req, NULL,
9696
ctx->result, 0);
9797
err = crypto_wait_req(crypto_ahash_final(&ctx->req),
9898
&ctx->wait);
9999
if (err)
100-
goto unlock_free;
100+
goto unlock_free_result;
101101
}
102102
goto done_more;
103103
}
@@ -170,6 +170,7 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg,
170170

171171
unlock_free:
172172
af_alg_free_sg(&ctx->sgl);
173+
unlock_free_result:
173174
hash_free_result(sk, ctx);
174175
ctx->more = false;
175176
goto unlock;

0 commit comments

Comments
 (0)