]> Pileus Git - ~andy/linux/commitdiff
random: printk notifications for urandom pool initialization
authorTheodore Ts'o <tytso@mit.edu>
Sun, 3 Nov 2013 11:54:51 +0000 (06:54 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 3 Nov 2013 23:18:48 +0000 (18:18 -0500)
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>
drivers/char/random.c

index 62923138e77a6e2de7f5cf5116cea37c4d7b065d..a19a7a63ec3589fccccb856cf8ea978cf5e7e44a 100644 (file)
@@ -655,6 +655,9 @@ retry:
        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;
                }
@@ -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));