Skip to contentSkip to conversation

ext2/3: use prandom_u32() instead of get_random_bytes()

PATCH In review ZhangZhen 2 participants 2 messages Feb 26, 2014 1 message not in the archive ext2 file system

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

ZhangZhen

author
#1 lore raw

PATCH 1/1 ext2/3: 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.

The commit dd1f723bf56bd96efc9d90e9e60dc511c79de48f has made that for ext4, and i did the same for ext2/3.

---
 fs/ext2/ialloc.c | 2 +-
 fs/ext3/ialloc.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
fs/ext2/ialloc.c +1 -1
index 7cadd82..32f131a 100644
@@ -284,7 +284,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
 		int best_ndir = inodes_per_group;
 		int best_group = -1;
 
-		get_random_bytes(&group, sizeof(group));
+		grp = prandom_u32();
 		parent_group = (unsigned)group % ngroups;
 		for (i = 0; i < ngroups; i++) {
 			group = (parent_group + i) % ngroups;
fs/ext3/ialloc.c +1 -1
index 082afd7..60e63e3 100644
@@ -215,7 +215,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
 		int best_ndir = inodes_per_group;
 		int best_group = -1;
 
-		get_random_bytes(&group, sizeof(group));
+		grp = prandom_u32();
 		parent_group = (unsigned)group % ngroups;
 		for (i = 0; i < ngroups; i++) {
 			group = (parent_group + i) % ngroups;
Signature · 4 lines
1.8.1.4


.
#2 lore raw
Quoted 7 lines · ZhangZhen

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.

The commit dd1f723bf56bd96efc9d90e9e60dc511c79de48f has made that for ext4, and i did the same for ext2/3.

Thanks. I've merged the patch to my tree.

Honza

Quoted 42 lines
---
 fs/ext2/ialloc.c | 2 +-
 fs/ext3/ialloc.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
fs/ext2/ialloc.c +1 -1
index 7cadd82..32f131a 100644
@@ -284,7 +284,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
 		int best_ndir = inodes_per_group;
 		int best_group = -1;
 
-		get_random_bytes(&group, sizeof(group));
+		grp = prandom_u32();
 		parent_group = (unsigned)group % ngroups;
 		for (i = 0; i < ngroups; i++) {
 			group = (parent_group + i) % ngroups;
fs/ext3/ialloc.c +1 -1
index 082afd7..60e63e3 100644
@@ -215,7 +215,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
 		int best_ndir = inodes_per_group;
 		int best_group = -1;
 
-		get_random_bytes(&group, sizeof(group));
+		grp = prandom_u32();
 		parent_group = (unsigned)group % ngroups;
 		for (i = 0; i < ngroups; i++) {
 			group = (parent_group + i) % ngroups;
Signature · 4 lines
1.8.1.4


.
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR