Skip to content

Commit dd1f723

Browse files
committed
ext4: use prandom_u32() instead of get_random_bytes()
Many of the uses of get_random_bytes() do not actually need cryptographically secure random numbers. Replace those uses with a call to prandom_u32(), which is faster and which doesn't consume entropy from the /dev/random driver. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent f275411 commit dd1f723

3 files changed

Lines changed: 4 additions & 7 deletions

File tree

‎fs/ext4/ialloc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
432432
ext4fs_dirhash(qstr->name, qstr->len, &hinfo);
433433
grp = hinfo.hash;
434434
} else
435-
get_random_bytes(&grp, sizeof(grp));
435+
grp = prandom_u32();
436436
parent_group = (unsigned)grp % ngroups;
437437
for (i = 0; i < ngroups; i++) {
438438
g = (parent_group + i) % ngroups;

‎fs/ext4/mmp.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ static unsigned int mmp_new_seq(void)
259259
u32 new_seq;
260260

261261
do {
262-
get_random_bytes(&new_seq, sizeof(u32));
262+
new_seq = prandom_u32();
263263
} while (new_seq > EXT4_MMP_SEQ_MAX);
264264

265265
return new_seq;

‎fs/ext4/super.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3068,7 +3068,6 @@ static struct ext4_li_request *ext4_li_request_new(struct super_block *sb,
30683068
{
30693069
struct ext4_sb_info *sbi = EXT4_SB(sb);
30703070
struct ext4_li_request *elr;
3071-
unsigned long rnd;
30723071

30733072
elr = kzalloc(sizeof(*elr), GFP_KERNEL);
30743073
if (!elr)
@@ -3083,10 +3082,8 @@ static struct ext4_li_request *ext4_li_request_new(struct super_block *sb,
30833082
* spread the inode table initialization requests
30843083
* better.
30853084
*/
3086-
get_random_bytes(&rnd, sizeof(rnd));
3087-
elr->lr_next_sched = jiffies + (unsigned long)rnd %
3088-
(EXT4_DEF_LI_MAX_START_DELAY * HZ);
3089-
3085+
elr->lr_next_sched = jiffies + (prandom_u32() %
3086+
(EXT4_DEF_LI_MAX_START_DELAY * HZ));
30903087
return elr;
30913088
}
30923089

0 commit comments

Comments
 (0)