Make sure to seed the random number generator for uuids
Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au>
This commit is contained in:
parent
892debc820
commit
dfe47e008e
2
mdadm.c
2
mdadm.c
|
@ -93,6 +93,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
int mdfd = -1;
|
int mdfd = -1;
|
||||||
|
|
||||||
|
srandom(time(0) ^ getpid());
|
||||||
|
|
||||||
ident.uuid_set=0;
|
ident.uuid_set=0;
|
||||||
ident.level = UnSet;
|
ident.level = UnSet;
|
||||||
ident.raid_disks = UnSet;
|
ident.raid_disks = UnSet;
|
||||||
|
|
15
super0.c
15
super0.c
|
@ -326,6 +326,7 @@ static int init_super0(void **sbp, mdu_array_info_t *info)
|
||||||
{
|
{
|
||||||
mdp_super_t *sb = malloc(MD_SB_BYTES);
|
mdp_super_t *sb = malloc(MD_SB_BYTES);
|
||||||
int spares;
|
int spares;
|
||||||
|
int rfd;
|
||||||
memset(sb, 0, MD_SB_BYTES);
|
memset(sb, 0, MD_SB_BYTES);
|
||||||
|
|
||||||
if (info->major_version == -1) {
|
if (info->major_version == -1) {
|
||||||
|
@ -340,12 +341,14 @@ static int init_super0(void **sbp, mdu_array_info_t *info)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rfd = open("/dev/urandom", O_RDONLY);
|
||||||
sb->md_magic = MD_SB_MAGIC;
|
sb->md_magic = MD_SB_MAGIC;
|
||||||
sb->major_version = 0;
|
sb->major_version = 0;
|
||||||
sb->minor_version = 90;
|
sb->minor_version = 90;
|
||||||
sb->patch_version = 0;
|
sb->patch_version = 0;
|
||||||
sb->gvalid_words = 0; /* ignored */
|
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->ctime = time(0);
|
||||||
sb->level = info->level;
|
sb->level = info->level;
|
||||||
sb->size = info->size;
|
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->raid_disks = info->raid_disks;
|
||||||
sb->md_minor = info->md_minor;
|
sb->md_minor = info->md_minor;
|
||||||
sb->not_persistent = 0;
|
sb->not_persistent = 0;
|
||||||
sb->set_uuid1 = random();
|
if (rfd < 0 || read(rfd, &sb->set_uuid1, 12) != 12) {
|
||||||
sb->set_uuid2 = random();
|
sb->set_uuid1 = random();
|
||||||
sb->set_uuid3 = random();
|
sb->set_uuid2 = random();
|
||||||
|
sb->set_uuid3 = random();
|
||||||
|
}
|
||||||
|
if (rfd >= 0)
|
||||||
|
close(rfd);
|
||||||
|
|
||||||
sb->utime = sb->ctime;
|
sb->utime = sb->ctime;
|
||||||
sb->state = info->state;
|
sb->state = info->state;
|
||||||
|
|
13
super1.c
13
super1.c
|
@ -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 *sb = sbv;
|
||||||
struct mdp_superblock_1 *refsb = NULL;
|
struct mdp_superblock_1 *refsb = NULL;
|
||||||
int fd = open(devname, O_RDWR | O_EXCL);
|
int fd = open(devname, O_RDWR | O_EXCL);
|
||||||
|
int rfd;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
long size;
|
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);
|
sb->dev_number = __cpu_to_le32(dinfo->number);
|
||||||
|
|
||||||
*(__u32*)(sb->device_uuid) = random();
|
if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 ||
|
||||||
*(__u32*)(sb->device_uuid+4) = random();
|
read(rfd, sb->device_uuid, 16) != 16) {
|
||||||
*(__u32*)(sb->device_uuid+8) = random();
|
*(__u32*)(sb->device_uuid) = random();
|
||||||
*(__u32*)(sb->device_uuid+12) = 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;
|
sb->events = 0;
|
||||||
|
|
||||||
if (load_super1(st, fd, (void**)&refsb, NULL)==0) {
|
if (load_super1(st, fd, (void**)&refsb, NULL)==0) {
|
||||||
|
|
Loading…
Reference in New Issue