Skip to content

Commit

Permalink
random: printk notifications for urandom pool initialization
Browse files Browse the repository at this point in the history
Print a notification to the console when the nonblocking pool is
initialized.  Also printk a warning when a process tries reading from
/dev/urandom before it is fully initialized.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
  • Loading branch information
Theodore Ts'o committed Nov 3, 2013
1 parent 40db23e commit 301f059
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion drivers/char/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,9 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)
r->entropy_total += nbits;
if (!r->initialized && nbits > 0) {
if (r->entropy_total > 128) {
if (r == &nonblocking_pool)
pr_notice("random: %s pool is initialized\n",
r->name);
r->initialized = 1;
r->entropy_total = 0;
}
Expand Down Expand Up @@ -1327,7 +1330,14 @@ random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
static ssize_t
urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
{
int ret = extract_entropy_user(&nonblocking_pool, buf, nbytes);
int ret;

if (unlikely(nonblocking_pool.initialized == 0))
printk_once(KERN_NOTICE "random: %s urandom read "
"with %d bits of entropy available\n",
current->comm, nonblocking_pool.entropy_total);

ret = extract_entropy_user(&nonblocking_pool, buf, nbytes);

trace_urandom_read(8 * nbytes, ENTROPY_BITS(&nonblocking_pool),
ENTROPY_BITS(&input_pool));
Expand Down

0 comments on commit 301f059

Please sign in to comment.