Skip to content

Commit ae9ecd9

Browse files
committed
random: don't zap entropy count in rand_initialize()
The rand_initialize() function was being run fairly late in the kernel boot sequence. This was unfortunate, since it zero'ed the entropy counters, thus throwing away credit that was accumulated earlier in the boot sequence, and it also meant that initcall functions run before rand_initialize were using a minimally initialized pool. To fix this, fix init_std_data() to no longer zap the entropy counter; it wasn't necessary, and move rand_initialize() to be an early initcall. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 301f059 commit ae9ecd9

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

‎drivers/char/random.c‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,14 +1228,11 @@ static void init_std_data(struct entropy_store *r)
12281228
ktime_t now = ktime_get_real();
12291229
unsigned long rv;
12301230

1231-
r->entropy_count = 0;
1232-
r->entropy_total = 0;
1233-
r->last_data_init = 0;
12341231
r->last_pulled = jiffies;
12351232
mix_pool_bytes(r, &now, sizeof(now), NULL);
12361233
for (i = r->poolinfo->poolbytes; i > 0; i -= sizeof(rv)) {
12371234
if (!arch_get_random_long(&rv))
1238-
break;
1235+
rv = random_get_entropy();
12391236
mix_pool_bytes(r, &rv, sizeof(rv), NULL);
12401237
}
12411238
mix_pool_bytes(r, utsname(), sizeof(*(utsname())), NULL);
@@ -1258,7 +1255,7 @@ static int rand_initialize(void)
12581255
init_std_data(&nonblocking_pool);
12591256
return 0;
12601257
}
1261-
module_init(rand_initialize);
1258+
early_initcall(rand_initialize);
12621259

12631260
#ifdef CONFIG_BLOCK
12641261
void rand_initialize_disk(struct gendisk *disk)
@@ -1433,10 +1430,15 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
14331430
return 0;
14341431
case RNDZAPENTCNT:
14351432
case RNDCLEARPOOL:
1436-
/* Clear the entropy pool counters. */
1433+
/*
1434+
* Clear the entropy pool counters. We no longer clear
1435+
* the entropy pool, as that's silly.
1436+
*/
14371437
if (!capable(CAP_SYS_ADMIN))
14381438
return -EPERM;
1439-
rand_initialize();
1439+
input_pool.entropy_count = 0;
1440+
nonblocking_pool.entropy_count = 0;
1441+
blocking_pool.entropy_count = 0;
14401442
return 0;
14411443
default:
14421444
return -EINVAL;

0 commit comments

Comments
 (0)