diff options
author | Neil Brown <neilb@suse.de> | 2005-06-07 23:03:48 +0000 |
---|---|---|
committer | Neil Brown <neilb@suse.de> | 2005-06-07 23:03:48 +0000 |
commit | dfe47e008e10d5640c6b3d0ae6de7ef6cefcb7b2 (patch) | |
tree | 0fd6aa40bd1559c813eab17392936bdaf2514a1f | |
parent | 892debc8200517e8b00750367acd890199f9f4de (diff) | |
download | mdadm-dfe47e008e10d5640c6b3d0ae6de7ef6cefcb7b2.tar.gz mdadm-dfe47e008e10d5640c6b3d0ae6de7ef6cefcb7b2.tar.xz mdadm-dfe47e008e10d5640c6b3d0ae6de7ef6cefcb7b2.zip |
Make sure to seed the random number generator for uuids
Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au>
-rw-r--r-- | mdadm.c | 2 | ||||
-rw-r--r-- | super0.c | 15 | ||||
-rw-r--r-- | super1.c | 13 |
3 files changed, 22 insertions, 8 deletions
@@ -93,6 +93,8 @@ int main(int argc, char *argv[]) int mdfd = -1; + srandom(time(0) ^ getpid()); + ident.uuid_set=0; ident.level = UnSet; ident.raid_disks = UnSet; @@ -326,6 +326,7 @@ static int init_super0(void **sbp, mdu_array_info_t *info) { mdp_super_t *sb = malloc(MD_SB_BYTES); int spares; + int rfd; memset(sb, 0, MD_SB_BYTES); if (info->major_version == -1) { @@ -340,12 +341,14 @@ static int init_super0(void **sbp, mdu_array_info_t *info) return 0; } + rfd = open("/dev/urandom", O_RDONLY); sb->md_magic = MD_SB_MAGIC; sb->major_version = 0; sb->minor_version = 90; sb->patch_version = 0; sb->gvalid_words = 0; /* ignored */ - sb->set_uuid0 = random(); + if (rfd < 0 || read(rfd, &sb->set_uuid0, 4) != 4) + sb->set_uuid0 = random(); sb->ctime = time(0); sb->level = info->level; sb->size = info->size; @@ -353,9 +356,13 @@ static int init_super0(void **sbp, mdu_array_info_t *info) sb->raid_disks = info->raid_disks; sb->md_minor = info->md_minor; sb->not_persistent = 0; - sb->set_uuid1 = random(); - sb->set_uuid2 = random(); - sb->set_uuid3 = random(); + if (rfd < 0 || read(rfd, &sb->set_uuid1, 12) != 12) { + sb->set_uuid1 = random(); + sb->set_uuid2 = random(); + sb->set_uuid3 = random(); + } + if (rfd >= 0) + close(rfd); sb->utime = sb->ctime; sb->state = info->state; @@ -466,6 +466,7 @@ static int write_init_super1(struct supertype *st, void *sbv, mdu_disk_info_t *d struct mdp_superblock_1 *sb = sbv; struct mdp_superblock_1 *refsb = NULL; int fd = open(devname, O_RDWR | O_EXCL); + int rfd; int rv; long size; @@ -480,10 +481,14 @@ static int write_init_super1(struct supertype *st, void *sbv, mdu_disk_info_t *d sb->dev_number = __cpu_to_le32(dinfo->number); - *(__u32*)(sb->device_uuid) = random(); - *(__u32*)(sb->device_uuid+4) = random(); - *(__u32*)(sb->device_uuid+8) = random(); - *(__u32*)(sb->device_uuid+12) = random(); + if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 || + read(rfd, sb->device_uuid, 16) != 16) { + *(__u32*)(sb->device_uuid) = random(); + *(__u32*)(sb->device_uuid+4) = random(); + *(__u32*)(sb->device_uuid+8) = random(); + *(__u32*)(sb->device_uuid+12) = random(); + } + if (rfd >= 0) close(rfd); sb->events = 0; if (load_super1(st, fd, (void**)&refsb, NULL)==0) { |