crypto: drbg - make drbg_prepare_hrng() handle jent instantiation errors

[ Upstream commit 559edd47cc ]

Now that drbg_prepare_hrng() doesn't do anything but to instantiate a
jitterentropy crypto_rng instance, it looks a little odd to have the
related error handling at its only caller, drbg_instantiate().

Move the handling of jitterentropy allocation failures from
drbg_instantiate() close to the allocation itself in drbg_prepare_hrng().

There is no change in behaviour.

Signed-off-by: Nicolai Stange <nstange@suse.de>
Reviewed-by: Stephan Müller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Stable-dep-of: 686cd976b6 ("crypto: drbg - Only fail when jent is unavailable in FIPS mode")
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Nicolai Stange 2021-11-15 15:18:08 +01:00 коммит произвёл Greg Kroah-Hartman
Родитель 80bfd8b184
Коммит 9317d66120
1 изменённых файлов: 8 добавлений и 8 удалений

Просмотреть файл

@ -1516,6 +1516,14 @@ static int drbg_prepare_hrng(struct drbg_state *drbg)
return 0; return 0;
drbg->jent = crypto_alloc_rng("jitterentropy_rng", 0, 0); drbg->jent = crypto_alloc_rng("jitterentropy_rng", 0, 0);
if (IS_ERR(drbg->jent)) {
const int err = PTR_ERR(drbg->jent);
drbg->jent = NULL;
if (fips_enabled || err != -ENOENT)
return err;
pr_info("DRBG: Continuing without Jitter RNG\n");
}
return 0; return 0;
} }
@ -1571,14 +1579,6 @@ static int drbg_instantiate(struct drbg_state *drbg, struct drbg_string *pers,
if (ret) if (ret)
goto free_everything; goto free_everything;
if (IS_ERR(drbg->jent)) {
ret = PTR_ERR(drbg->jent);
drbg->jent = NULL;
if (fips_enabled || ret != -ENOENT)
goto free_everything;
pr_info("DRBG: Continuing without Jitter RNG\n");
}
reseed = false; reseed = false;
} }