Commit b32a7dc8 authored by Eric Biggers's avatar Eric Biggers Committed by Herbert Xu

crypto: algif_aead - fix reference counting of null skcipher

In the AEAD interface for AF_ALG, the reference to the "null skcipher"
held by each tfm was being dropped in the wrong place -- when each
af_alg_ctx was freed instead of when the aead_tfm was freed.  As
discovered by syzkaller, a specially crafted program could use this to
cause the null skcipher to be freed while it is still in use.

Fix it by dropping the reference in the right place.

Fixes: 72548b09 ("crypto: algif_aead - copy AAD from src to dst")
Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
Cc: <stable@vger.kernel.org> # v4.14+
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Reviewed-by: default avatarStephan Mueller <smueller@chronox.de>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent d2890c37
...@@ -487,6 +487,7 @@ static void aead_release(void *private) ...@@ -487,6 +487,7 @@ static void aead_release(void *private)
struct aead_tfm *tfm = private; struct aead_tfm *tfm = private;
crypto_free_aead(tfm->aead); crypto_free_aead(tfm->aead);
crypto_put_default_null_skcipher2();
kfree(tfm); kfree(tfm);
} }
...@@ -519,7 +520,6 @@ static void aead_sock_destruct(struct sock *sk) ...@@ -519,7 +520,6 @@ static void aead_sock_destruct(struct sock *sk)
unsigned int ivlen = crypto_aead_ivsize(tfm); unsigned int ivlen = crypto_aead_ivsize(tfm);
af_alg_pull_tsgl(sk, ctx->used, NULL, 0); af_alg_pull_tsgl(sk, ctx->used, NULL, 0);
crypto_put_default_null_skcipher2();
sock_kzfree_s(sk, ctx->iv, ivlen); sock_kzfree_s(sk, ctx->iv, ivlen);
sock_kfree_s(sk, ctx, ctx->len); sock_kfree_s(sk, ctx, ctx->len);
af_alg_release_parent(sk); af_alg_release_parent(sk);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment