Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

hwrng: core - credit entropy for low quality sources of randomness

In case the entropy quality is low, there may be less than one bit to
credit in the call to add_hwgenerator_randomness(): The number of bytes
returned by rng_get_data() multiplied by the current quality (in entropy
bits per 1024 bits of input) must be larger than 128 to credit at least
one bit. However, imx-rngc.c sets the quality to 19, but may return less
than 32 bytes; hid_u2fzero.c sets the quality to 1; and users may override
the quality setting manually.

In case there is less than one bit to credit, keep track of it and add
that credit to the next iteration.

Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Dominik Brodowski and committed by
Herbert Xu
a43bed82 dfc6031e

+10 -1
+10 -1
drivers/char/hw_random/core.c
··· 424 424 425 425 static int hwrng_fillfn(void *unused) 426 426 { 427 + size_t entropy, entropy_credit = 0; /* in 1/1024 of a bit */ 427 428 long rc; 428 429 429 430 while (!kthread_should_stop()) { ··· 446 445 msleep_interruptible(10000); 447 446 continue; 448 447 } 448 + 449 + /* If we cannot credit at least one bit of entropy, 450 + * keep track of the remainder for the next iteration 451 + */ 452 + entropy = rc * current_quality * 8 + entropy_credit; 453 + if ((entropy >> 10) == 0) 454 + entropy_credit = entropy; 455 + 449 456 /* Outside lock, sure, but y'know: randomness. */ 450 457 add_hwgenerator_randomness((void *)rng_fillbuf, rc, 451 - rc * current_quality * 8 >> 10); 458 + entropy >> 10); 452 459 } 453 460 hwrng_fill = NULL; 454 461 return 0;