mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-31 08:28:13 +00:00
random: fix locking in crng_fast_load()
commit 7c2fe2b32b
upstream.
crng_init is protected by primary_crng->lock, so keep holding that lock
when incrementing crng_init from 0 to 1 in crng_fast_load(). The call to
pr_notice() can wait until the lock is released; this code path cannot
be reached twice, as crng_fast_load() aborts early if crng_init > 0.
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Reviewed-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
048d57faf9
commit
ba20054937
1 changed files with 3 additions and 2 deletions
|
@ -647,12 +647,13 @@ static size_t crng_fast_load(const u8 *cp, size_t len)
|
||||||
p[crng_init_cnt % CHACHA_KEY_SIZE] ^= *cp;
|
p[crng_init_cnt % CHACHA_KEY_SIZE] ^= *cp;
|
||||||
cp++; crng_init_cnt++; len--; ret++;
|
cp++; crng_init_cnt++; len--; ret++;
|
||||||
}
|
}
|
||||||
spin_unlock_irqrestore(&primary_crng.lock, flags);
|
|
||||||
if (crng_init_cnt >= CRNG_INIT_CNT_THRESH) {
|
if (crng_init_cnt >= CRNG_INIT_CNT_THRESH) {
|
||||||
invalidate_batched_entropy();
|
invalidate_batched_entropy();
|
||||||
crng_init = 1;
|
crng_init = 1;
|
||||||
pr_notice("fast init done\n");
|
|
||||||
}
|
}
|
||||||
|
spin_unlock_irqrestore(&primary_crng.lock, flags);
|
||||||
|
if (crng_init == 1)
|
||||||
|
pr_notice("fast init done\n");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue