1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-13 10:02:38 +00:00

arc4random() returns 0 to (2**32)−1, use an alternative to initialize

i_gen if it's zero rather than a divide by 2.

With inputs from  delphij, mckusick, rmacklem

Reviewed by:	mckusick
This commit is contained in:
Kevin Lo 2016-05-22 14:31:20 +00:00
parent 91460148b2
commit 57d2ac2f90
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=300423
4 changed files with 10 additions and 6 deletions

View File

@ -408,7 +408,8 @@ ext2_valloc(struct vnode *pvp, int mode, struct ucred *cred, struct vnode **vpp)
/*
* Set up a new generation number for this inode.
*/
ip->i_gen = arc4random();
while (ip->i_gen == 0 || ++ip->i_gen == 0)
ip->i_gen = arc4random();
vfs_timestamp(&ts);
ip->i_birthtime = ts.tv_sec;

View File

@ -998,7 +998,8 @@ ext2_vget(struct mount *mp, ino_t ino, int flags, struct vnode **vpp)
* already have one. This should only happen on old filesystems.
*/
if (ip->i_gen == 0) {
ip->i_gen = random() + 1;
while (ip->i_gen == 0)
ip->i_gen = arc4random();
if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
ip->i_flag |= IN_MODIFIED;
}

View File

@ -1102,8 +1102,8 @@ ffs_valloc(pvp, mode, cred, vpp)
/*
* Set up a new generation number for this inode.
*/
if (ip->i_gen == 0 || ++ip->i_gen == 0)
ip->i_gen = arc4random() / 2 + 1;
while (ip->i_gen == 0 || ++ip->i_gen == 0)
ip->i_gen = arc4random();
DIP_SET(ip, i_gen, ip->i_gen);
if (fs->fs_magic == FS_UFS2_MAGIC) {
vfs_timestamp(&ts);
@ -2080,7 +2080,8 @@ ffs_nodealloccg(ip, cg, ipref, mode, unused)
bzero(ibp->b_data, (int)fs->fs_bsize);
dp2 = (struct ufs2_dinode *)(ibp->b_data);
for (i = 0; i < INOPB(fs); i++) {
dp2->di_gen = arc4random() / 2 + 1;
while (dp2->di_gen == 0)
dp2->di_gen = arc4random();
dp2++;
}
/*

View File

@ -1768,7 +1768,8 @@ ffs_vgetf(mp, ino, flags, vpp, ffs_flags)
* already have one. This should only happen on old filesystems.
*/
if (ip->i_gen == 0) {
ip->i_gen = arc4random() / 2 + 1;
while (ip->i_gen == 0)
ip->i_gen = arc4random();
if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
ip->i_flag |= IN_MODIFIED;
DIP_SET(ip, i_gen, ip->i_gen);