提交 30d0f6a9 编写于 作者: E Eric Biggers 提交者: Herbert Xu

crypto: rng - fix crypto_rng_reset() refcounting when !CRYPTO_STATS

crypto_stats_get() is a no-op when the kernel is compiled without
CONFIG_CRYPTO_STATS, so pairing it with crypto_alg_put() unconditionally
(as crypto_rng_reset() does) is wrong.

Fix this by moving the call to crypto_stats_get() to just before the
actual algorithm operation which might need it.  This makes it always
paired with crypto_stats_rng_seed().

Fixes: eed74b3e ("crypto: rng - Fix a refcounting bug in crypto_rng_reset()")
Cc: stable@vger.kernel.org
Signed-off-by: NEric Biggers <ebiggers@google.com>
Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
上级 10cb823b
...@@ -34,22 +34,18 @@ int crypto_rng_reset(struct crypto_rng *tfm, const u8 *seed, unsigned int slen) ...@@ -34,22 +34,18 @@ int crypto_rng_reset(struct crypto_rng *tfm, const u8 *seed, unsigned int slen)
u8 *buf = NULL; u8 *buf = NULL;
int err; int err;
crypto_stats_get(alg);
if (!seed && slen) { if (!seed && slen) {
buf = kmalloc(slen, GFP_KERNEL); buf = kmalloc(slen, GFP_KERNEL);
if (!buf) { if (!buf)
crypto_alg_put(alg);
return -ENOMEM; return -ENOMEM;
}
err = get_random_bytes_wait(buf, slen); err = get_random_bytes_wait(buf, slen);
if (err) { if (err)
crypto_alg_put(alg);
goto out; goto out;
}
seed = buf; seed = buf;
} }
crypto_stats_get(alg);
err = crypto_rng_alg(tfm)->seed(tfm, seed, slen); err = crypto_rng_alg(tfm)->seed(tfm, seed, slen);
crypto_stats_rng_seed(alg, err); crypto_stats_rng_seed(alg, err);
out: out:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册