Skip to content

Commit 392a546

Browse files
committed
random: add debugging code to detect early use of get_random_bytes()
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 644008d commit 392a546

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎drivers/char/random.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@
280280
#define SEC_XFER_SIZE 512
281281
#define EXTRACT_SIZE 10
282282

283+
#define DEBUG_RANDOM_BOOT 0
284+
283285
#define LONGS(x) (((x) + sizeof(unsigned long) - 1)/sizeof(unsigned long))
284286

285287
/*
@@ -1177,6 +1179,13 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
11771179
*/
11781180
void get_random_bytes(void *buf, int nbytes)
11791181
{
1182+
#if DEBUG_RANDOM_BOOT > 0
1183+
if (unlikely(nonblocking_pool.initialized == 0))
1184+
printk(KERN_NOTICE "random: %pF get_random_bytes called "
1185+
"with %d bits of entropy available\n",
1186+
(void *) _RET_IP_,
1187+
nonblocking_pool.entropy_total);
1188+
#endif
11801189
trace_get_random_bytes(nbytes, _RET_IP_);
11811190
extract_entropy(&nonblocking_pool, buf, nbytes, 0, 0);
11821191
}

0 commit comments

Comments
 (0)